ManaPlus
adminhandler.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
25 
26 #include "being/being.h"
27 
28 #include "net/eathena/messageout.h"
30 
31 #include "utils/gmfunctions.h"
32 #include "utils/stringutils.h"
33 
34 #include "debug.h"
35 
36 extern int packetVersion;
37 extern int packetVersionZero;
38 
39 namespace EAthena
40 {
41 
42 std::string AdminHandler::mStatsName;
43 
45  Ea::AdminHandler()
46 {
47  adminHandler = this;
48 }
49 
51 {
52  adminHandler = nullptr;
53 }
54 
55 void AdminHandler::announce(const std::string &text) const
56 {
57  createOutPacket(CMSG_ADMIN_ANNOUNCE);
58  outMsg.writeInt16(CAST_S16(text.length() + 4), "len");
59  outMsg.writeString(text, CAST_S32(text.length()), "message");
60 }
61 
62 void AdminHandler::localAnnounce(const std::string &text) const
63 {
64  createOutPacket(CMSG_ADMIN_LOCAL_ANNOUNCE);
65  outMsg.writeInt16(CAST_S16(text.length() + 4), "len");
66  outMsg.writeString(text, CAST_S32(text.length()), "message");
67 }
68 
69 void AdminHandler::hide(const bool h A_UNUSED) const
70 {
71  createOutPacket(CMSG_ADMIN_HIDE);
72  outMsg.writeInt32(0, "unused");
73 }
74 
75 void AdminHandler::kick(const BeingId playerId) const
76 {
77  createOutPacket(CMSG_ADMIN_KICK);
78  outMsg.writeBeingId(playerId, "account id");
79 }
80 
82 {
83  createOutPacket(CMSG_ADMIN_KICK_ALL);
84 }
85 
86 void AdminHandler::warp(const std::string &map, const int x, const int y) const
87 {
88  createOutPacket(CMSG_PLAYER_MAPMOVE);
89  outMsg.writeString(map, 16, "map");
90  outMsg.writeInt16(CAST_S16(x), "x");
91  outMsg.writeInt16(CAST_S16(y), "y");
92 }
93 
95 {
96  createOutPacket(CMSG_ADMIN_RESET_PLAYER);
97  outMsg.writeInt16(0, "flag");
98 }
99 
101 {
102  createOutPacket(CMSG_ADMIN_RESET_PLAYER);
103  outMsg.writeInt16(1, "flag");
104 }
105 
106 void AdminHandler::gotoName(const std::string &name) const
107 {
108  createOutPacket(CMSG_ADMIN_GOTO);
109  outMsg.writeString(name, 24, "name");
110 }
111 
112 void AdminHandler::recallName(const std::string &name) const
113 {
114  createOutPacket(CMSG_ADMIN_RECALL);
115  outMsg.writeString(name, 24, "name");
116 }
117 
118 void AdminHandler::mute(const Being *const being,
119  const int type,
120  const int limit) const
121 {
122  if (being == nullptr)
123  return;
124 
125  createOutPacket(CMSG_ADMIN_MUTE);
126  outMsg.writeBeingId(being->getId(), "account id");
127  outMsg.writeInt8(CAST_S8(type), "type");
128  outMsg.writeInt16(CAST_S16(limit), "value");
129 }
130 
131 void AdminHandler::muteName(const std::string &name) const
132 {
133  createOutPacket(CMSG_ADMIN_MUTE_NAME);
134  outMsg.writeString(name, 24, "name");
135 }
136 
137 void AdminHandler::requestLogin(const Being *const being) const
138 {
139  if (being == nullptr)
140  return;
141 
142  createOutPacket(CMSG_ADMIN_ID_TO_LOGIN);
143  outMsg.writeBeingId(being->getId(), "account id");
144 }
145 
146 void AdminHandler::setTileType(const int x, const int y,
147  const int type) const
148 {
149  createOutPacket(CMSG_ADMIN_SET_TILE_TYPE);
150  outMsg.writeInt16(CAST_S16(x), "x");
151  outMsg.writeInt16(CAST_S16(y), "y");
152  outMsg.writeInt16(CAST_S16(type), "type");
153 }
154 
155 void AdminHandler::unequipAll(const Being *const being) const
156 {
157  if (being == nullptr)
158  return;
159 
160  createOutPacket(CMSG_ADMIN_UNEQUIP_ALL);
161  outMsg.writeBeingId(being->getId(), "account id");
162 }
163 
164 void AdminHandler::requestStats(const std::string &name) const
165 {
166  mStatsName = name;
167  createOutPacket(CMSG_ADMIN_REQUEST_STATS);
168  outMsg.writeString(name, 24, "name");
169 }
170 
171 void AdminHandler::monsterInfo(const std::string &name) const
172 {
173  Gm::runCommand("monsterinfo", name);
174 }
175 
176 void AdminHandler::itemInfo(const std::string &name) const
177 {
178  Gm::runCommand("iteminfo", name);
179 }
180 
181 void AdminHandler::whoDrops(const std::string &name) const
182 {
183  Gm::runCommand("whodrops", name);
184 }
185 
186 void AdminHandler::mobSearch(const std::string &name) const
187 {
188  Gm::runCommand("mobsearch", name);
189 }
190 
191 void AdminHandler::mobSpawnSearch(const std::string &name) const
192 {
193  Gm::runCommand("whereis", name);
194 }
195 
196 void AdminHandler::playerGmCommands(const std::string &name) const
197 {
198  Gm::runCharCommand("commands", name);
199 }
200 
201 void AdminHandler::playerCharGmCommands(const std::string &name) const
202 {
203  Gm::runCharCommand("charcommands", name);
204 }
205 
206 void AdminHandler::showLevel(const std::string &name) const
207 {
208  Gm::runCharCommand("exp", name);
209 }
210 
211 void AdminHandler::showStats(const std::string &name) const
212 {
213  Gm::runCharCommand("stats", name);
214 }
215 
216 void AdminHandler::showStorageList(const std::string &name) const
217 {
218  Gm::runCharCommand("storagelist", name);
219 }
220 
221 void AdminHandler::showCartList(const std::string &name) const
222 {
223  Gm::runCharCommand("cartlist", name);
224 }
225 
226 void AdminHandler::showInventoryList(const std::string &name) const
227 {
228  Gm::runCharCommand("itemlist", name);
229 }
230 
231 void AdminHandler::locatePlayer(const std::string &name) const
232 {
233  Gm::runCommand("where", name);
234 }
235 
236 void AdminHandler::showAccountInfo(const std::string &name) const
237 {
238  Gm::runCommand("accinfo", name);
239 }
240 
241 void AdminHandler::spawnSlave(const std::string &name) const
242 {
243  Gm::runCommand("summon", name);
244 }
245 
246 void AdminHandler::spawnClone(const std::string &name) const
247 {
248  Gm::runCommand("clone", name);
249 }
250 
251 void AdminHandler::spawnSlaveClone(const std::string &name) const
252 {
253  Gm::runCommand("slaveclone", name);
254 }
255 
256 void AdminHandler::spawnEvilClone(const std::string &name) const
257 {
258  Gm::runCommand("evilclone", name);
259 }
260 
261 void AdminHandler::savePosition(const std::string &name) const
262 {
263  Gm::runCharCommand("save", name);
264 }
265 
266 void AdminHandler::loadPosition(const std::string &name) const
267 {
268  Gm::runCharCommand("load", name);
269 }
270 
271 void AdminHandler::randomWarp(const std::string &name) const
272 {
273  Gm::runCharCommand("jump", name);
274 }
275 
276 void AdminHandler::gotoNpc(const std::string &name) const
277 {
278  Gm::runCommand("tonpc", name);
279 }
280 
281 void AdminHandler::killer(const std::string &name) const
282 {
283  Gm::runCharCommand("killer", name);
284 }
285 
286 void AdminHandler::killable(const std::string &name) const
287 {
288  Gm::runCharCommand("killable", name);
289 }
290 
291 void AdminHandler::heal(const std::string &name) const
292 {
293  Gm::runCharCommand("heal", name);
294 }
295 
296 void AdminHandler::alive(const std::string &name) const
297 {
298  Gm::runCharCommand("alive", name);
299 }
300 
301 void AdminHandler::disguise(const std::string &name) const
302 {
303  Gm::runCommand("disguise", name);
304 }
305 
306 void AdminHandler::immortal(const std::string &name) const
307 {
308  Gm::runCharCommand("monsterignore", name);
309 }
310 
311 void AdminHandler::hide(const std::string &name) const
312 {
313  Gm::runCharCommand("hide", name);
314 }
315 
316 void AdminHandler::nuke(const std::string &name) const
317 {
318  Gm::runCommand("nuke", name);
319 }
320 
321 void AdminHandler::kill(const std::string &name) const
322 {
323  Gm::runCharCommand("kill", name);
324 }
325 
326 void AdminHandler::jail(const std::string &name) const
327 {
328  Gm::runCommand("jail", name);
329 }
330 
331 void AdminHandler::unjail(const std::string &name) const
332 {
333  Gm::runCommand("unjail", name);
334 }
335 
336 void AdminHandler::npcMove(const std::string &name,
337  const int x,
338  const int y) const
339 {
340  Gm::runCommand("npcmove",
341  strprintf("%d %d %s",
342  x,
343  y,
344  name.c_str()));
345 }
346 
347 void AdminHandler::hideNpc(const std::string &name) const
348 {
349  Gm::runCommand("hidenpc", name);
350 }
351 
352 void AdminHandler::showNpc(const std::string &name) const
353 {
354  Gm::runCommand("shownpc", name);
355 }
356 
357 void AdminHandler::changePartyLeader(const std::string &name) const
358 {
359  Gm::runCommand("changeleader", name);
360 }
361 
362 void AdminHandler::partyRecall(const std::string &name) const
363 {
364  Gm::runCommand("partyrecall", name);
365 }
366 
367 void AdminHandler::breakGuild(const std::string &name) const
368 {
369  Gm::runCharCommand("breakguild", name);
370 }
371 
372 void AdminHandler::guildRecall(const std::string &name) const
373 {
374  Gm::runCommand("guildrecall", name);
375 }
376 
377 void AdminHandler::slide(const int x, const int y) const
378 {
379  Gm::runCommand("slide",
380  strprintf("%d %d", x, y));
381 }
382 
384 {
385  if (packetVersionZero < 20171214 &&
386  packetVersion < 20171220)
387  {
388  return;
389  }
390  createOutPacket(CMSG_CHANGE_DRESS);
391 }
392 
394 {
395  if (packetVersion < 20160622)
396  return;
397  createOutPacket(CMSG_ADMIN_RESET_COOLDOWNS);
398 }
399 
400 } // namespace EAthena
Net::AdminHandler * adminHandler
Definition: net.cpp:84
int BeingId
Definition: beingid.h:30
#define CAST_S8
Definition: cast.h:26
#define CAST_S16
Definition: cast.h:28
#define CAST_S32
Definition: cast.h:30
BeingId getId() const
Definition: actorsprite.h:64
Definition: being.h:96
void itemInfo(const std::string &name) const
void guildRecall(const std::string &name) const
void playerGmCommands(const std::string &name) const
void kick(const BeingId playerId) const
void disguise(const std::string &name) const
void spawnSlave(const std::string &name) const
void randomWarp(const std::string &name) const
void jail(const std::string &name) const
void heal(const std::string &name) const
void showCartList(const std::string &name) const
void alive(const std::string &name) const
void muteName(const std::string &name) const
void resetSkills() const
void spawnClone(const std::string &name) const
void npcMove(const std::string &name, const int x, const int y) const
void loadPosition(const std::string &name) const
void showLevel(const std::string &name) const
void localAnnounce(const std::string &text) const
void partyRecall(const std::string &name) const
void resetCooldowns() const
void playerCharGmCommands(const std::string &name) const
void breakGuild(const std::string &name) const
void showStats(const std::string &name) const
void killable(const std::string &name) const
void requestLogin(const Being *const being) const
void showStorageList(const std::string &name) const
void whoDrops(const std::string &name) const
void nuke(const std::string &name) const
void mobSearch(const std::string &name) const
void kill(const std::string &name) const
void recallName(const std::string &name) const
void warp(const std::string &map, const int x, const int y) const
void setTileType(const int x, const int y, const int type) const
void unjail(const std::string &name) const
void showNpc(const std::string &name) const
void hide(const bool h) const
void showAccountInfo(const std::string &name) const
void changeDress() const
void monsterInfo(const std::string &name) const
void spawnEvilClone(const std::string &name) const
void changePartyLeader(const std::string &name) const
void gotoNpc(const std::string &name) const
void showInventoryList(const std::string &name) const
void resetStats() const
void announce(const std::string &text) const
void locatePlayer(const std::string &name) const
void hideNpc(const std::string &name) const
void slide(const int x, const int y) const
void mute(const Being *const being, const int type, const int limit) const
void killer(const std::string &name) const
void unequipAll(const Being *const being) const
void spawnSlaveClone(const std::string &name) const
void requestStats(const std::string &name) const
void gotoName(const std::string &name) const
void mobSpawnSearch(const std::string &name) const
void savePosition(const std::string &name) const
static std::string mStatsName
Definition: adminhandler.h:167
void immortal(const std::string &name) const
int packetVersionZero
Definition: client.cpp:128
int packetVersion
Definition: client.cpp:125
#define A_UNUSED
Definition: localconsts.h:160
#define createOutPacket(name)
Definition: messageout.h:37
void runCommand(const std::string &command, const std::string &params)
Definition: gmfunctions.cpp:35
void runCharCommand(const std::string &command, const std::string &name, const std::string &params)
Definition: gmfunctions.cpp:61
std::string strprintf(const char *const format,...)