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

3
}  // namespace EAthena