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

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