1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
/*
* The ManaPlus Client
* Copyright (C) 2009-2010 The Mana Developers
* Copyright (C) 2011-2015 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "net/eathena/guildhandler.h"
#include "actormanager.h"
#include "configuration.h"
#include "being/localplayer.h"
#include "being/playerinfo.h"
#include "gui/windows/chatwindow.h"
#include "gui/windows/socialwindow.h"
#include "gui/widgets/tabs/chat/guildtab.h"
#include "net/eathena/messageout.h"
#include "net/eathena/protocol.h"
#include "debug.h"
extern Net::GuildHandler *guildHandler;
namespace EAthena
{
GuildHandler::GuildHandler() :
Ea::GuildHandler(),
MessageHandler()
{
static const uint16_t _messages[] =
{
SMSG_GUILD_CREATE_RESPONSE,
SMSG_GUILD_POSITION_INFO,
SMSG_GUILD_MEMBER_LOGIN,
SMSG_GUILD_MASTER_OR_MEMBER,
SMSG_GUILD_BASIC_INFO,
SMSG_GUILD_ALIANCE_INFO,
SMSG_GUILD_MEMBER_LIST,
SMSG_GUILD_POS_NAME_LIST,
SMSG_GUILD_POS_INFO_LIST,
SMSG_GUILD_POSITION_CHANGED,
SMSG_GUILD_MEMBER_POS_CHANGE,
SMSG_GUILD_EMBLEM_DATA,
SMSG_GUILD_SKILL_INFO,
SMSG_GUILD_NOTICE,
SMSG_GUILD_INVITE,
SMSG_GUILD_INVITE_ACK,
SMSG_GUILD_LEAVE,
SMSG_GUILD_EXPULSION,
SMSG_GUILD_EXPULSION_LIST,
SMSG_GUILD_MESSAGE,
SMSG_GUILD_SKILL_UP,
SMSG_GUILD_REQ_ALLIANCE,
SMSG_GUILD_REQ_ALLIANCE_ACK,
SMSG_GUILD_DEL_ALLIANCE,
SMSG_GUILD_OPPOSITION_ACK,
SMSG_GUILD_BROKEN,
SMSG_GUILD_UPDATE_COORDS,
SMSG_GUILD_EMBLEM,
0
};
handledMessages = _messages;
guildHandler = this;
}
GuildHandler::~GuildHandler()
{
}
void GuildHandler::handleMessage(Net::MessageIn &msg)
{
switch (msg.getId())
{
case SMSG_GUILD_CREATE_RESPONSE:
processGuildCreateResponse(msg);
break;
case SMSG_GUILD_POSITION_INFO:
processGuildPositionInfo(msg);
break;
case SMSG_GUILD_MEMBER_LOGIN:
processGuildMemberLogin(msg);
break;
case SMSG_GUILD_MASTER_OR_MEMBER:
processGuildMasterOrMember(msg);
break;
case SMSG_GUILD_BASIC_INFO:
processGuildBasicInfo(msg);
break;
case SMSG_GUILD_ALIANCE_INFO:
processGuildAlianceInfo(msg);
break;
case SMSG_GUILD_MEMBER_LIST:
processGuildMemberList(msg);
break;
case SMSG_GUILD_POS_NAME_LIST:
processGuildPosNameList(msg);
break;
case SMSG_GUILD_POS_INFO_LIST:
processGuildPosInfoList(msg);
break;
case SMSG_GUILD_POSITION_CHANGED:
processGuildPositionChanged(msg);
break;
case SMSG_GUILD_MEMBER_POS_CHANGE:
processGuildMemberPosChange(msg);
break;
case SMSG_GUILD_EMBLEM_DATA:
processGuildEmblemData(msg);
break;
case SMSG_GUILD_SKILL_INFO:
processGuildSkillInfo(msg);
break;
case SMSG_GUILD_NOTICE:
processGuildNotice(msg);
break;
case SMSG_GUILD_INVITE:
processGuildInvite(msg);
break;
case SMSG_GUILD_INVITE_ACK:
processGuildInviteAck(msg);
break;
case SMSG_GUILD_LEAVE:
processGuildLeave(msg);
break;
case SMSG_GUILD_EXPULSION:
processGuildExpulsion(msg);
break;
case SMSG_GUILD_EXPULSION_LIST:
processGuildExpulsionList(msg);
break;
case SMSG_GUILD_MESSAGE:
processGuildMessage(msg);
break;
case SMSG_GUILD_SKILL_UP:
processGuildSkillUp(msg);
break;
case SMSG_GUILD_REQ_ALLIANCE:
processGuildReqAlliance(msg);
break;
case SMSG_GUILD_REQ_ALLIANCE_ACK:
processGuildReqAllianceAck(msg);
break;
case SMSG_GUILD_DEL_ALLIANCE:
processGuildDelAlliance(msg);
break;
case SMSG_GUILD_OPPOSITION_ACK:
processGuildOppositionAck(msg);
break;
case SMSG_GUILD_BROKEN:
processGuildBroken(msg);
break;
case SMSG_GUILD_UPDATE_COORDS:
processGuildUpdateCoords(msg);
break;
case SMSG_GUILD_EMBLEM:
processGuildEmblem(msg);
break;
default:
break;
}
}
void GuildHandler::processGuildUpdateCoords(Net::MessageIn &msg)
{
const int id = msg.readInt32("account id");
const int x = msg.readInt16("x");
const int y = msg.readInt16("y");
if (Ea::taGuild)
{
GuildMember *const m = Ea::taGuild->getMember(id);
if (m)
{
m->setX(x);
m->setY(y);
}
}
}
void GuildHandler::create(const std::string &name) const
{
createOutPacket(CMSG_GUILD_CREATE);
outMsg.writeInt32(0, "unused");
outMsg.writeString(name, 24, "guild name");
}
void GuildHandler::invite(const std::string &name) const
{
if (!actorManager)
return;
const Being *const being = actorManager->findBeingByName(
name, ActorType::Player);
if (being)
{
createOutPacket(CMSG_GUILD_INVITE);
outMsg.writeInt32(being->getId(), "account id");
outMsg.writeInt32(0, "unused");
outMsg.writeInt32(0, "unused");
}
}
void GuildHandler::invite(const Being *const being) const
{
if (!being)
return;
createOutPacket(CMSG_GUILD_INVITE);
outMsg.writeInt32(being->getId(), "account id");
outMsg.writeInt32(0, "unused");
outMsg.writeInt32(0, "unused");
}
void GuildHandler::inviteResponse(const int guildId,
const bool response) const
{
createOutPacket(CMSG_GUILD_INVITE_REPLY);
outMsg.writeInt32(guildId, "guild id");
outMsg.writeInt8(response, "response");
outMsg.writeInt8(0, "unused");
outMsg.writeInt16(0, "unused");
}
void GuildHandler::leave(const int guildId) const
{
if (!localPlayer)
return;
createOutPacket(CMSG_GUILD_LEAVE);
outMsg.writeInt32(guildId, "guild id");
outMsg.writeInt32(localPlayer->getId(), "account id");
outMsg.writeInt32(PlayerInfo::getCharId(), "char id");
outMsg.writeString("", 40, "message");
}
void GuildHandler::kick(const GuildMember *restrict const member,
const std::string &restrict reason) const
{
if (!member || !member->getGuild())
return;
createOutPacket(CMSG_GUILD_EXPULSION);
outMsg.writeInt32(member->getGuild()->getId(), "guild id");
outMsg.writeInt32(member->getID(), "account id");
outMsg.writeInt32(member->getCharId(), "char id");
outMsg.writeString(reason, 40, "message");
}
void GuildHandler::chat(const std::string &text) const
{
if (!localPlayer)
return;
const std::string str = std::string(localPlayer->getName()).append(
" : ").append(text);
createOutPacket(CMSG_GUILD_MESSAGE);
outMsg.writeInt16(static_cast<uint16_t>(str.size() + 4 + 1), "len");
outMsg.writeString(str, static_cast<int>(str.length()), "message");
outMsg.writeInt8(0, "zero byte");
}
void GuildHandler::memberList() const
{
// 0 = basic info + alliance info
// 1 = position name list + member list
// 2 = position name list + position info list
// 3 = skill info
// 4 = expulsion list
createOutPacket(CMSG_GUILD_REQUEST_INFO);
outMsg.writeInt32(1, "action"); // Request member list
}
void GuildHandler::info()
{
// 0 = basic info + alliance info
// 1 = position name list + member list
// 2 = position name list + position info list
// 3 = skill info
// 4 = expulsion list
showBasicInfo = true;
createOutPacket(CMSG_GUILD_REQUEST_INFO);
outMsg.writeInt32(0, "action"); // Request basic info
}
void GuildHandler::changeMemberPostion(const GuildMember *const member,
const int level) const
{
if (!member || !member->getGuild())
return;
createOutPacket(CMSG_GUILD_CHANGE_MEMBER_POS);
outMsg.writeInt16(16, "len");
outMsg.writeInt32(member->getID(), "account id");
outMsg.writeInt32(member->getCharId(), "char id");
outMsg.writeInt32(level, "pos");
}
void GuildHandler::changeNotice(const int guildId,
const std::string &restrict msg1,
const std::string &restrict msg2) const
{
createOutPacket(CMSG_GUILD_CHANGE_NOTICE);
outMsg.writeInt32(guildId, "guild id");
outMsg.writeString(msg1, 60, "msg1");
outMsg.writeString(msg2, 120, "msg2");
}
void GuildHandler::checkMaster() const
{
createOutPacket(CMSG_GUILD_CHECK_MASTER);
}
void GuildHandler::processGuildPositionInfo(Net::MessageIn &msg)
{
const int guildId = msg.readInt32("guild id");
const int emblem = msg.readInt32("elblem id");
PlayerInfo::setGuildPositionFlags(
static_cast<GuildPositionFlags::Type>(msg.readInt32("mode")));
msg.readUInt8("guild master");
msg.readInt32("unused");
std::string guildName = msg.readString(24, "guild name");
Guild *const g = Guild::getGuild(static_cast<int16_t>(guildId));
if (!g)
return;
g->setName(guildName);
g->setEmblemId(emblem);
if (!Ea::taGuild)
Ea::taGuild = g;
if (!guildTab && chatWindow)
{
guildTab = new GuildTab(chatWindow);
if (config.getBoolValue("showChatHistory"))
guildTab->loadFromLogFile("#Guild");
if (localPlayer)
localPlayer->addGuild(Ea::taGuild);
guildHandler->memberList();
}
if (localPlayer)
{
localPlayer->setGuild(g);
localPlayer->setGuildName(g->getName());
}
}
void GuildHandler::processGuildMemberLogin(Net::MessageIn &msg)
{
const int accountId = msg.readInt32("account id");
const int charId = msg.readInt32("char id");
const int online = msg.readInt32("flag");
const Gender::Type gender = Being::intToGender(static_cast<uint8_t>(
msg.readInt16("sex")));
msg.readInt16("hair");
msg.readInt16("hair color");
if (Ea::taGuild)
{
GuildMember *const m = Ea::taGuild->getMember(accountId, charId);
if (m)
{
m->setOnline(online);
if (online)
m->setGender(gender);
if (guildTab)
guildTab->showOnline(m->getName(), online);
if (socialWindow)
socialWindow->updateGuildCounter();
}
}
}
void GuildHandler::processGuildExpulsion(Net::MessageIn &msg)
{
const std::string nick = msg.readString(24, "name");
msg.readString(40, "message");
processGuildExpulsionContinue(nick);
}
void GuildHandler::processGuildExpulsionList(Net::MessageIn &msg)
{
const int length = msg.readInt16("len");
if (length < 4)
return;
const int count = (length - 4) / 64;
for (int i = 0; i < count; i++)
{
msg.readString(24, "name");
msg.readString(40, "message");
}
}
void GuildHandler::processGuildEmblem(Net::MessageIn &msg)
{
UNIMPLIMENTEDPACKET;
msg.readInt32("being id");
msg.readInt32("guild id");
msg.readInt16("emblem id");
}
void GuildHandler::requestAlliance(const Being *const being) const
{
if (!being)
return;
createOutPacket(CMSG_GUILD_ALLIANCE_REQUEST);
outMsg.writeInt32(being->getId(), "account id");
outMsg.writeInt32(0, "inviter account id");
outMsg.writeInt32(0, "inviter char id");
}
void GuildHandler::requestAllianceResponse(const int beingId,
const bool accept) const
{
createOutPacket(CMSG_GUILD_ALLIANCE_REPLY);
outMsg.writeInt32(beingId, "account id");
outMsg.writeInt32(accept, "accept flag");
}
void GuildHandler::endAlliance(const int guildId,
const int flag) const
{
createOutPacket(CMSG_GUILD_ALLIANCE_DELETE);
outMsg.writeInt32(guildId, "guild id");
outMsg.writeInt32(flag, "flag");
}
void GuildHandler::changePostionInfo(const int posId,
const int mode,
const int ranking,
const int payRate,
const std::string &name) const
{
createOutPacket(CMSG_GUILD_CHANGE_POS_INFO);
outMsg.writeInt16(44, "len");
outMsg.writeInt32(posId, "position id");
outMsg.writeInt32(mode, "mode");
outMsg.writeInt32(ranking, "ranking");
outMsg.writeInt32(payRate, "pay rate");
outMsg.writeString(name, 24, "name");
}
void GuildHandler::requestOpposition(const Being *const being) const
{
if (!being)
return;
createOutPacket(CMSG_GUILD_OPPOSITION);
outMsg.writeInt32(being->getId(), "account id");
}
void GuildHandler::breakGuild(const std::string &name) const
{
createOutPacket(CMSG_GUILD_BREAK);
outMsg.writeString(name, 40, "name");
}
void GuildHandler::changeEmblem(std::string emblem) const
{
createOutPacket(CMSG_GUILD_CHANGE_EMBLEM);
if (emblem.size() > 200)
emblem = emblem.substr(0, 200);
const int sz = emblem.size();
outMsg.writeInt16(sz + 4, "len");
outMsg.writeString(emblem, sz, "emblem");
}
} // namespace EAthena
|