GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/guildhandler.cpp Lines: 1 132 0.8 %
Date: 2017-11-29 Branches: 0 190 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2009-2010  The Mana Developers
4
 *  Copyright (C) 2011-2017  The ManaPlus Developers
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/guildhandler.h"
23
24
#include "actormanager.h"
25
26
#include "being/localplayer.h"
27
#include "being/playerinfo.h"
28
29
#include "gui/widgets/tabs/chat/guildtab.h"
30
31
#include "net/eathena/guildrecv.h"
32
#include "net/eathena/messageout.h"
33
#include "net/eathena/protocolout.h"
34
35
#include "utils/delete2.h"
36
37
#include "debug.h"
38
39
GuildTab *guildTab = nullptr;
40
41
extern int packetVersion;
42
43
namespace EAthena
44
{
45
46
GuildHandler::GuildHandler() :
47
    Net::GuildHandler()
48
{
49
    guildHandler = this;
50
    GuildRecv::showBasicInfo = false;
51
}
52
53
GuildHandler::~GuildHandler()
54
{
55
    delete2(guildTab);
56
    guildHandler = nullptr;
57
    taGuild = nullptr;
58
}
59
60
void GuildHandler::clear() const
61
{
62
    taGuild = nullptr;
63
}
64
65
ChatTab *GuildHandler::getTab() const
66
{
67
    return guildTab;
68
}
69
70
void GuildHandler::create(const std::string &name) const
71
{
72
    createOutPacket(CMSG_GUILD_CREATE);
73
    outMsg.writeInt32(0, "unused");
74
    outMsg.writeString(name, 24, "guild name");
75
}
76
77
void GuildHandler::invite(const std::string &name) const
78
{
79
    if (actorManager == nullptr)
80
        return;
81
82
    const Being *const being = actorManager->findBeingByName(
83
        name, ActorType::Player);
84
    if (being != nullptr)
85
    {
86
        createOutPacket(CMSG_GUILD_INVITE);
87
        outMsg.writeBeingId(being->getId(), "account id");
88
        outMsg.writeInt32(0, "unused");
89
        outMsg.writeInt32(0, "unused");
90
    }
91
    else if (packetVersion >= 20120418)
92
    {
93
        createOutPacket(CMSG_GUILD_INVITE2);
94
        outMsg.writeString(name, 24, "name");
95
    }
96
}
97
98
void GuildHandler::invite(const Being *const being) const
99
{
100
    if (being == nullptr)
101
        return;
102
103
    createOutPacket(CMSG_GUILD_INVITE);
104
    outMsg.writeBeingId(being->getId(), "account id");
105
    outMsg.writeInt32(0, "unused");
106
    outMsg.writeInt32(0, "unused");
107
}
108
109
void GuildHandler::inviteResponse(const int guildId,
110
                                  const bool response) const
111
{
112
    createOutPacket(CMSG_GUILD_INVITE_REPLY);
113
    outMsg.writeInt32(guildId, "guild id");
114
    outMsg.writeInt8(static_cast<int8_t>(response), "response");
115
    outMsg.writeInt8(0, "unused");
116
    outMsg.writeInt16(0, "unused");
117
}
118
119
void GuildHandler::leave(const int guildId) const
120
{
121
    if (localPlayer == nullptr)
122
        return;
123
124
    createOutPacket(CMSG_GUILD_LEAVE);
125
    outMsg.writeInt32(guildId, "guild id");
126
    outMsg.writeBeingId(localPlayer->getId(), "account id");
127
    outMsg.writeInt32(PlayerInfo::getCharId(), "char id");
128
    outMsg.writeString("", 40, "message");
129
}
130
131
void GuildHandler::kick(const GuildMember *restrict const member,
132
                        const std::string &restrict reason) const
133
{
134
    if ((member == nullptr) || (member->getGuild() == nullptr))
135
        return;
136
137
    createOutPacket(CMSG_GUILD_EXPULSION);
138
    outMsg.writeInt32(member->getGuild()->getId(), "guild id");
139
    outMsg.writeBeingId(member->getID(), "account id");
140
    outMsg.writeInt32(member->getCharId(), "char id");
141
    outMsg.writeString(reason, 40, "message");
142
}
143
144
void GuildHandler::chat(const std::string &text) const
145
{
146
    if (localPlayer == nullptr)
147
        return;
148
149
    const std::string str = std::string(localPlayer->getName()).append(
150
        " : ").append(text);
151
    createOutPacket(CMSG_GUILD_MESSAGE);
152
    if (packetVersion >= 20151001)
153
    {
154
        outMsg.writeInt16(CAST_U16(str.size() + 4), "len");
155
        outMsg.writeString(str, CAST_S32(str.length()), "message");
156
    }
157
    else
158
    {
159
        outMsg.writeInt16(CAST_U16(str.size() + 4 + 1), "len");
160
        outMsg.writeString(str, CAST_S32(str.length()), "message");
161
        outMsg.writeInt8(0, "zero byte");
162
    }
163
}
164
165
void GuildHandler::memberList() const
166
{
167
    // 0 = basic info + alliance info
168
    // 1 = position name list + member list
169
    // 2 = position name list + position info list
170
    // 3 = skill info
171
    // 4 = expulsion list
172
173
    createOutPacket(CMSG_GUILD_REQUEST_INFO);
174
    outMsg.writeInt32(1, "action");  // Request member list
175
}
176
177
void GuildHandler::info() const
178
{
179
    // 0 = basic info + alliance info
180
    // 1 = position name list + member list
181
    // 2 = position name list + position info list
182
    // 3 = skill info
183
    // 4 = expulsion list
184
185
    GuildRecv::showBasicInfo = true;
186
    createOutPacket(CMSG_GUILD_REQUEST_INFO);
187
    outMsg.writeInt32(0, "action");  // Request basic info
188
}
189
190
void GuildHandler::changeMemberPostion(const GuildMember *const member,
191
                                       const int level) const
192
{
193
    if ((member == nullptr) || (member->getGuild() == nullptr))
194
        return;
195
196
    createOutPacket(CMSG_GUILD_CHANGE_MEMBER_POS);
197
    outMsg.writeInt16(16, "len");
198
    outMsg.writeBeingId(member->getID(), "account id");
199
    outMsg.writeInt32(member->getCharId(), "char id");
200
    outMsg.writeInt32(level, "pos");
201
}
202
203
void GuildHandler::changeNotice(const int guildId,
204
                                const std::string &restrict msg1,
205
                                const std::string &restrict msg2) const
206
{
207
    createOutPacket(CMSG_GUILD_CHANGE_NOTICE);
208
    outMsg.writeInt32(guildId, "guild id");
209
    outMsg.writeString(msg1, 60, "msg1");
210
    outMsg.writeString(msg2, 120, "msg2");
211
}
212
213
void GuildHandler::checkMaster() const
214
{
215
    createOutPacket(CMSG_GUILD_CHECK_MASTER);
216
}
217
218
void GuildHandler::requestAlliance(const Being *const being) const
219
{
220
    if (being == nullptr)
221
        return;
222
223
    createOutPacket(CMSG_GUILD_ALLIANCE_REQUEST);
224
    outMsg.writeBeingId(being->getId(), "account id");
225
    outMsg.writeInt32(0, "inviter account id");
226
    outMsg.writeInt32(0, "inviter char id");
227
}
228
229
void GuildHandler::requestAllianceResponse(const int beingId,
230
                                           const bool accept) const
231
{
232
    createOutPacket(CMSG_GUILD_ALLIANCE_REPLY);
233
    outMsg.writeInt32(beingId, "account id");
234
    outMsg.writeInt32(static_cast<int32_t>(accept), "accept flag");
235
}
236
237
void GuildHandler::endAlliance(const int guildId,
238
                               const int flag) const
239
{
240
    createOutPacket(CMSG_GUILD_ALLIANCE_DELETE);
241
    outMsg.writeInt32(guildId, "guild id");
242
    outMsg.writeInt32(flag, "flag");
243
}
244
245
void GuildHandler::changePostionInfo(const int posId,
246
                                     const int mode,
247
                                     const int ranking,
248
                                     const int payRate,
249
                                     const std::string &name) const
250
{
251
    createOutPacket(CMSG_GUILD_CHANGE_POS_INFO);
252
    outMsg.writeInt16(44, "len");
253
    outMsg.writeInt32(posId, "position id");
254
    outMsg.writeInt32(mode, "mode");
255
    outMsg.writeInt32(ranking, "ranking");
256
    outMsg.writeInt32(payRate, "pay rate");
257
    outMsg.writeString(name, 24, "name");
258
}
259
260
void GuildHandler::requestOpposition(const Being *const being) const
261
{
262
    if (being == nullptr)
263
        return;
264
265
    createOutPacket(CMSG_GUILD_OPPOSITION);
266
    outMsg.writeBeingId(being->getId(), "account id");
267
}
268
269
void GuildHandler::breakGuild(const std::string &name) const
270
{
271
    createOutPacket(CMSG_GUILD_BREAK);
272
    outMsg.writeString(name, 40, "name");
273
}
274
275
void GuildHandler::changeEmblem(std::string emblem) const
276
{
277
    createOutPacket(CMSG_GUILD_CHANGE_EMBLEM);
278
    if (emblem.size() > 200)
279
        emblem = emblem.substr(0, 200);
280
    const int sz = CAST_S32(emblem.size());
281
    outMsg.writeInt16(CAST_S16(sz + 4), "len");
282
    outMsg.writeString(emblem, sz, "emblem");
283
}
284
285
void GuildHandler::requestEmblem(const int guildId) const
286
{
287
    createOutPacket(CMSG_GUILD_REQUEST_EMBLEM);
288
    outMsg.writeInt32(guildId, "guild id");
289
}
290
291
4
}  // namespace EAthena