ManaPlus
mailhandler.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
23 
24 #include "const/net/inventory.h"
25 
26 #include "net/eathena/messageout.h"
28 
29 #include "debug.h"
30 
31 namespace EAthena
32 {
33 
35 {
36  mailHandler = this;
37 }
38 
40 {
41  mailHandler = nullptr;
42 }
43 
45 {
46  createOutPacket(CMSG_MAIL_REFRESH_INBOX);
47 }
48 
49 void MailHandler::readMessage(const int msgId) const
50 {
51  createOutPacket(CMSG_MAIL_READ_MESSAGE);
52  outMsg.writeInt32(msgId, "message id");
53 }
54 
55 void MailHandler::getAttach(const int msgId) const
56 {
57  createOutPacket(CMSG_MAIL_GET_ATTACH);
58  outMsg.writeInt32(msgId, "message id");
59 }
60 
61 void MailHandler::deleteMessage(const int msgId) const
62 {
63  createOutPacket(CMSG_MAIL_DELETE_MESSAGE);
64  outMsg.writeInt32(msgId, "message id");
65 }
66 
67 void MailHandler::returnMessage(const int msgId) const
68 {
69  createOutPacket(CMSG_MAIL_RETURN_MESSAGE);
70  outMsg.writeInt32(msgId, "message id");
71  outMsg.writeString("", 24, "unused");
72 }
73 
74 void MailHandler::setAttach(const int index, const int amount) const
75 {
76  createOutPacket(CMSG_MAIL_SET_ATTACH);
77  outMsg.writeInt16(CAST_S16(index + INVENTORY_OFFSET), "index");
78  outMsg.writeInt32(amount, "amount");
79 }
80 
81 void MailHandler::setAttachMoney(const int money) const
82 {
83  createOutPacket(CMSG_MAIL_SET_ATTACH);
84  outMsg.writeInt16(CAST_S16(0), "index");
85  outMsg.writeInt32(money, "money");
86 }
87 
88 void MailHandler::resetAttach(const int flag) const
89 {
90  createOutPacket(CMSG_MAIL_RESET_ATTACH);
91  outMsg.writeInt16(CAST_S16(flag), "flag");
92 }
93 
94 void MailHandler::send(const std::string &name,
95  const std::string &title,
96  std::string message) const
97 {
98  if (message.size() > 255)
99  message = message.substr(0, 255);
100  const int sz = CAST_S32(message.size());
101 
102  createOutPacket(CMSG_MAIL_SEND);
103  outMsg.writeInt16(CAST_S16(69 + sz), "len");
104  outMsg.writeString(name, 24, "name");
105  outMsg.writeString(title, 40, "title");
106  outMsg.writeInt8(CAST_S8(sz), "message size");
107  outMsg.writeString(message, sz, "message");
108 }
109 
110 } // namespace EAthena
#define CAST_S8
Definition: cast.h:26
#define CAST_S16
Definition: cast.h:28
#define CAST_S32
Definition: cast.h:30
void refresh() const
Definition: mailhandler.cpp:44
void getAttach(const int msgId) const
Definition: mailhandler.cpp:55
void returnMessage(const int msgId) const
Definition: mailhandler.cpp:67
void setAttach(const int index, const int amount) const
Definition: mailhandler.cpp:74
void setAttachMoney(const int money) const
Definition: mailhandler.cpp:81
void send(const std::string &name, const std::string &title, std::string message) const
Definition: mailhandler.cpp:94
void readMessage(const int msgId) const
Definition: mailhandler.cpp:49
void resetAttach(const int flag) const
Definition: mailhandler.cpp:88
void deleteMessage(const int msgId) const
Definition: mailhandler.cpp:61
static const int INVENTORY_OFFSET
Definition: inventory.h:27
Net::MailHandler * mailHandler
Definition: net.cpp:114
#define createOutPacket(name)
Definition: messageout.h:37