TrinityCore
Loading...
Searching...
No Matches
cs_gm.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18/* ScriptData
19Name: gm_commandscript
20%Complete: 100
21Comment: All gm related commands
22Category: commandscripts
23EndScriptData */
24
25#include "ScriptMgr.h"
26#include "AccountMgr.h"
27#include "Chat.h"
28#include "DatabaseEnv.h"
29#include "Language.h"
30#include "ObjectAccessor.h"
31#include "Opcodes.h"
32#include "Player.h"
33#include "Realm.h"
34#include "World.h"
35#include "WorldSession.h"
36
37using namespace Trinity::ChatCommands;
38
40{
41public:
42 gm_commandscript() : CommandScript("gm_commandscript") { }
43
45 {
46 static ChatCommandTable gmCommandTable =
47 {
53 { "on", HandleGMOnCommand, rbac::RBAC_PERM_COMMAND_GM, Console::No },
54 { "off", HandleGMOffCommand, rbac::RBAC_PERM_COMMAND_GM, Console::No },
55 };
56 static ChatCommandTable commandTable =
57 {
58 { "gm", gmCommandTable },
59 };
60 return commandTable;
61 }
62
63 // Enables or disables the staff badge
64 static bool HandleGMChatCommand(ChatHandler* handler, Optional<bool> enableArg)
65 {
66 if (WorldSession* session = handler->GetSession())
67 {
68 if (!enableArg)
69 {
70 if (session->HasPermission(rbac::RBAC_PERM_CHAT_USE_STAFF_BADGE) && session->GetPlayer()->isGMChat())
71 session->SendNotification(LANG_GM_CHAT_ON);
72 else
73 session->SendNotification(LANG_GM_CHAT_OFF);
74 return true;
75 }
76
77 if (*enableArg)
78 {
79 session->GetPlayer()->SetGMChat(true);
80 session->SendNotification(LANG_GM_CHAT_ON);
81 return true;
82 }
83 else
84 {
85 session->GetPlayer()->SetGMChat(false);
86 session->SendNotification(LANG_GM_CHAT_OFF);
87 return true;
88 }
89 }
90
92 handler->SetSentErrorMessage(true);
93 return false;
94 }
95
96 static bool HandleGMFlyCommand(ChatHandler* handler, bool enable)
97 {
98 Player* target = handler->getSelectedPlayer();
99 if (!target)
100 target = handler->GetSession()->GetPlayer();
101
102 WorldPacket data(12);
103 if (enable)
105 else
107
108 data << target->GetPackGUID();
109 data << uint32(0); // unknown
110 target->SendMessageToSet(&data, true);
111 handler->PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, handler->GetNameLink(target).c_str(), enable ? "on" : "off");
112 return true;
113 }
114
116 {
117 bool first = true;
118 bool footer = false;
119
120 std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
121 for (auto const& [playerGuid, player] : ObjectAccessor::GetPlayers())
122 {
123 AccountTypes playerSec = player->GetSession()->GetSecurity();
124 if ((player->IsGameMaster() ||
125 (player->GetSession()->HasPermission(rbac::RBAC_PERM_COMMANDS_APPEAR_IN_GM_LIST) &&
126 playerSec <= AccountTypes(sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_GM_LIST)))) &&
127 (!handler->GetSession() || player->IsVisibleGloballyFor(handler->GetSession()->GetPlayer())))
128 {
129 if (first)
130 {
131 first = false;
132 footer = true;
134 handler->SendSysMessage("========================");
135 }
136 std::string const& name = player->GetName();
137 uint8 size = uint8(name.size());
138 uint8 security = playerSec;
139 uint8 max = ((16 - size) / 2);
140 uint8 max2 = max;
141 if ((max + max2 + size) == 16)
142 max2 = max - 1;
143 if (handler->GetSession())
144 handler->PSendSysMessage("| %s GMLevel %u", name.c_str(), security);
145 else
146 handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name.c_str(), max2, " ", security);
147 }
148 }
149 if (footer)
150 handler->SendSysMessage("========================");
151 if (first)
153 return true;
154 }
155
158 {
161 stmt->setUInt8(0, uint8(SEC_MODERATOR));
162 stmt->setInt32(1, int32(realm.Id.Realm));
163 PreparedQueryResult result = LoginDatabase.Query(stmt);
164
165 if (result)
166 {
167 handler->SendSysMessage(LANG_GMLIST);
168 handler->SendSysMessage("========================");
170 do
171 {
172 Field* fields = result->Fetch();
173 char const* name = fields[0].GetCString();
174 uint8 security = fields[1].GetUInt8();
175 uint8 max = (16 - strlen(name)) / 2;
176 uint8 max2 = max;
177 if ((max + max2 + strlen(name)) == 16)
178 max2 = max - 1;
179 if (handler->GetSession())
180 handler->PSendSysMessage("| %s GMLevel %u", name, security);
181 else
182 handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name, max2, " ", security);
183 } while (result->NextRow());
184 handler->SendSysMessage("========================");
185 }
186 else
188 return true;
189 }
190
191 //Enable\Disable Invisible mode
192 static bool HandleGMVisibleCommand(ChatHandler* handler, Optional<bool> visibleArg)
193 {
194 Player* _player = handler->GetSession()->GetPlayer();
195
196 if (!visibleArg)
197 {
199 return true;
200 }
201
202 const uint32 VISUAL_AURA = 37800;
203
204 if (*visibleArg)
205 {
206 if (_player->HasAura(VISUAL_AURA))
207 _player->RemoveAurasDueToSpell(VISUAL_AURA);
208
209 _player->SetGMVisible(true);
210 _player->UpdateObjectVisibility();
212 }
213 else
214 {
215 _player->AddAura(VISUAL_AURA, _player);
216 _player->SetGMVisible(false);
217 _player->UpdateObjectVisibility();
219 }
220
221 return true;
222 }
223
224 static bool HandleGMOnCommand(ChatHandler* handler)
225 {
226 handler->GetPlayer()->SetGameMaster(true);
229 return true;
230 }
231
232 static bool HandleGMOffCommand(ChatHandler* handler)
233 {
234 handler->GetPlayer()->SetGameMaster(false);
237 return true;
238 }
239};
240
242{
243 new gm_commandscript();
244}
AccountTypes
Definition Common.h:39
@ SEC_MODERATOR
Definition Common.h:41
std::shared_ptr< PreparedResultSet > PreparedQueryResult
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
uint8_t uint8
Definition Define.h:135
int32_t int32
Definition Define.h:129
uint32_t uint32
Definition Define.h:133
@ LANG_INVISIBLE_INVISIBLE
Definition Language.h:663
@ LANG_YOU_ARE
Definition Language.h:72
@ LANG_GMLIST
Definition Language.h:687
@ LANG_GMS_ON_SRV
Definition Language.h:48
@ LANG_GMLIST_EMPTY
Definition Language.h:689
@ LANG_USE_BOL
Definition Language.h:309
@ LANG_GMS_NOT_LOGGED
Definition Language.h:49
@ LANG_GM_OFF
Definition Language.h:388
@ LANG_INVISIBLE
Definition Language.h:74
@ LANG_COMMAND_FLYMODE_STATUS
Definition Language.h:542
@ LANG_GM_CHAT_ON
Definition Language.h:389
@ LANG_GM_CHAT_OFF
Definition Language.h:390
@ LANG_INVISIBLE_VISIBLE
Definition Language.h:664
@ LANG_VISIBLE
Definition Language.h:73
@ LANG_GM_ON
Definition Language.h:387
@ LOGIN_SEL_GM_ACCOUNTS
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
Player * getSelectedPlayer()
Definition Chat.cpp:302
WorldSession * GetSession()
Definition Chat.h:46
virtual std::string GetNameLink() const
Definition Chat.cpp:46
void SetSentErrorMessage(bool val)
Definition Chat.h:134
Player * GetPlayer() const
Definition Chat.cpp:34
void PSendSysMessage(char const *fmt, Args &&... args)
Definition Chat.h:69
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:101
virtual char const * GetTrinityString(uint32 entry) const
Definition Chat.cpp:36
Class used to access individual fields of database query result.
Definition Field.h:92
uint8 GetUInt8() const
Definition Field.cpp:29
char const * GetCString() const
Definition Field.cpp:117
PackedGuid const & GetPackGUID() const
Definition Object.h:80
bool isGMVisible() const
Definition Player.h:1006
void SetGameMaster(bool on)
Definition Player.cpp:2198
void UpdateTriggerVisibility()
Definition Player.cpp:22208
void SetGMVisible(bool on)
Definition Player.cpp:2258
void UpdateObjectVisibility(bool forced=true) override
Definition Player.cpp:22297
void SendMessageToSet(WorldPacket const *data, bool self) const override
Definition Player.h:1747
void setInt32(uint8 index, int32 value)
void setUInt8(uint8 index, uint8 value)
Aura * AddAura(uint32 spellId, Unit *target)
Definition Unit.cpp:11964
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint8 reqEffMask=0) const
Definition Unit.cpp:4535
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint8 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:3784
void SetOpcode(uint16 opcode)
Definition WorldPacket.h:81
Player session in the World.
void SendNotification(const char *format,...) ATTR_PRINTF(2
Player * GetPlayer() const
static bool HandleGMChatCommand(ChatHandler *handler, Optional< bool > enableArg)
Definition cs_gm.cpp:64
ChatCommandTable GetCommands() const override
Definition cs_gm.cpp:44
static bool HandleGMFlyCommand(ChatHandler *handler, bool enable)
Definition cs_gm.cpp:96
static bool HandleGMOffCommand(ChatHandler *handler)
Definition cs_gm.cpp:232
static bool HandleGMVisibleCommand(ChatHandler *handler, Optional< bool > visibleArg)
Definition cs_gm.cpp:192
static bool HandleGMListIngameCommand(ChatHandler *handler)
Definition cs_gm.cpp:115
static bool HandleGMListFullCommand(ChatHandler *handler)
Display the list of GMs.
Definition cs_gm.cpp:157
static bool HandleGMOnCommand(ChatHandler *handler)
Definition cs_gm.cpp:224
void AddSC_gm_commandscript()
Definition cs_gm.cpp:241
@ SMSG_MOVE_SET_CAN_FLY
Definition Opcodes.h:864
@ SMSG_MOVE_UNSET_CAN_FLY
Definition Opcodes.h:865
#define sWorld
Definition World.h:900
Realm realm
Definition World.cpp:3605
@ CONFIG_GM_LEVEL_IN_GM_LIST
Definition World.h:263
TC_GAME_API HashMapHolder< Player >::MapType const & GetPlayers()
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:50
@ RBAC_PERM_COMMAND_GM
Definition RBAC.h:245
@ RBAC_PERM_COMMAND_GM_INGAME
Definition RBAC.h:248
@ RBAC_PERM_COMMAND_GM_CHAT
Definition RBAC.h:246
@ RBAC_PERM_CHAT_USE_STAFF_BADGE
Definition RBAC.h:90
@ RBAC_PERM_COMMAND_GM_VISIBLE
Definition RBAC.h:250
@ RBAC_PERM_COMMAND_GM_LIST
Definition RBAC.h:249
@ RBAC_PERM_COMMAND_GM_FLY
Definition RBAC.h:247
@ RBAC_PERM_COMMANDS_APPEAR_IN_GM_LIST
Definition RBAC.h:87
uint32 Realm
Definition Realm.h:44
RealmHandle Id
Definition Realm.h:67