ManaPlus
guildhandler.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2009-2010 The Mana Developers
4  * Copyright (C) 2011-2018 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 
23 
24 #include "actormanager.h"
25 
26 #include "being/localplayer.h"
27 #include "being/playerinfo.h"
28 
30 
31 #include "net/eathena/guildrecv.h"
32 #include "net/eathena/messageout.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 
47  Net::GuildHandler()
48 {
49  guildHandler = this;
51 }
52 
54 {
55  delete2(guildTab);
56  guildHandler = nullptr;
57  taGuild = nullptr;
58 }
59 
60 void GuildHandler::clear() const
61 {
62  taGuild = nullptr;
63 }
64 
66 {
67  return guildTab;
68 }
69 
70 void GuildHandler::create(const std::string &name) const
71 {
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  {
87  outMsg.writeBeingId(being->getId(), "account id");
88  outMsg.writeInt32(0, "unused");
89  outMsg.writeInt32(0, "unused");
90  }
91  else if (packetVersion >= 20120418)
92  {
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 
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 {
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 
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 
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);
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 
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 
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 
187  outMsg.writeInt32(0, "action"); // Request basic info
188 }
189 
191  const int level) const
192 {
193  if ((member == nullptr) || (member->getGuild() == nullptr))
194  return;
195 
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 {
208  outMsg.writeInt32(guildId, "guild id");
209  outMsg.writeString(msg1, 60, "msg1");
210  outMsg.writeString(msg2, 120, "msg2");
211 }
212 
214 {
216 }
217 
218 void GuildHandler::requestAlliance(const Being *const being) const
219 {
220  if (being == nullptr)
221  return;
222 
224  outMsg.writeBeingId(being->getId(), "account id");
225  outMsg.writeInt32(0, "inviter account id");
226  outMsg.writeInt32(0, "inviter char id");
227 }
228 
230  const bool accept) const
231 {
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 {
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 {
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 
266  outMsg.writeBeingId(being->getId(), "account id");
267 }
268 
269 void GuildHandler::breakGuild(const std::string &name) const
270 {
272  outMsg.writeString(name, 40, "name");
273 }
274 
275 void GuildHandler::changeEmblem(std::string emblem) const
276 {
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 {
288  outMsg.writeInt32(guildId, "guild id");
289 }
290 
291 } // namespace EAthena
void changeEmblem(std::string emblem) const
int CMSG_GUILD_CHANGE_NOTICE
int CMSG_GUILD_ALLIANCE_REPLY
void kick(const GuildMember *const member, const std::string &reason) const
int CMSG_GUILD_CHANGE_POS_INFO
BeingId getID() const
Definition: avatar.h:149
BeingId getId() const
Definition: actorsprite.h:63
void requestOpposition(const Being *const being) const
Guild * taGuild
Definition: guildhandler.h:98
int CMSG_GUILD_ALLIANCE_DELETE
int CMSG_GUILD_CHECK_MASTER
int packetVersion
Definition: client.cpp:120
int CMSG_GUILD_INVITE2
void breakGuild(const std::string &name) const
#define delete2(var)
Definition: delete2.h:24
Net::GuildHandler * guildHandler
Definition: net.cpp:85
void create(const std::string &name) const
int CMSG_GUILD_REQUEST_INFO
int CMSG_GUILD_INVITE_REPLY
void changePostionInfo(const int posId, const int mode, const int ranking, const int payRate, const std::string &name) const
#define CAST_U16
Definition: cast.h:28
#define CAST_S32
Definition: cast.h:29
void changeNotice(const int guildId, const std::string &msg1, const std::string &msg2) const
int CMSG_GUILD_INVITE
void requestEmblem(const int guildId) const
LocalPlayer * localPlayer
void invite(const std::string &name) const
int CMSG_GUILD_CHANGE_MEMBER_POS
ChatTab * getTab() const
int CMSG_GUILD_CHANGE_EMBLEM
int CMSG_GUILD_MESSAGE
int CMSG_GUILD_EXPULSION
void endAlliance(const int guildId, const int flag) const
void changeMemberPostion(const GuildMember *const member, const int level) const
const std::string & getName() const
Definition: being.h:231
#define createOutPacket(name)
Definition: messageout.h:36
int CMSG_GUILD_CREATE
int getCharId()
Definition: playerinfo.cpp:383
void requestAllianceResponse(const int beingId, const bool accept) const
int CMSG_GUILD_BREAK
int CMSG_GUILD_LEAVE
void checkMaster() const
GuildTab * guildTab
#define restrict
Definition: localconsts.h:176
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
int CMSG_GUILD_ALLIANCE_REQUEST
const Guild * getGuild() const
Definition: guild.h:43
#define CAST_S16
Definition: cast.h:27
void leave(const int guildId) const
Definition: being.h:93
int CMSG_GUILD_REQUEST_EMBLEM
void requestAlliance(const Being *const being) const
ActorManager * actorManager
int getCharId() const
Definition: avatar.h:155
void chat(const std::string &text) const
void inviteResponse(const int guildId, const bool response) const
int CMSG_GUILD_OPPOSITION
bool msg2(InputEvent &event)
Definition: chat.cpp:40