ManaPlus
clanrecv.cpp
Go to the documentation of this file.
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 
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 
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();
78 }
79 
81 {
82  localClan.onlineMembers = msg.readInt16("online members count");
83  localClan.totalMembers = msg.readInt16("total members count");
85 }
86 
88 {
90  localClan.clear();
92 }
93 
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,
120  }
121 }
122 
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
ChatWindow * chatWindow
Definition: chatwindow.cpp:94
#define reportAlways(...)
Definition: checkutils.h:253
ClanTab * clanTab
Definition: clantab.cpp:36
ClanWindow * clanWindow
Definition: clanwindow.cpp:38
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:111
void loadFromLogFile(const std::string &name)
Definition: chattab.cpp:510
void resetClan()
Definition: clanwindow.cpp:144
void updateClan()
Definition: clanwindow.cpp:136
void updateClanMembers()
Definition: clanwindow.cpp:152
bool getBoolValue(const std::string &key) const
Configuration config
#define delete2(var)
Definition: delete2.h:25
const bool IgnoreRecord_false
Definition: ignorerecord.h:30
LocalClan localClan
Definition: localclan.cpp:26
#define A_UNUSED
Definition: localconsts.h:160
bool msg(InputEvent &event)
Definition: chat.cpp:39
bool info(InputEvent &event)
Definition: commands.cpp:57
std::string trim(std::string const &str)
const ClanInfo * get(const int clanId)
Definition: clandb.cpp:122
void processClanOnlineCount(Net::MessageIn &msg)
Definition: clanrecv.cpp:80
void processClanInfo(Net::MessageIn &msg)
Definition: clanrecv.cpp:47
void processClanLeave(Net::MessageIn &msg)
Definition: clanrecv.cpp:87
void processClanChat(Net::MessageIn &msg)
Definition: clanrecv.cpp:94
void createTab()
Definition: partyrecv.cpp:226
int onlineMembers
Definition: localclan.h:68
void clear()
Definition: localclan.h:48
std::string masterName
Definition: localclan.h:64
std::string mapName
Definition: localclan.h:65
std::string name
Definition: localclan.h:63
std::vector< std::string > allyClans
Definition: localclan.h:61
std::vector< std::string > stats
Definition: localclan.h:66
int totalMembers
Definition: localclan.h:69
std::vector< std::string > antagonistClans
Definition: localclan.h:62
int id
Definition: localclan.h:67
const bool TryRemoveColors_true