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
42: CommandScript("gm_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable gm_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

45 {
46 static ChatCommandTable gmCommandTable =
47 {
48 { "chat", HandleGMChatCommand, SEC_GAMEMASTER, Console::No },
49 { "fly", HandleGMFlyCommand, SEC_GAMEMASTER, Console::No },
50 { "ingame", HandleGMListIngameCommand, SEC_PLAYER, Console::Yes },
51 { "list", HandleGMListFullCommand, SEC_ADMINISTRATOR, Console::Yes },
52 { "visible", HandleGMVisibleCommand, SEC_GAMEMASTER, Console::No },
53 { "on", HandleGMOnCommand, SEC_MODERATOR, Console::No },
54 { "off", HandleGMOffCommand, SEC_MODERATOR, Console::No }
55 };
56 static ChatCommandTable commandTable =
57 {
58 { "gm", gmCommandTable }
59 };
60 return commandTable;
61 }
@ 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:64
static bool HandleGMFlyCommand(ChatHandler *handler, Optional< bool > enable)
Definition cs_gm.cpp:95
static bool HandleGMOffCommand(ChatHandler *handler)
Definition cs_gm.cpp:239
static bool HandleGMVisibleCommand(ChatHandler *handler, Optional< bool > visibleArg)
Definition cs_gm.cpp:199
static bool HandleGMListIngameCommand(ChatHandler *handler)
Definition cs_gm.cpp:123
static bool HandleGMListFullCommand(ChatHandler *handler)
Display the list of GMs.
Definition cs_gm.cpp:164
static bool HandleGMOnCommand(ChatHandler *handler)
Definition cs_gm.cpp:231
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
65 {
66 if (WorldSession* session = handler->GetSession())
67 {
68 if (!enableArg)
69 {
70 if (!AccountMgr::IsPlayerAccount(session->GetSecurity()) && session->GetPlayer()->isGMChat())
72 else
74 return true;
75 }
76
77 if (*enableArg)
78 {
79 session->GetPlayer()->SetGMChat(true);
81 return true;
82 }
83 else
84 {
85 session->GetPlayer()->SetGMChat(false);
87 return true;
88 }
89 }
90
92 return false;
93 }
@ 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
96 {
97 Player* target = handler->getSelectedPlayer();
98 if (!target)
99 target = handler->GetSession()->GetPlayer();
100
101 WorldPacket data(12);
102
103 bool canFly = false;
104 if (enable.has_value())
105 {
106 data.SetOpcode(*enable ? SMSG_MOVE_SET_CAN_FLY : SMSG_MOVE_UNSET_CAN_FLY);
107 canFly = *enable;
108 }
109 else
110 {
111 canFly = handler->GetSession()->GetPlayer()->CanFly();
112 data.SetOpcode(canFly ? SMSG_MOVE_UNSET_CAN_FLY : SMSG_MOVE_SET_CAN_FLY);
113 canFly = !canFly;
114 }
115
116 data << target->GetPackGUID();
117 data << uint32(0); // unknown
118 target->SendMessageToSet(&data, true);
119 handler->PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, handler->GetNameLink(target), canFly ? "on" : "off");
120 return true;
121 }
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:114
Definition Player.h:1081
bool CanFly() const override
Definition Player.h:2577
void SendMessageToSet(WorldPacket const *data, bool self) const override
Definition Player.cpp:5697
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
165 {
168 stmt->SetData(0, uint8(SEC_MODERATOR));
169 stmt->SetData(1, int32(realm.Id.Realm));
170 PreparedQueryResult result = LoginDatabase.Query(stmt);
171
172 if (result)
173 {
174 handler->SendSysMessage(LANG_GMLIST);
175 handler->SendSysMessage("========================");
177 do
178 {
179 Field* fields = result->Fetch();
180 std::string name = fields[0].Get<std::string>();
181 uint8 security = fields[1].Get<uint8>();
182 uint8 max = (16 - name.length()) / 2;
183 uint8 max2 = max;
184 if ((max + max2 + name.length()) == 16)
185 max2 = max - 1;
186 if (handler->GetSession())
187 handler->PSendSysMessage("| {} GMLevel {}", name, security);
188 else
189 handler->PSendSysMessage("|{}{}{}| {} |", max, " ", name, max2, " ", security);
190 } while (result->NextRow());
191 handler->SendSysMessage("========================");
192 }
193 else
195 return true;
196 }
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
124 {
125 bool first = true;
126 bool footer = false;
127
128 std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
129 for (auto const& [playerGuid, player] : ObjectAccessor::GetPlayers())
130 {
131 AccountTypes playerSec = player->GetSession()->GetSecurity();
132 if ((player->IsGameMaster() ||
133 (!AccountMgr::IsPlayerAccount(playerSec) && playerSec <= AccountTypes(sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_GM_LIST)))) &&
134 (!handler->GetSession() || player->IsVisibleGloballyFor(handler->GetSession()->GetPlayer())))
135 {
136 if (first)
137 {
138 first = false;
139 footer = true;
141 handler->SendSysMessage("========================");
142 }
143 std::string const& name = player->GetName();
144 uint8 size = uint8(name.size());
145 uint8 security = playerSec;
146 uint8 max = ((16 - size) / 2);
147 uint8 max2 = max;
148 if ((max + max2 + size) == 16)
149 max2 = max - 1;
150 if (handler->GetSession())
151 handler->PSendSysMessage("| {} GMLevel {}", name, security);
152 else
153 handler->PSendSysMessage("|{}{}{}| {} |", max, " ", name, max2, " ", security);
154 }
155 }
156 if (footer)
157 handler->SendSysMessage("========================");
158 if (first)
160 return true;
161 }
AccountTypes
Definition Common.h:56
@ CONFIG_GM_LEVEL_IN_GM_LIST
Definition IWorld.h:258
@ 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:363
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
240 {
241 handler->GetPlayer()->SetGameMaster(false);
244 return true;
245 }
@ LANG_GM_OFF
Definition Language.h:375
Player * GetPlayer() const
Definition Chat.cpp:36
void SetGameMaster(bool on)
Definition Player.cpp:2233
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
232 {
233 handler->GetPlayer()->SetGameMaster(true);
236 return true;
237 }
@ 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
200 {
201 Player* _player = handler->GetSession()->GetPlayer();
202
203 if (!visibleArg)
204 {
206 return true;
207 }
208
209 const uint32 VISUAL_AURA = 37800;
210
211 if (*visibleArg)
212 {
213 if (_player->HasAura(VISUAL_AURA))
214 _player->RemoveAurasDueToSpell(VISUAL_AURA);
215
216 _player->SetGMVisible(true);
217 _player->UpdateObjectVisibility();
219 }
220 else
221 {
222 _player->AddAura(VISUAL_AURA, _player);
223 _player->SetGMVisible(false);
224 _player->UpdateObjectVisibility();
226 }
227
228 return true;
229 }
@ 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:1181
void UpdateObjectVisibility(bool forced=true, bool fromUpdate=false) override
Definition PlayerUpdates.cpp:1617
void SetGMVisible(bool on)
Definition Player.cpp:2302
Aura * AddAura(uint32 spellId, Unit *target)
Definition Unit.cpp:18915
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint8 reqEffMask=0) const
Definition Unit.cpp:5753
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint8 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:4941
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: