AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
gm_commandscript Class Reference
Inheritance diagram for gm_commandscript:
CommandScript ScriptObject

Public Member Functions

 gm_commandscript ()
 
ChatCommandTable GetCommands () const override
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 
uint16 GetTotalAvailableHooks ()
 

Static Public Member Functions

static bool HandleGMChatCommand (ChatHandler *handler, Optional< bool > enableArg)
 
static bool HandleGMFlyCommand (ChatHandler *handler, Optional< bool > enable)
 
static bool HandleGMListIngameCommand (ChatHandler *handler)
 
static bool HandleGMListFullCommand (ChatHandler *handler)
 Display the list of GMs.
 
static bool HandleGMVisibleCommand (ChatHandler *handler, Optional< bool > visibleArg)
 
static bool HandleGMOnCommand (ChatHandler *handler)
 
static bool HandleGMOffCommand (ChatHandler *handler)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ gm_commandscript()

gm_commandscript::gm_commandscript ( )
inline
35: CommandScript("gm_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable gm_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

38 {
39 static ChatCommandTable gmCommandTable =
40 {
41 { "chat", HandleGMChatCommand, SEC_GAMEMASTER, Console::No },
42 { "fly", HandleGMFlyCommand, SEC_GAMEMASTER, Console::No },
43 { "ingame", HandleGMListIngameCommand, SEC_PLAYER, Console::Yes },
44 { "list", HandleGMListFullCommand, SEC_ADMINISTRATOR, Console::Yes },
45 { "visible", HandleGMVisibleCommand, SEC_GAMEMASTER, Console::No },
46 { "on", HandleGMOnCommand, SEC_MODERATOR, Console::No },
47 { "off", HandleGMOffCommand, SEC_MODERATOR, Console::No }
48 };
49 static ChatCommandTable commandTable =
50 {
51 { "gm", gmCommandTable }
52 };
53 return commandTable;
54 }
@ SEC_PLAYER
Definition Common.h:57
@ SEC_ADMINISTRATOR
Definition Common.h:60
@ SEC_GAMEMASTER
Definition Common.h:59
@ SEC_MODERATOR
Definition Common.h:58
static bool HandleGMChatCommand(ChatHandler *handler, Optional< bool > enableArg)
Definition cs_gm.cpp:57
static bool HandleGMFlyCommand(ChatHandler *handler, Optional< bool > enable)
Definition cs_gm.cpp:88
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:116
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
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46

References HandleGMChatCommand(), HandleGMFlyCommand(), HandleGMListFullCommand(), HandleGMListIngameCommand(), HandleGMOffCommand(), HandleGMOnCommand(), HandleGMVisibleCommand(), SEC_ADMINISTRATOR, SEC_GAMEMASTER, SEC_MODERATOR, and SEC_PLAYER.

◆ HandleGMChatCommand()

static bool gm_commandscript::HandleGMChatCommand ( ChatHandler handler,
Optional< bool >  enableArg 
)
inlinestatic
58 {
59 if (WorldSession* session = handler->GetSession())
60 {
61 if (!enableArg)
62 {
63 if (!AccountMgr::IsPlayerAccount(session->GetSecurity()) && session->GetPlayer()->isGMChat())
65 else
67 return true;
68 }
69
70 if (*enableArg)
71 {
72 session->GetPlayer()->SetGMChat(true);
74 return true;
75 }
76 else
77 {
78 session->GetPlayer()->SetGMChat(false);
80 return true;
81 }
82 }
83
85 return false;
86 }
@ LANG_USE_BOL
Definition Language.h:304
@ LANG_GM_CHAT_ON
Definition Language.h:376
@ LANG_GM_CHAT_OFF
Definition Language.h:377
WorldSession * GetSession()
Definition Chat.h:242
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:216
void SendNotification(std::string_view str)
Definition Chat.cpp:105
Player session in the World.
Definition WorldSession.h:330
bool IsPlayerAccount(uint32 gmlevel)
Definition AccountMgr.cpp:305

References ChatHandler::GetSession(), AccountMgr::IsPlayerAccount(), LANG_GM_CHAT_OFF, LANG_GM_CHAT_ON, LANG_USE_BOL, ChatHandler::SendErrorMessage(), and ChatHandler::SendNotification().

Referenced by GetCommands().

◆ HandleGMFlyCommand()

static bool gm_commandscript::HandleGMFlyCommand ( ChatHandler handler,
Optional< bool >  enable 
)
inlinestatic
89 {
90 Player* target = handler->getSelectedPlayer();
91 if (!target)
92 target = handler->GetSession()->GetPlayer();
93
94 WorldPacket data(12);
95
96 bool canFly = false;
97 if (enable.has_value())
98 {
99 data.SetOpcode(*enable ? SMSG_MOVE_SET_CAN_FLY : SMSG_MOVE_UNSET_CAN_FLY);
100 canFly = *enable;
101 }
102 else
103 {
104 canFly = handler->GetSession()->GetPlayer()->CanFly();
105 data.SetOpcode(canFly ? SMSG_MOVE_UNSET_CAN_FLY : SMSG_MOVE_SET_CAN_FLY);
106 canFly = !canFly;
107 }
108
109 data << target->GetPackGUID();
110 data << uint32(0); // unknown
111 target->SendMessageToSet(&data, true);
112 handler->PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, handler->GetNameLink(target), canFly ? "on" : "off");
113 return true;
114 }
std::uint32_t uint32
Definition Define.h:107
@ LANG_COMMAND_FLYMODE_STATUS
Definition Language.h:512
virtual std::string GetNameLink() const
Definition Chat.h:198
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:211
Player * getSelectedPlayer() const
Definition Chat.cpp:374
PackedGuid const & GetPackGUID() const
Definition Object.h:115
Definition Player.h:1082
bool CanFly() const override
Definition Player.h:2579
void SendMessageToSet(WorldPacket const *data, bool self) const override
Definition Player.cpp:5676
Definition WorldPacket.h:26
Player * GetPlayer() const
Definition WorldSession.h:376
@ SMSG_MOVE_SET_CAN_FLY
Definition Opcodes.h:865
@ SMSG_MOVE_UNSET_CAN_FLY
Definition Opcodes.h:866

References Player::CanFly(), ChatHandler::GetNameLink(), Object::GetPackGUID(), WorldSession::GetPlayer(), ChatHandler::getSelectedPlayer(), ChatHandler::GetSession(), LANG_COMMAND_FLYMODE_STATUS, ChatHandler::PSendSysMessage(), Player::SendMessageToSet(), WorldPacket::SetOpcode(), SMSG_MOVE_SET_CAN_FLY, and SMSG_MOVE_UNSET_CAN_FLY.

Referenced by GetCommands().

◆ HandleGMListFullCommand()

static bool gm_commandscript::HandleGMListFullCommand ( ChatHandler handler)
inlinestatic

Display the list of GMs.

  • Get the accounts with GM Level >0
  • Cycle through them. Display username and GM level
158 {
161 stmt->SetData(0, uint8(SEC_MODERATOR));
162 stmt->SetData(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 std::string name = fields[0].Get<std::string>();
174 uint8 security = fields[1].Get<uint8>();
175 uint8 max = (16 - name.length()) / 2;
176 uint8 max2 = max;
177 if ((max + max2 + name.length()) == 16)
178 max2 = max - 1;
179 if (handler->GetSession())
180 handler->PSendSysMessage("| {} GMLevel {}", name, security);
181 else
182 handler->PSendSysMessage("|{}{}{}| {} |", max, " ", name, max2, " ", security);
183 } while (result->NextRow());
184 handler->SendSysMessage("========================");
185 }
186 else
188 return true;
189 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition DatabaseEnvFwd.h:45
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition DatabaseEnv.cpp:22
std::int32_t int32
Definition Define.h:103
std::uint8_t uint8
Definition Define.h:109
@ LANG_GMLIST
Definition Language.h:660
@ LANG_GMLIST_EMPTY
Definition Language.h:662
@ LOGIN_SEL_GM_ACCOUNTS
Definition LoginDatabase.h:90
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:160
Class used to access individual fields of database query result.
Definition Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition Field.h:112
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157
Realm realm
Definition World.cpp:111
uint32 Realm
Definition Realm.h:43
RealmHandle Id
Definition Realm.h:69

References Field::Get(), ChatHandler::GetSession(), Realm::Id, LANG_GMLIST, LANG_GMLIST_EMPTY, LOGIN_SEL_GM_ACCOUNTS, LoginDatabase, ChatHandler::PSendSysMessage(), realm, RealmHandle::Realm, SEC_MODERATOR, ChatHandler::SendSysMessage(), and PreparedStatementBase::SetData().

Referenced by GetCommands().

◆ HandleGMListIngameCommand()

static bool gm_commandscript::HandleGMListIngameCommand ( ChatHandler handler)
inlinestatic
117 {
118 bool first = true;
119 bool footer = false;
120
121 std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
122 for (auto const& [playerGuid, player] : ObjectAccessor::GetPlayers())
123 {
124 AccountTypes playerSec = player->GetSession()->GetSecurity();
125 if ((player->IsGameMaster() ||
126 (!AccountMgr::IsPlayerAccount(playerSec) && 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("| {} GMLevel {}", name, security);
145 else
146 handler->PSendSysMessage("|{}{}{}| {} |", max, " ", name, max2, " ", security);
147 }
148 }
149 if (footer)
150 handler->SendSysMessage("========================");
151 if (first)
153 return true;
154 }
AccountTypes
Definition Common.h:56
@ CONFIG_GM_LEVEL_IN_GM_LIST
Definition IWorld.h:259
@ LANG_GMS_ON_SRV
Definition Language.h:48
@ LANG_GMS_NOT_LOGGED
Definition Language.h:49
Definition ObjectAccessor.h:41
#define sWorld
Definition World.h:357
Definition ObjectAccessor.h:61
HashMapHolder< Player >::MapType const & GetPlayers()
Definition ObjectAccessor.cpp:75

References CONFIG_GM_LEVEL_IN_GM_LIST, WorldSession::GetPlayer(), ObjectAccessor::GetPlayers(), ChatHandler::GetSession(), AccountMgr::IsPlayerAccount(), LANG_GMS_NOT_LOGGED, LANG_GMS_ON_SRV, ChatHandler::PSendSysMessage(), ChatHandler::SendSysMessage(), and sWorld.

Referenced by GetCommands().

◆ HandleGMOffCommand()

static bool gm_commandscript::HandleGMOffCommand ( ChatHandler handler)
inlinestatic
233 {
234 handler->GetPlayer()->SetGameMaster(false);
237 return true;
238 }
@ LANG_GM_OFF
Definition Language.h:375
Player * GetPlayer() const
Definition Chat.cpp:36
void SetGameMaster(bool on)
Definition Player.cpp:2212
void UpdateTriggerVisibility()
Definition PlayerUpdates.cpp:1746

References ChatHandler::GetPlayer(), LANG_GM_OFF, ChatHandler::SendNotification(), Player::SetGameMaster(), and Player::UpdateTriggerVisibility().

Referenced by GetCommands().

◆ HandleGMOnCommand()

static bool gm_commandscript::HandleGMOnCommand ( ChatHandler handler)
inlinestatic
225 {
226 handler->GetPlayer()->SetGameMaster(true);
229 return true;
230 }
@ LANG_GM_ON
Definition Language.h:374

References ChatHandler::GetPlayer(), LANG_GM_ON, ChatHandler::SendNotification(), Player::SetGameMaster(), and Player::UpdateTriggerVisibility().

Referenced by GetCommands().

◆ HandleGMVisibleCommand()

static bool gm_commandscript::HandleGMVisibleCommand ( ChatHandler handler,
Optional< bool >  visibleArg 
)
inlinestatic
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 }
@ LANG_INVISIBLE_INVISIBLE
Definition Language.h:636
@ LANG_YOU_ARE
Definition Language.h:72
@ LANG_INVISIBLE
Definition Language.h:74
@ LANG_INVISIBLE_VISIBLE
Definition Language.h:637
@ LANG_VISIBLE
Definition Language.h:73
virtual std::string GetAcoreString(uint32 entry) const
Definition Chat.cpp:41
bool isGMVisible() const
Definition Player.h:1182
void UpdateObjectVisibility(bool forced=true, bool fromUpdate=false) override
Definition PlayerUpdates.cpp:1617
void SetGMVisible(bool on)
Definition Player.cpp:2281
Aura * AddAura(uint32 spellId, Unit *target)
Definition Unit.cpp:18910
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint8 reqEffMask=0) const
Definition Unit.cpp:5754
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint8 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:4942
AC_GAME_API std::string GetAcoreString(ChatHandler const *handler, AcoreStrings which)
Definition ChatCommandHelpers.cpp:27

References Unit::AddAura(), ChatHandler::GetAcoreString(), WorldSession::GetPlayer(), ChatHandler::GetSession(), Unit::HasAura(), Player::isGMVisible(), LANG_INVISIBLE, LANG_INVISIBLE_INVISIBLE, LANG_INVISIBLE_VISIBLE, LANG_VISIBLE, LANG_YOU_ARE, ChatHandler::PSendSysMessage(), Unit::RemoveAurasDueToSpell(), ChatHandler::SendNotification(), Player::SetGMVisible(), and Player::UpdateObjectVisibility().

Referenced by GetCommands().


The documentation for this class was generated from the following file: