GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/mailhandler.cpp Lines: 0 40 0.0 %
Date: 2021-03-17 Branches: 0 52 0.0 %

Line Branch Exec Source
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
22
#include "net/eathena/mailhandler.h"
23
24
#include "const/net/inventory.h"
25
26
#include "net/eathena/messageout.h"
27
#include "net/eathena/protocolout.h"
28
29
#include "debug.h"
30
31
namespace EAthena
32
{
33
34
MailHandler::MailHandler()
35
{
36
    mailHandler = this;
37
}
38
39
MailHandler::~MailHandler()
40
{
41
    mailHandler = nullptr;
42
}
43
44
void MailHandler::refresh() const
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