Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
cs_gm.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6/* ScriptData
7Name: gm_commandscript
8%Complete: 100
9Comment: All gm related commands
10Category: commandscripts
11EndScriptData */
12
13#include "AccountMgr.h"
14#include "Chat.h"
15#include "DatabaseEnv.h"
16#include "GMNoteUtils.h"
17#include "Language.h"
18#include "ObjectMgr.h"
19#include "Opcodes.h"
20#include "Player.h"
21#include "ScriptMgr.h"
22#include "World.h"
23
25{
26public:
27 gm_commandscript() : CommandScript("gm_commandscript") { }
28
29 std::vector<ChatCommand> GetCommands() const OVERRIDE
30 {
31 static std::vector<ChatCommand> gmCommandTable =
32 {
39 { "", rbac::RBAC_PERM_COMMAND_GM, false, &HandleGMCommand, "", },
40 };
41 static std::vector<ChatCommand> commandTable =
42 {
43 { "gm", rbac::RBAC_PERM_COMMAND_GM, false, NULL, "", gmCommandTable },
44 };
45 return commandTable;
46 }
47
48 // Enables or disables hiding of the staff badge
49 static bool HandleGMChatCommand(ChatHandler* handler, char const* args)
50 {
51 if (WorldSession* session = handler->GetSession())
52 {
53 if (!*args)
54 {
55 if (session->HasPermission(rbac::RBAC_PERM_CHAT_USE_STAFF_BADGE) && session->GetPlayer()->isGMChat())
56 session->SendNotification(LANG_GM_CHAT_ON);
57 else
58 session->SendNotification(LANG_GM_CHAT_OFF);
59 return true;
60 }
61
62 std::string param = (char*)args;
63
64 if (param == "on")
65 {
66 session->GetPlayer()->SetGMChat(true);
67 session->SendNotification(LANG_GM_CHAT_ON);
68 return true;
69 }
70
71 if (param == "off")
72 {
73 session->GetPlayer()->SetGMChat(false);
74 session->SendNotification(LANG_GM_CHAT_OFF);
75 return true;
76 }
77 }
78
80 handler->SetSentErrorMessage(true);
81 return false;
82 }
83
84 static bool HandleGMFlyCommand(ChatHandler* handler, char const* args)
85 {
86 if (!*args)
87 return false;
88
89 Player* target = handler->getSelectedPlayer();
90 if (!target)
91 target = handler->GetSession()->GetPlayer();
92
93 WorldPacket data;
94 if (strncmp(args, "on", 3) == 0)
95 target->SetCanFly(true);
96 else if (strncmp(args, "off", 4) == 0)
97 target->SetCanFly(false);
98 else
99 {
101 return false;
102 }
103 handler->PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, handler->GetNameLink(target).c_str(), args);
104 return true;
105 }
106
107 static bool HandleGMListIngameCommand(ChatHandler* handler, char const* /*args*/)
108 {
109 bool first = true;
110 bool footer = false;
111
112
114 HashMapHolder<Player>::MapType const& m = sObjectAccessor->GetPlayers();
115 for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
116 {
117 AccountTypes itrSec = itr->second->GetSession()->GetSecurity();
118 if ((itr->second->IsGameMaster() ||
119 (itr->second->GetSession()->HasPermission(rbac::RBAC_PERM_COMMANDS_APPEAR_IN_GM_LIST) &&
121 (!handler->GetSession() || itr->second->IsVisibleGloballyFor(handler->GetSession()->GetPlayer())))
122 {
123 if (first)
124 {
125 first = false;
126 footer = true;
128 handler->SendSysMessage("========================");
129 }
130 std::string const& name = itr->second->GetName();
131 uint8 size = name.size();
132 AccountTypes security = itrSec;
133 uint8 max = ((16 - size) / 2);
134 uint8 max2 = max;
135 if ((max + max2 + size) == 16)
136 max2 = max - 1;
137 if (handler->GetSession())
138 handler->PSendSysMessage("| %s GMLevel %u", name.c_str(), uint8(security));
139 else
140 handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name.c_str(), max2, " ", uint8(security));
141 }
142 }
143 if (footer)
144 handler->SendSysMessage("========================");
145 if (first)
147 return true;
148 }
149
151 static bool HandleGMListFullCommand(ChatHandler* handler, char const* /*args*/)
152 {
154 PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_GM_ACCOUNTS);
156 stmt->setInt32(1, int32(realmID));
157 PreparedQueryResult result = LoginDatabase.Query(stmt);
158
159 if (result)
160 {
161 handler->SendSysMessage(LANG_GMLIST);
162 handler->SendSysMessage("========================");
164 do
165 {
166 Field* fields = result->Fetch();
167 char const* name = fields[0].GetCString();
168 uint8 security = fields[1].GetUInt8();
169 uint8 max = (16 - strlen(name)) / 2;
170 uint8 max2 = max;
171 if ((max + max2 + strlen(name)) == 16)
172 max2 = max - 1;
173 if (handler->GetSession())
174 handler->PSendSysMessage("| %s GMLevel %u", name, security);
175 else
176 handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name, max2, " ", security);
177 } while (result->NextRow());
178 handler->SendSysMessage("========================");
179 }
180 else
182 return true;
183 }
184
185 static bool HandleGMNoteCommand(ChatHandler* handler, char const* args)
186 {
187 WorldSession* session = handler->GetSession();
188 if (!session || !session->GetPlayer())
189 {
190 handler->SendSysMessage("This command can only be used in game.");
191 handler->SetSentErrorMessage(true);
192 return false;
193 }
194
195 while (*args == ' ' || *args == '\t')
196 ++args;
197
198 std::string note(args);
199 while (!note.empty() && (note[note.size() - 1] == ' ' || note[note.size() - 1] == '\t'))
200 note.erase(note.size() - 1);
201
203 if (!validation.IsValid)
204 {
205 handler->SendSysMessage(validation.Message);
206 handler->SetSentErrorMessage(true);
207 return false;
208 }
209
210 Player* player = session->GetPlayer();
212 location.MapId = player->GetMapId();
213 location.ZoneId = player->GetZoneId();
214 location.AreaId = player->GetAreaId();
215 location.X = player->GetPositionX();
216 location.Y = player->GetPositionY();
217 location.Z = player->GetPositionZ();
218 location.Orientation = player->GetOrientation();
219
220 PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_GM_NOTE);
221 stmt->setInt32(0, int32(realmID));
222 stmt->setUInt32(1, session->GetAccountId());
223 stmt->setUInt32(2, player->GetGUIDLow());
224 stmt->setUInt32(3, location.MapId);
225 stmt->setUInt32(4, location.ZoneId);
226 stmt->setUInt32(5, location.AreaId);
227 stmt->setFloat(6, location.X);
228 stmt->setFloat(7, location.Y);
229 stmt->setFloat(8, location.Z);
230 stmt->setFloat(9, location.Orientation);
231 stmt->setString(10, Skyfire::FormatGMNoteLocation(location));
232 stmt->setString(11, note);
233 LoginDatabase.Execute(stmt);
234
235 handler->SendSysMessage("GM note saved.");
236 return true;
237 }
238
239 //Enable\Disable Invisible mode
240 static bool HandleGMVisibleCommand(ChatHandler* handler, char const* args)
241 {
242 if (!*args)
243 {
245 return true;
246 }
247
248 const uint32 VISUAL_AURA = 37800;
249 std::string param = (char*)args;
250 Player* player = handler->GetSession()->GetPlayer();
251
252 if (param == "on")
253 {
254 if (player->HasAura(VISUAL_AURA, 0))
255 player->RemoveAurasDueToSpell(VISUAL_AURA);
256
257 player->SetGMVisible(true);
259 return true;
260 }
261
262 if (param == "off")
263 {
265 player->SetGMVisible(false);
266
267 player->AddAura(VISUAL_AURA, player);
268
269 return true;
270 }
271
273 handler->SetSentErrorMessage(true);
274 return false;
275 }
276
277 //Enable\Disable GM Mode
278 static bool HandleGMCommand(ChatHandler* handler, char const* args)
279 {
280 if (!*args)
281 {
282 if (handler->GetSession()->GetPlayer()->IsGameMaster())
284 else
286 return true;
287 }
288
289 std::string param = (char*)args;
290
291 if (param == "on")
292 {
293 handler->GetSession()->GetPlayer()->SetGameMaster(true);
296#ifdef _DEBUG_VMAPS
298 vMapManager->processCommand("stoplog");
299#endif
300 return true;
301 }
302
303 if (param == "off")
304 {
305 handler->GetSession()->GetPlayer()->SetGameMaster(false);
308#ifdef _DEBUG_VMAPS
310 vMapManager->processCommand("startlog");
311#endif
312 return true;
313 }
314
316 handler->SetSentErrorMessage(true);
317 return false;
318 }
319};
320
322{
323 new gm_commandscript();
324}
AccountTypes
Definition Common.h:129
@ SEC_MODERATOR
Definition Common.h:131
std::int32_t int32
Definition Define.h:73
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
#define OVERRIDE
Definition Define.h:60
@ LANG_INVISIBLE_INVISIBLE
Definition Language.h:580
@ LANG_YOU_ARE
Definition Language.h:53
@ LANG_GMLIST
Definition Language.h:604
@ LANG_GMS_ON_SRV
Definition Language.h:29
@ LANG_GMLIST_EMPTY
Definition Language.h:606
@ LANG_USE_BOL
Definition Language.h:265
@ LANG_GMS_NOT_LOGGED
Definition Language.h:30
@ LANG_GM_OFF
Definition Language.h:340
@ LANG_INVISIBLE
Definition Language.h:55
@ LANG_COMMAND_FLYMODE_STATUS
Definition Language.h:459
@ LANG_GM_CHAT_ON
Definition Language.h:341
@ LANG_GM_CHAT_OFF
Definition Language.h:342
@ LANG_INVISIBLE_VISIBLE
Definition Language.h:581
@ LANG_VISIBLE
Definition Language.h:54
@ LANG_GM_ON
Definition Language.h:339
@ LOGIN_INS_GM_NOTE
@ LOGIN_SEL_GM_ACCOUNTS
#define sObjectAccessor
Skyfire::AutoPtr< PreparedResultSet, Skyfire::Mutex > PreparedQueryResult
Definition QueryResult.h:94
#define SF_SHARED_GUARD
Definition SharedMutex.h:17
virtual std::string GetNameLink() const
Definition Chat.h:79
Player * getSelectedPlayer()
Definition Chat.cpp:829
WorldSession * GetSession()
Definition Chat.h:43
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
Definition Chat.cpp:221
void SetSentErrorMessage(bool val)
Definition Chat.h:114
virtual void SendSysMessage(const char *str)
Definition Chat.cpp:153
virtual const char * GetSkyFireString(int32 entry) const
Definition Chat.cpp:68
CommandScript(const char *name)
Definition Field.h:16
uint8 GetUInt8() const
Definition Field.h:26
char const * GetCString() const
Definition Field.h:213
static SF_SHARED_MUTEX * GetLock()
UNORDERED_MAP< uint64, T * > MapType
uint32 GetGUIDLow() const
Definition Object.h:120
bool isGMVisible() const
Definition Player.h:1390
void SetGameMaster(bool on)
Definition Player.cpp:2944
void UpdateTriggerVisibility()
Definition Player.cpp:18217
bool IsGameMaster() const
Definition Player.h:1369
void SetGMVisible(bool on)
Definition Player.cpp:2995
void setFloat(const uint8 index, const float value)
void setString(const uint8 index, const std::string &value)
void setUInt32(const uint8 index, const uint32 value)
void setUInt8(const uint8 index, const uint8 value)
void setInt32(const uint8 index, const int32 value)
void RemoveAurasDueToSpell(uint32 spellId, uint64 casterGUID=0, uint32 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Aura * AddAura(uint32 spellId, Unit *target)
bool HasAura(uint32 spellId, uint64 casterGUID=0, uint64 itemCasterGUID=0, uint32 reqEffMask=0) const
bool SetCanFly(bool enable)
Definition Unit.cpp:9219
virtual bool processCommand(char *pCommand)=0
static IVMapManager * createOrGetVMapManager()
uint32 GetMapId() const
Definition Object.h:546
uint32 GetAreaId() const
Definition Object.cpp:1602
uint32 GetZoneId() const
Definition Object.cpp:1597
Player session in the World.
void SendNotification(const char *format,...) ATTR_PRINTF(2
Player * GetPlayer() const
uint32 GetAccountId() const
static bool HandleGMNoteCommand(ChatHandler *handler, char const *args)
Definition cs_gm.cpp:185
static bool HandleGMChatCommand(ChatHandler *handler, char const *args)
Definition cs_gm.cpp:49
std::vector< ChatCommand > GetCommands() const OVERRIDE
Definition cs_gm.cpp:29
static bool HandleGMListFullCommand(ChatHandler *handler, char const *)
Display the list of GMs.
Definition cs_gm.cpp:151
static bool HandleGMFlyCommand(ChatHandler *handler, char const *args)
Definition cs_gm.cpp:84
static bool HandleGMListIngameCommand(ChatHandler *handler, char const *)
Definition cs_gm.cpp:107
static bool HandleGMVisibleCommand(ChatHandler *handler, char const *args)
Definition cs_gm.cpp:240
static bool HandleGMCommand(ChatHandler *handler, char const *args)
Definition cs_gm.cpp:278
void AddSC_gm_commandscript()
Definition cs_gm.cpp:321
#define sWorld
Definition World.h:910
uint32 realmID
Id of the realm.
Definition Main.cpp:73
@ CONFIG_GM_LEVEL_IN_GM_LIST
Definition World.h:251
std::string FormatGMNoteLocation(GMNoteLocation const &location)
GMNoteValidation ValidateGMNoteText(std::string const &note)
@ RBAC_PERM_COMMAND_GM
Definition RBAC.h:259
@ RBAC_PERM_COMMAND_GM_INGAME
Definition RBAC.h:262
@ RBAC_PERM_COMMAND_GM_CHAT
Definition RBAC.h:260
@ RBAC_PERM_CHAT_USE_STAFF_BADGE
Definition RBAC.h:77
@ RBAC_PERM_COMMAND_GM_VISIBLE
Definition RBAC.h:264
@ RBAC_PERM_COMMAND_GM_LIST
Definition RBAC.h:263
@ RBAC_PERM_COMMAND_GM_FLY
Definition RBAC.h:261
@ RBAC_PERM_COMMANDS_APPEAR_IN_GM_LIST
Definition RBAC.h:74
@ RBAC_PERM_COMMAND_GM_NOTE
Definition RBAC.h:695
LoginDatabaseWorkerPool LoginDatabase
Definition Main.cpp:54
float GetPositionZ() const
Definition Object.h:330
float GetOrientation() const
Definition Object.h:331
float GetPositionX() const
Definition Object.h:328
float GetPositionY() const
Definition Object.h:329