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
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 

Static Public Member Functions

static bool HandleGMChatCommand (ChatHandler *handler, Optional< bool > enableArg)
 
static bool HandleGMFlyCommand (ChatHandler *handler, 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)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ gm_commandscript()

gm_commandscript::gm_commandscript ( )
inline
42: CommandScript("gm_commandscript") { }
Definition: ScriptMgr.h:850

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:66
@ SEC_ADMINISTRATOR
Definition: Common.h:69
@ SEC_GAMEMASTER
Definition: Common.h:68
@ SEC_MODERATOR
Definition: Common.h:67
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:50
static bool HandleGMChatCommand(ChatHandler *handler, Optional< bool > enableArg)
Definition: cs_gm.cpp:64
static bool HandleGMFlyCommand(ChatHandler *handler, bool enable)
Definition: cs_gm.cpp:96
static bool HandleGMOffCommand(ChatHandler *handler)
Definition: cs_gm.cpp:231
static bool HandleGMVisibleCommand(ChatHandler *handler, Optional< bool > visibleArg)
Definition: cs_gm.cpp:191
static bool HandleGMListIngameCommand(ChatHandler *handler)
Definition: cs_gm.cpp:115
static bool HandleGMListFullCommand(ChatHandler *handler)
Display the list of GMs.
Definition: cs_gm.cpp:156
static bool HandleGMOnCommand(ChatHandler *handler)
Definition: cs_gm.cpp:223

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())
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 }
@ LANG_USE_BOL
Definition: Language.h:303
@ LANG_GM_CHAT_ON
Definition: Language.h:375
@ LANG_GM_CHAT_OFF
Definition: Language.h:376
bool IsPlayerAccount(uint32 gmlevel)
Definition: AccountMgr.cpp:276
WorldSession * GetSession()
Definition: Chat.h:122
void SetSentErrorMessage(bool val)
Definition: Chat.h:118
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:103
Player session in the World.
Definition: WorldSession.h:330

References ChatHandler::GetSession(), AccountMgr::IsPlayerAccount(), LANG_GM_CHAT_OFF, LANG_GM_CHAT_ON, LANG_USE_BOL, ChatHandler::SendSysMessage(), and ChatHandler::SetSentErrorMessage().

Referenced by GetCommands().

◆ HandleGMFlyCommand()

static bool gm_commandscript::HandleGMFlyCommand ( ChatHandler handler,
bool  enable 
)
inlinestatic
97 {
98 Player* target = handler->getSelectedPlayer();
99 if (!target)
100 target = handler->GetSession()->GetPlayer();
101
102 WorldPacket data(12);
103 if (enable)
104 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
105 else
106 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
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 }
std::uint32_t uint32
Definition: Define.h:108
@ LANG_COMMAND_FLYMODE_STATUS
Definition: Language.h:494
@ SMSG_MOVE_SET_CAN_FLY
Definition: Opcodes.h:865
@ SMSG_MOVE_UNSET_CAN_FLY
Definition: Opcodes.h:866
virtual std::string GetNameLink() const
Definition: Chat.h:84
void PSendSysMessage(char const *fmt, Args &&... args)
Definition: Chat.h:60
Player * getSelectedPlayer() const
Definition: Chat.cpp:301
PackedGuid const & GetPackGUID() const
Definition: Object.h:108
Definition: Player.h:1046
void SendMessageToSet(WorldPacket const *data, bool self) const override
Definition: Player.h:1976
Definition: WorldPacket.h:27
Player * GetPlayer() const
Definition: WorldSession.h:361

References 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
157 {
160 stmt->SetData(0, uint8(SEC_MODERATOR));
161 stmt->SetData(1, int32(realm.Id.Realm));
162 PreparedQueryResult result = LoginDatabase.Query(stmt);
163
164 if (result)
165 {
166 handler->SendSysMessage(LANG_GMLIST);
167 handler->SendSysMessage("========================");
169 do
170 {
171 Field* fields = result->Fetch();
172 std::string name = fields[0].Get<std::string>();
173 uint8 security = fields[1].Get<uint8>();
174 uint8 max = (16 - name.length()) / 2;
175 uint8 max2 = max;
176 if ((max + max2 + name.length()) == 16)
177 max2 = max - 1;
178 if (handler->GetSession())
179 handler->PSendSysMessage("| %s GMLevel %u", name.c_str(), security);
180 else
181 handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name.c_str(), max2, " ", security);
182 } while (result->NextRow());
183 handler->SendSysMessage("========================");
184 }
185 else
187 return true;
188 }
std::int32_t int32
Definition: Define.h:104
std::uint8_t uint8
Definition: Define.h:110
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:46
@ LOGIN_SEL_GM_ACCOUNTS
Definition: LoginDatabase.h:89
@ LANG_GMLIST
Definition: Language.h:642
@ LANG_GMLIST_EMPTY
Definition: Language.h:644
Realm realm
Definition: World.cpp:113
Definition: PreparedStatement.h:158
Class used to access individual fields of database query result.
Definition: Field.h:99
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:113
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:78
uint32 Realm
Definition: Realm.h:42
RealmHandle Id
Definition: Realm.h:68

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
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 (!AccountMgr::IsPlayerAccount(playerSec) && playerSec <= AccountTypes(sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_GM_LIST)))) &&
126 (!handler->GetSession() || player->IsVisibleGloballyFor(handler->GetSession()->GetPlayer())))
127 {
128 if (first)
129 {
130 first = false;
131 footer = true;
133 handler->SendSysMessage("========================");
134 }
135 std::string const& name = player->GetName();
136 uint8 size = uint8(name.size());
137 uint8 security = playerSec;
138 uint8 max = ((16 - size) / 2);
139 uint8 max2 = max;
140 if ((max + max2 + size) == 16)
141 max2 = max - 1;
142 if (handler->GetSession())
143 handler->PSendSysMessage("| %s GMLevel %u", name.c_str(), security);
144 else
145 handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name.c_str(), max2, " ", security);
146 }
147 }
148 if (footer)
149 handler->SendSysMessage("========================");
150 if (first)
152 return true;
153 }
AccountTypes
Definition: Common.h:65
@ LANG_GMS_ON_SRV
Definition: Language.h:48
@ LANG_GMS_NOT_LOGGED
Definition: Language.h:49
@ CONFIG_GM_LEVEL_IN_GM_LIST
Definition: IWorld.h:257
#define sWorld
Definition: World.h:451
HashMapHolder< Player >::MapType const & GetPlayers()
Definition: ObjectAccessor.cpp:80
Definition: ObjectAccessor.h:45

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
232 {
233 handler->GetPlayer()->SetGameMaster(false);
236 return true;
237 }
@ LANG_GM_OFF
Definition: Language.h:374
Player * GetPlayer() const
Definition: Chat.cpp:37
void SetGameMaster(bool on)
Definition: Player.cpp:2177
void UpdateTriggerVisibility()
Definition: PlayerUpdates.cpp:1697
void SendNotification(const char *format,...) ATTR_PRINTF(2
Definition: WorldSession.cpp:787

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

Referenced by GetCommands().

◆ HandleGMOnCommand()

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

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

Referenced by GetCommands().

◆ HandleGMVisibleCommand()

static bool gm_commandscript::HandleGMVisibleCommand ( ChatHandler handler,
Optional< bool >  visibleArg 
)
inlinestatic
192 {
193 Player* _player = handler->GetSession()->GetPlayer();
194
195 if (!visibleArg)
196 {
198 return true;
199 }
200
201 const uint32 VISUAL_AURA = 37800;
202
203 if (*visibleArg)
204 {
205 if (_player->HasAura(VISUAL_AURA))
206 _player->RemoveAurasDueToSpell(VISUAL_AURA);
207
208 _player->SetGMVisible(true);
209 _player->UpdateObjectVisibility();
211 }
212 else
213 {
214 _player->AddAura(VISUAL_AURA, _player);
215 _player->SetGMVisible(false);
216 _player->UpdateObjectVisibility();
218 }
219
220 return true;
221 }
@ LANG_INVISIBLE_INVISIBLE
Definition: Language.h:618
@ LANG_YOU_ARE
Definition: Language.h:72
@ LANG_INVISIBLE
Definition: Language.h:74
@ LANG_INVISIBLE_VISIBLE
Definition: Language.h:619
@ LANG_VISIBLE
Definition: Language.h:73
virtual char const * GetAcoreString(uint32 entry) const
Definition: Chat.cpp:42
bool isGMVisible() const
Definition: Player.h:1142
void UpdateObjectVisibility(bool forced=true, bool fromUpdate=false) override
Definition: PlayerUpdates.cpp:1568
void SetGMVisible(bool on)
Definition: Player.cpp:2246
Aura * AddAura(uint32 spellId, Unit *target)
Definition: Unit.cpp:19031
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint8 reqEffMask=0) const
Definition: Unit.cpp:5610
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint8 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition: Unit.cpp:4835

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(), WorldSession::SendNotification(), Player::SetGMVisible(), and Player::UpdateObjectVisibility().

Referenced by GetCommands().