TrinityCore
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 "ChatCommand.h"
29#include "DatabaseEnv.h"
30#include "Language.h"
31#include "ObjectAccessor.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 if (enable)
103 {
104 target->SetCanFly(true);
106 }
107 else
108 {
109 target->SetCanFly(false);
111 }
112
113 handler->PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, handler->GetNameLink(target).c_str(), enable ? "on" : "off");
114 return true;
115 }
116
118 {
119 bool first = true;
120 bool footer = false;
121
122 std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
123 for (auto&& [playerGuid, player] : ObjectAccessor::GetPlayers())
124 {
125 AccountTypes playerSec = player->GetSession()->GetSecurity();
126 if ((player->IsGameMaster() ||
127 (player->GetSession()->HasPermission(rbac::RBAC_PERM_COMMANDS_APPEAR_IN_GM_LIST) &&
128 playerSec <= AccountTypes(sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_GM_LIST)))) &&
129 (!handler->GetSession() || player->IsVisibleGloballyFor(handler->GetSession()->GetPlayer())))
130 {
131 if (first)
132 {
133 first = false;
134 footer = true;
136 handler->SendSysMessage("========================");
137 }
138 std::string const& name = player->GetName();
139 uint8 size = uint8(name.size());
140 uint8 security = playerSec;
141 uint8 max = ((16 - size) / 2);
142 uint8 max2 = max;
143 if ((max + max2 + size) == 16)
144 max2 = max - 1;
145 if (handler->GetSession())
146 handler->PSendSysMessage("| %s GMLevel %u", name.c_str(), security);
147 else
148 handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name.c_str(), max2, " ", security);
149 }
150 }
151 if (footer)
152 handler->SendSysMessage("========================");
153 if (first)
155 return true;
156 }
157
160 {
163 stmt->setUInt8(0, uint8(SEC_MODERATOR));
164 stmt->setInt32(1, int32(realm.Id.Realm));
165 PreparedQueryResult result = LoginDatabase.Query(stmt);
166
167 if (result)
168 {
169 handler->SendSysMessage(LANG_GMLIST);
170 handler->SendSysMessage("========================");
172 do
173 {
174 Field* fields = result->Fetch();
175 char const* name = fields[0].GetCString();
176 uint8 security = fields[1].GetUInt8();
177 uint8 max = (16 - strlen(name)) / 2;
178 uint8 max2 = max;
179 if ((max + max2 + strlen(name)) == 16)
180 max2 = max - 1;
181 if (handler->GetSession())
182 handler->PSendSysMessage("| %s GMLevel %u", name, security);
183 else
184 handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name, max2, " ", security);
185 } while (result->NextRow());
186 handler->SendSysMessage("========================");
187 }
188 else
190 return true;
191 }
192
193 //Enable\Disable Invisible mode
194 static bool HandleGMVisibleCommand(ChatHandler* handler, Optional<bool> visibleArg)
195 {
196 Player* _player = handler->GetSession()->GetPlayer();
197
198 if (!visibleArg)
199 {
201 return true;
202 }
203
204 const uint32 VISUAL_AURA = 37800;
205
206 if (*visibleArg)
207 {
208 if (_player->HasAura(VISUAL_AURA))
209 _player->RemoveAurasDueToSpell(VISUAL_AURA);
210
211 _player->SetGMVisible(true);
212 _player->UpdateObjectVisibility();
214 }
215 else
216 {
217 _player->AddAura(VISUAL_AURA, _player);
218 _player->SetGMVisible(false);
219 _player->UpdateObjectVisibility();
221 }
222
223 return true;
224 }
225
226 static bool HandleGMOnCommand(ChatHandler* handler)
227 {
228 handler->GetPlayer()->SetGameMaster(true);
231 return true;
232 }
233
234 static bool HandleGMOffCommand(ChatHandler* handler)
235 {
236 handler->GetPlayer()->SetGameMaster(false);
239 return true;
240 }
241};
242
244{
245 new gm_commandscript();
246}
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.
Definition: DatabaseEnv.cpp:22
uint8_t uint8
Definition: Define.h:144
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
@ LANG_INVISIBLE_INVISIBLE
Definition: Language.h:660
@ LANG_YOU_ARE
Definition: Language.h:72
@ LANG_GMLIST
Definition: Language.h:684
@ LANG_GMS_ON_SRV
Definition: Language.h:48
@ LANG_GMLIST_EMPTY
Definition: Language.h:686
@ LANG_USE_BOL
Definition: Language.h:310
@ LANG_GMS_NOT_LOGGED
Definition: Language.h:49
@ LANG_GM_OFF
Definition: Language.h:389
@ LANG_INVISIBLE
Definition: Language.h:74
@ LANG_COMMAND_FLYMODE_STATUS
Definition: Language.h:539
@ LANG_GM_CHAT_ON
Definition: Language.h:390
@ LANG_GM_CHAT_OFF
Definition: Language.h:391
@ LANG_INVISIBLE_VISIBLE
Definition: Language.h:661
@ LANG_VISIBLE
Definition: Language.h:73
@ LANG_GM_ON
Definition: Language.h:388
@ LOGIN_SEL_GM_ACCOUNTS
Definition: LoginDatabase.h:84
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
Player * getSelectedPlayer()
Definition: Chat.cpp:200
WorldSession * GetSession()
Definition: Chat.h:42
virtual std::string GetNameLink() const
Definition: Chat.cpp:58
void PSendSysMessage(const char *fmt, Args &&... args)
Definition: Chat.h:57
void SetSentErrorMessage(bool val)
Definition: Chat.h:114
Player * GetPlayer() const
Definition: Chat.cpp:39
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:113
virtual char const * GetTrinityString(uint32 entry) const
Definition: Chat.cpp:48
Class used to access individual fields of database query result.
Definition: Field.h:90
uint8 GetUInt8() const
Definition: Field.cpp:30
char const * GetCString() const
Definition: Field.cpp:110
bool isGMVisible() const
Definition: Player.h:1186
void SetGameMaster(bool on)
Definition: Player.cpp:2071
void UpdateTriggerVisibility()
Definition: Player.cpp:23953
void SetGMVisible(bool on)
Definition: Player.cpp:2121
void UpdateObjectVisibility(bool forced=true) override
Definition: Player.cpp:24070
void setInt32(const uint8 index, const int32 value)
void setUInt8(const uint8 index, const uint8 value)
Aura * AddAura(uint32 spellId, Unit *target)
Definition: Unit.cpp:11618
bool SetCanTransitionBetweenSwimAndFly(bool enable)
Definition: Unit.cpp:13048
bool SetCanFly(bool enable)
Definition: Unit.cpp:12820
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint32 reqEffMask=0) const
Definition: Unit.cpp:4664
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint32 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition: Unit.cpp:3831
Player session in the World.
Definition: WorldSession.h:963
void SendNotification(char const *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:234
static bool HandleGMVisibleCommand(ChatHandler *handler, Optional< bool > visibleArg)
Definition: cs_gm.cpp:194
static bool HandleGMListIngameCommand(ChatHandler *handler)
Definition: cs_gm.cpp:117
static bool HandleGMListFullCommand(ChatHandler *handler)
Display the list of GMs.
Definition: cs_gm.cpp:159
static bool HandleGMOnCommand(ChatHandler *handler)
Definition: cs_gm.cpp:226
void AddSC_gm_commandscript()
Definition: cs_gm.cpp:243
#define sWorld
Definition: World.h:931
Realm realm
Definition: World.cpp:3966
@ CONFIG_GM_LEVEL_IN_GM_LIST
Definition: World.h:291
TC_GAME_API HashMapHolder< Player >::MapType const & GetPlayers()
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:49
constexpr std::size_t size()
Definition: UpdateField.h:796
@ RBAC_PERM_COMMAND_GM
Definition: RBAC.h:243
@ RBAC_PERM_COMMAND_GM_INGAME
Definition: RBAC.h:246
@ RBAC_PERM_COMMAND_GM_CHAT
Definition: RBAC.h:244
@ RBAC_PERM_CHAT_USE_STAFF_BADGE
Definition: RBAC.h:90
@ RBAC_PERM_COMMAND_GM_VISIBLE
Definition: RBAC.h:248
@ RBAC_PERM_COMMAND_GM_LIST
Definition: RBAC.h:247
@ RBAC_PERM_COMMAND_GM_FLY
Definition: RBAC.h:245
@ RBAC_PERM_COMMANDS_APPEAR_IN_GM_LIST
Definition: RBAC.h:87
Battlenet::RealmHandle Id
Definition: Realm.h:82