GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/guildhandler.cpp Lines: 1 132 0.8 %
Date: 2021-03-17 Branches: 0 194 0.0 %

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