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/clanrecv.h" |
23 |
|
|
|
24 |
|
|
#include "configuration.h" |
25 |
|
|
|
26 |
|
|
#include "being/localclan.h" |
27 |
|
|
|
28 |
|
|
#include "gui/widgets/tabs/chat/clantab.h" |
29 |
|
|
|
30 |
|
|
#include "gui/windows/chatwindow.h" |
31 |
|
|
#include "gui/windows/clanwindow.h" |
32 |
|
|
|
33 |
|
|
#include "net/messagein.h" |
34 |
|
|
|
35 |
|
|
#include "utils/checkutils.h" |
36 |
|
|
#include "utils/delete2.h" |
37 |
|
|
|
38 |
|
|
#include "resources/claninfo.h" |
39 |
|
|
|
40 |
|
|
#include "resources/db/clandb.h" |
41 |
|
|
|
42 |
|
|
#include "debug.h" |
43 |
|
|
|
44 |
|
|
namespace EAthena |
45 |
|
|
{ |
46 |
|
|
|
47 |
|
|
void ClanRecv::processClanInfo(Net::MessageIn &msg) |
48 |
|
|
{ |
49 |
|
|
msg.readInt16("len"); |
50 |
|
|
localClan.id = msg.readInt32("clan id"); |
51 |
|
|
localClan.name = msg.readString(24, "clan name"); |
52 |
|
|
localClan.masterName = msg.readString(24, "master name"); |
53 |
|
|
localClan.mapName = msg.readString(16, "map name"); |
54 |
|
|
const int allyCount = msg.readUInt8("ally clans count"); |
55 |
|
|
const int antagonistCount = msg.readUInt8("antagonist clans count"); |
56 |
|
|
for (int f = 0; f < allyCount; f ++) |
57 |
|
|
{ |
58 |
|
|
localClan.allyClans.push_back( |
59 |
|
|
msg.readString(24, "ally clan name")); |
60 |
|
|
} |
61 |
|
|
for (int f = 0; f < antagonistCount; f ++) |
62 |
|
|
{ |
63 |
|
|
localClan.antagonistClans.push_back( |
64 |
|
|
msg.readString(24, "antagonist clan name")); |
65 |
|
|
} |
66 |
|
|
const ClanInfo *const info = ClanDb::get(localClan.id); |
67 |
|
|
if (info == nullptr) |
68 |
|
|
{ |
69 |
|
|
reportAlways("missing clan %d in clandb", |
70 |
|
|
localClan.id) |
71 |
|
|
} |
72 |
|
|
else |
73 |
|
|
{ |
74 |
|
|
localClan.stats = info->stats; |
75 |
|
|
} |
76 |
|
|
createTab(); |
77 |
|
|
clanWindow->updateClan(); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
void ClanRecv::processClanOnlineCount(Net::MessageIn &msg) |
81 |
|
|
{ |
82 |
|
|
localClan.onlineMembers = msg.readInt16("online members count"); |
83 |
|
|
localClan.totalMembers = msg.readInt16("total members count"); |
84 |
|
|
clanWindow->updateClanMembers(); |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
void ClanRecv::processClanLeave(Net::MessageIn &msg A_UNUSED) |
88 |
|
|
{ |
89 |
|
|
delete2(clanTab) |
90 |
|
|
localClan.clear(); |
91 |
|
|
clanWindow->resetClan(); |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
void ClanRecv::processClanChat(Net::MessageIn &msg) |
95 |
|
|
{ |
96 |
|
|
const int chatMsgLength = msg.readInt16("len") - 4 - 24; |
97 |
|
|
if (chatMsgLength <= 0) |
98 |
|
|
return; |
99 |
|
|
msg.readString(24, "player name (unused)"); |
100 |
|
|
std::string chatMsg = msg.readString(chatMsgLength, "message"); |
101 |
|
|
if (clanTab == nullptr) |
102 |
|
|
{ |
103 |
|
|
reportAlways("received clan chat messages without clan.") |
104 |
|
|
return; |
105 |
|
|
} |
106 |
|
|
const size_t pos = chatMsg.find(" : ", 0); |
107 |
|
|
if (pos != std::string::npos) |
108 |
|
|
{ |
109 |
|
|
const std::string sender_name = chatMsg.substr(0, pos); |
110 |
|
|
chatMsg.erase(0, pos + 3); |
111 |
|
|
trim(chatMsg); |
112 |
|
|
clanTab->chatLog(sender_name, chatMsg); |
113 |
|
|
} |
114 |
|
|
else |
115 |
|
|
{ |
116 |
|
|
clanTab->chatLog(chatMsg, |
117 |
|
|
ChatMsgType::BY_SERVER, |
118 |
|
|
IgnoreRecord_false, |
119 |
|
|
TryRemoveColors_true); |
120 |
|
|
} |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
void ClanRecv::createTab() |
124 |
|
|
{ |
125 |
|
|
if (clanTab != nullptr) |
126 |
|
|
return; |
127 |
|
|
clanTab = new ClanTab(chatWindow); |
128 |
|
|
if (config.getBoolValue("showChatHistory")) |
129 |
|
|
clanTab->loadFromLogFile("#Clan"); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
} // namespace EAthena |