1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-GPL2
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*/
/* ScriptData
Name: gm_commandscript
%Complete: 100
Comment: All gm related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "ObjectMgr.h"
#include "Chat.h"
#include "AccountMgr.h"
#include "Language.h"
#include "World.h"
#include "Player.h"
#include "Opcodes.h"
class gm_commandscript : public CommandScript
{
public:
gm_commandscript() : CommandScript("gm_commandscript") { }
std::vector<ChatCommand> GetCommands() const override
{
static std::vector<ChatCommand> gmCommandTable =
{
{ "chat", SEC_GAMEMASTER, false, &HandleGMChatCommand, "" },
{ "fly", SEC_GAMEMASTER, false, &HandleGMFlyCommand, "" },
{ "ingame", SEC_PLAYER, true, &HandleGMListIngameCommand, "" },
{ "list", SEC_GAMEMASTER, true, &HandleGMListFullCommand, "" },
{ "visible", SEC_GAMEMASTER, false, &HandleGMVisibleCommand, "" },
{ "", SEC_GAMEMASTER, false, &HandleGMCommand, "" }
};
static std::vector<ChatCommand> commandTable =
{
{ "gm", SEC_MODERATOR, false, nullptr, "", gmCommandTable }
};
return commandTable;
}
// Enables or disables hiding of the staff badge
static bool HandleGMChatCommand(ChatHandler* handler, char const* args)
{
if (!*args)
{
WorldSession* session = handler->GetSession();
if (!AccountMgr::IsPlayerAccount(session->GetSecurity()) && session->GetPlayer()->isGMChat())
session->SendNotification(LANG_GM_CHAT_ON);
else
session->SendNotification(LANG_GM_CHAT_OFF);
return true;
}
std::string param = (char*)args;
if (param == "on")
{
handler->GetSession()->GetPlayer()->SetGMChat(true);
handler->GetSession()->SendNotification(LANG_GM_CHAT_ON);
return true;
}
if (param == "off")
{
handler->GetSession()->GetPlayer()->SetGMChat(false);
handler->GetSession()->SendNotification(LANG_GM_CHAT_OFF);
return true;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleGMFlyCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
Player* target = handler->getSelectedPlayer();
if (!target || handler->GetSession()->GetSecurity() < SEC_GAMEMASTER)
target = handler->GetSession()->GetPlayer();
WorldPacket data(12);
if (strncmp(args, "on", 3) == 0)
data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
else if (strncmp(args, "off", 4) == 0)
data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
else
{
handler->SendSysMessage(LANG_USE_BOL);
return false;
}
data.append(target->GetPackGUID());
data << uint32(0); // unknown
target->SendMessageToSet(&data, true);
handler->PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, handler->GetNameLink(target).c_str(), args);
handler->SetSentErrorMessage(true);
return false;
}
static bool HandleGMListIngameCommand(ChatHandler* handler, char const* /*args*/)
{
bool first = true;
bool footer = false;
TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
HashMapHolder<Player>::MapType const& m = sObjectAccessor->GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
{
AccountTypes itrSec = itr->second->GetSession()->GetSecurity();
if ((itr->second->IsGameMaster() || (!AccountMgr::IsPlayerAccount(itrSec) && itrSec <= AccountTypes(sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_GM_LIST)))) &&
(!handler->GetSession() || itr->second->IsVisibleGloballyFor(handler->GetSession()->GetPlayer())))
{
if (first)
{
first = false;
footer = true;
handler->SendSysMessage(LANG_GMS_ON_SRV);
handler->SendSysMessage("========================");
}
std::string const& name = itr->second->GetName();
uint8 size = name.size();
uint8 security = itrSec;
uint8 max = ((16 - size) / 2);
uint8 max2 = max;
if ((max + max2 + size) == 16)
max2 = max - 1;
if (handler->GetSession())
handler->PSendSysMessage("| %s GMLevel %u", name.c_str(), security);
else
handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name.c_str(), max2, " ", security);
}
}
if (footer)
handler->SendSysMessage("========================");
if (first)
handler->SendSysMessage(LANG_GMS_NOT_LOGGED);
return true;
}
/// Display the list of GMs
static bool HandleGMListFullCommand(ChatHandler* handler, char const* /*args*/)
{
///- Get the accounts with GM Level >0
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_GM_ACCOUNTS);
stmt->setUInt8(0, uint8(SEC_MODERATOR));
stmt->setInt32(1, int32(realmID));
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (result)
{
handler->SendSysMessage(LANG_GMLIST);
handler->SendSysMessage("========================");
///- Cycle through them. Display username and GM level
do
{
Field* fields = result->Fetch();
char const* name = fields[0].GetCString();
uint8 security = fields[1].GetUInt8();
uint8 max = (16 - strlen(name)) / 2;
uint8 max2 = max;
if ((max + max2 + strlen(name)) == 16)
max2 = max - 1;
if (handler->GetSession())
handler->PSendSysMessage("| %s GMLevel %u", name, security);
else
handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name, max2, " ", security);
} while (result->NextRow());
handler->SendSysMessage("========================");
}
else
handler->PSendSysMessage(LANG_GMLIST_EMPTY);
return true;
}
//Enable\Disable Invisible mode
static bool HandleGMVisibleCommand(ChatHandler* handler, char const* args)
{
Player* _player = handler->GetSession()->GetPlayer();
if (!*args)
{
handler->PSendSysMessage(LANG_YOU_ARE, _player->isGMVisible() ? handler->GetTrinityString(LANG_VISIBLE) : handler->GetTrinityString(LANG_INVISIBLE));
handler->SetSentErrorMessage(true);
return false;
}
const uint32 VISUAL_AURA = 37800;
std::string param = (char*)args;
if (param == "on")
{
if (_player->HasAura(VISUAL_AURA, 0))
_player->RemoveAurasDueToSpell(VISUAL_AURA);
_player->SetGMVisible(true);
//_player->UpdateObjectVisibility();
handler->GetSession()->SendNotification(LANG_INVISIBLE_VISIBLE);
handler->SetSentErrorMessage(true);
return false;
}
if (param == "off")
{
_player->AddAura(VISUAL_AURA, _player);
_player->SetGMVisible(false);
//_player->UpdateObjectVisibility();
handler->GetSession()->SendNotification(LANG_INVISIBLE_INVISIBLE);
handler->SetSentErrorMessage(true);
return false;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
//Enable\Disable GM Mode
static bool HandleGMCommand(ChatHandler* handler, char const* args)
{
Player* _player = handler->GetSession()->GetPlayer();
if (!*args)
{
handler->GetSession()->SendNotification(_player->IsGameMaster() ? LANG_GM_ON : LANG_GM_OFF);
handler->SetSentErrorMessage(true);
return false;
}
std::string param = (char*)args;
if (param == "on")
{
_player->SetGameMaster(true);
handler->GetSession()->SendNotification(LANG_GM_ON);
_player->UpdateTriggerVisibility();
handler->SetSentErrorMessage(true);
return false;
}
if (param == "off")
{
_player->SetGameMaster(false);
handler->GetSession()->SendNotification(LANG_GM_OFF);
_player->UpdateTriggerVisibility();
handler->SetSentErrorMessage(true);
return false;
}
handler->SendSysMessage(LANG_USE_BOL);
handler->SetSentErrorMessage(true);
return false;
}
};
void AddSC_gm_commandscript()
{
new gm_commandscript();
}
|