ManaPlus
Functions
EAthena::MailRecv Namespace Reference

Functions

void processMailOpen (Net::MessageIn &msg)
 
void processMailList (Net::MessageIn &msg)
 
void processReadMail (Net::MessageIn &msg)
 
void processGetAttachment (Net::MessageIn &msg)
 
void processSendMailAck (Net::MessageIn &msg)
 
void processNewMail (Net::MessageIn &msg)
 
void processSetAttachmentAck (Net::MessageIn &msg)
 
void processDeleteAck (Net::MessageIn &msg)
 
void processMailReturn (Net::MessageIn &msg)
 

Function Documentation

◆ processDeleteAck()

void EAthena::MailRecv::processDeleteAck ( Net::MessageIn msg)

Definition at line 222 of file mailrecv.cpp.

223 {
224  const int mail = msg.readInt32("message id");
225  const int flag = msg.readInt16("fail flag");
226  if (flag != 0)
227  {
229  }
230  else
231  {
233  mailWindow->removeMail(mail);
234  }
235 }
void removeMail(const int64_t id)
Definition: mailwindow.cpp:233
MailWindow * mailWindow
Definition: mailwindow.cpp:54
bool msg(InputEvent &event)
Definition: chat.cpp:39
void notify(const unsigned int message)

References NotifyTypes::MAIL_DELETE_ERROR, NotifyTypes::MAIL_DELETE_OK, mailWindow, Actions::msg(), NotifyManager::notify(), and MailWindow::removeMail().

◆ processGetAttachment()

void EAthena::MailRecv::processGetAttachment ( Net::MessageIn msg)

Definition at line 160 of file mailrecv.cpp.

161 {
162  const uint8_t flag = msg.readUInt8("flag");
163  switch (flag)
164  {
165  case 0:
167  break;
168  case 1:
170  break;
171  case 2:
173  break;
174  default:
176  break;
177  }
178 }
#define UNIMPLEMENTEDPACKETFIELD(field)
Definition: logger.h:59
@ MAIL_GET_ATTACH_ERROR
Definition: notifytypes.h:175
@ MAIL_GET_ATTACH_TOO_MANY_ITEMS
Definition: notifytypes.h:176
@ MAIL_GET_ATTACH_OK
Definition: notifytypes.h:174

References NotifyTypes::MAIL_GET_ATTACH_ERROR, NotifyTypes::MAIL_GET_ATTACH_OK, NotifyTypes::MAIL_GET_ATTACH_TOO_MANY_ITEMS, Actions::msg(), NotifyManager::notify(), and UNIMPLEMENTEDPACKETFIELD.

◆ processMailList()

void EAthena::MailRecv::processMailList ( Net::MessageIn msg)

Definition at line 78 of file mailrecv.cpp.

79 {
80  const int count = (msg.readInt16("len") - 8) / 73;
81  const int amount = msg.readInt32("amount");
82  if (count != amount)
83  logger->log("error: wrong mails count");
84  mailWindow->clear();
85  for (int f = 0; f < count; f ++)
86  {
87  MailMessage *const mail = new MailMessage;
88  mail->id = msg.readInt32("message id");
89  mail->title = msg.readString(40, "title");
90  mail->read = msg.readUInt8("unread flag") != 0U ? true : false;
91  mail->sender = msg.readString(24, "sender name");
92  mail->time = msg.readInt32("time stamp");
93  mail->strTime = timeToStr(mail->time);
94  mailWindow->addMail(mail);
95  }
96 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
void clear()
Definition: mailwindow.cpp:184
void addMail(MailMessage *const message)
Definition: mailwindow.cpp:224
Logger * logger
Definition: logger.cpp:89
std::string timeToStr(const uint32_t time)
std::string sender
Definition: mailmessage.h:51
int64_t id
Definition: mailmessage.h:54
std::string strTime
Definition: mailmessage.h:52
std::string title
Definition: mailmessage.h:50

References MailWindow::addMail(), MailWindow::clear(), MailMessage::id, Logger::log(), logger, mailWindow, Actions::msg(), MailMessage::read, MailMessage::sender, MailMessage::strTime, MailMessage::time, timeToStr(), and MailMessage::title.

◆ processMailOpen()

void EAthena::MailRecv::processMailOpen ( Net::MessageIn msg)

Definition at line 50 of file mailrecv.cpp.

51 {
52  const int flag = msg.readInt32("flag");
53  switch (flag)
54  {
55  case 0: // open window
56  if (mailWindow != nullptr)
57  {
61  }
62  break;
63 
64  case 1: // close window
65  if (mailWindow != nullptr)
66  {
69  }
70  break;
71 
72  default:
74  break;
75  }
76 }
virtual void requestMoveToTop()
Definition: widget.cpp:213
virtual void setVisible(Visible visible)
Definition: window.cpp:778
bool isWindowVisible() const
Definition: window.h:484
const bool Visible_false
Definition: visible.h:30
const bool Visible_true
Definition: visible.h:30

References Window::isWindowVisible(), mailWindow, Actions::msg(), Widget::requestMoveToTop(), Window::setVisible(), UNIMPLEMENTEDPACKETFIELD, Visible_false, and Visible_true.

◆ processMailReturn()

void EAthena::MailRecv::processMailReturn ( Net::MessageIn msg)

Definition at line 237 of file mailrecv.cpp.

238 {
239  const int mail = msg.readInt32("message id");
240  const int flag = msg.readInt16("fail flag");
241  if (flag != 0)
242  {
244  }
245  else
246  {
248  mailWindow->removeMail(mail);
249  }
250 }

References NotifyTypes::MAIL_RETURN_ERROR, NotifyTypes::MAIL_RETURN_OK, mailWindow, Actions::msg(), NotifyManager::notify(), and MailWindow::removeMail().

◆ processNewMail()

void EAthena::MailRecv::processNewMail ( Net::MessageIn msg)

Definition at line 197 of file mailrecv.cpp.

198 {
199  msg.readInt32("message id");
200  const std::string subj = msg.readString(40, "title");
201  const std::string sender = msg.readString(24, "sender name");
203  // TRANSLATORS: mail message notification
204  strprintf(_("You have new mail from %s with subject %s"),
205  sender.c_str(), subj.c_str()));
206  mailHandler->refresh();
207 }
virtual void refresh() const =0
#define _(s)
Definition: gettext.h:35
Net::MailHandler * mailHandler
Definition: net.cpp:114
std::string strprintf(const char *const format,...)

References _, mailHandler, Actions::msg(), NotifyTypes::NEW_MAIL, NotifyManager::notify(), Net::MailHandler::refresh(), and strprintf().

◆ processReadMail()

void EAthena::MailRecv::processReadMail ( Net::MessageIn msg)

Definition at line 98 of file mailrecv.cpp.

99 {
100  const int sz = msg.readInt16("len") - 101;
101  MailMessage *const mail = new MailMessage;
102  mail->id = msg.readInt32("message id");
103  mail->title = msg.readString(40, "title");
104  mail->sender = msg.readString(24, "sender name");
105  msg.readInt32("unused");
106  mail->money = msg.readInt32("money");
107 
108  const int amount = msg.readInt32("item amount");
109  const int itemId = msg.readInt16("item id");
110  const ItemTypeT itemType = static_cast<ItemTypeT>(
111  msg.readInt16("item type"));
112  const uint8_t identify = msg.readUInt8("identify");
113  const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged);
114  const uint8_t refine = msg.readUInt8("refine");
115  int cards[maxCards];
116  for (int d = 0; d < maxCards; d ++)
117  cards[d] = msg.readUInt16("card");
118  const int msgLen = msg.readUInt8("msg len");
119  if (msgLen != sz)
120  logger->log("error: wrong message size");
121  mail->text = msg.readString(sz, "message");
122  msg.readUInt8("zero");
123  mail->strTime = timeToStr(mail->time);
124  if (mailWindow == nullptr)
125  {
126  reportAlways("Mail window not created")
127  delete mail;
128  return;
129  }
130  mailWindow->showMessage(mail, itemId != 0 ? 1 : 0);
131  if (mailViewWindow == nullptr)
132  {
133  reportAlways("Mail view window not created")
134  return;
135  }
136 
137  Inventory *const inventory = mailViewWindow->getInventory();
138  if (inventory == nullptr)
139  {
140  reportAlways("Mail view window missing inventory")
141  return;
142  }
143 
144  const int slot = inventory->addItem(itemId,
145  itemType,
146  amount,
147  refine,
148  ItemColorManager::getColorFromCards(&cards[0]),
149  fromBool(identify, Identified),
150  damaged,
152  Equipm_false,
154  if (slot != -1)
155  inventory->setCards(slot, cards, maxCards);
156 
157  mailViewWindow->updateItems();
158 }
#define fromBool(val, name)
Definition: booldefines.h:49
#define maxCards
Definition: cards.h:25
#define reportAlways(...)
Definition: checkutils.h:253
bool Damaged
Definition: damaged.h:30
const bool Equipm_false
Definition: equipm.h:30
const bool Equipped_false
Definition: equipped.h:30
const bool Favorite_false
Definition: favorite.h:30
if(!vert) return
bool Identified
Definition: identified.h:30
ItemType ::T ItemTypeT
Definition: itemtype.h:43
MailViewWindow * mailViewWindow
Inventory * getInventory()
Definition: playerinfo.cpp:195
int64_t money
Definition: mailmessage.h:57
std::string text
Definition: mailmessage.h:53

References Inventory::addItem(), Equipm_false, Equipped_false, Favorite_false, fromBool, ItemColorManager::getColorFromCards(), MailViewWindow::getInventory(), MailMessage::id, Logger::log(), logger, mailViewWindow, mailWindow, maxCards, MailMessage::money, Actions::msg(), reportAlways, MailMessage::sender, Inventory::setCards(), MailWindow::showMessage(), MailMessage::strTime, MailMessage::text, MailMessage::time, timeToStr(), MailMessage::title, and MailViewWindow::updateItems().

◆ processSendMailAck()

void EAthena::MailRecv::processSendMailAck ( Net::MessageIn msg)

Definition at line 180 of file mailrecv.cpp.

181 {
182  const uint8_t flag = msg.readUInt8("fail flag");
183  switch (flag)
184  {
185  case 0:
187  break;
188  case 1:
190  break;
191  default:
193  break;
194  }
195 }

References NotifyTypes::MAIL_SEND_ERROR, NotifyTypes::MAIL_SEND_OK, Actions::msg(), NotifyManager::notify(), and UNIMPLEMENTEDPACKETFIELD.

◆ processSetAttachmentAck()

void EAthena::MailRecv::processSetAttachmentAck ( Net::MessageIn msg)

Definition at line 209 of file mailrecv.cpp.

210 {
211  const int index = msg.readInt16("index");
212  const int flag = msg.readUInt8("flag");
213  if (flag != 0)
214  {
215  if (index != 0)
217  else
219  }
220 }
@ MAIL_ATTACH_MONEY_ERROR
Definition: notifytypes.h:169
@ MAIL_ATTACH_ITEM_ERROR
Definition: notifytypes.h:168

References NotifyTypes::MAIL_ATTACH_ITEM_ERROR, NotifyTypes::MAIL_ATTACH_MONEY_ERROR, Actions::msg(), and NotifyManager::notify().