GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/adminhandler.cpp Lines: 2 163 1.2 %
Date: 2021-03-17 Branches: 2 184 1.1 %

Line Branch Exec Source
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
24
#include "net/eathena/adminhandler.h"
25
26
#include "being/being.h"
27
28
#include "net/eathena/messageout.h"
29
#include "net/eathena/protocolout.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
1
std::string AdminHandler::mStatsName;
43
44
AdminHandler::AdminHandler() :
45
    Ea::AdminHandler()
46
{
47
    adminHandler = this;
48
}
49
50
AdminHandler::~AdminHandler()
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
81
void AdminHandler::kickAll() const
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
94
void AdminHandler::resetStats() const
95
{
96
    createOutPacket(CMSG_ADMIN_RESET_PLAYER);
97
    outMsg.writeInt16(0, "flag");
98
}
99
100
void AdminHandler::resetSkills() const
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
383
void AdminHandler::changeDress() const
384
{
385
    if (packetVersionZero < 20171214 &&
386
        packetVersion < 20171220)
387
    {
388
        return;
389
    }
390
    createOutPacket(CMSG_CHANGE_DRESS);
391
}
392
393
void AdminHandler::resetCooldowns() const
394
{
395
    if (packetVersion < 20160622)
396
        return;
397
    createOutPacket(CMSG_ADMIN_RESET_COOLDOWNS);
398
}
399
400

3
}  // namespace EAthena