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: 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:59
@ SEC_ADMINISTRATOR
Definition: Common.h:62
@ SEC_GAMEMASTER
Definition: Common.h:61
@ SEC_MODERATOR
Definition: Common.h:60
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:49
static bool HandleGMChatCommand(ChatHandler *handler, Optional< bool > enableArg)
Definition: cs_gm.cpp:64
static bool HandleGMFlyCommand(ChatHandler *handler, bool enable)
Definition: cs_gm.cpp:95
static bool HandleGMOffCommand(ChatHandler *handler)
Definition: cs_gm.cpp:230
static bool HandleGMVisibleCommand(ChatHandler *handler, Optional< bool > visibleArg)
Definition: cs_gm.cpp:190
static bool HandleGMListIngameCommand(ChatHandler *handler)
Definition: cs_gm.cpp:114
static bool HandleGMListFullCommand(ChatHandler *handler)
Display the list of GMs.
Definition: cs_gm.cpp:155
static bool HandleGMOnCommand(ChatHandler *handler)
Definition: cs_gm.cpp:222

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 return false;
93 }
@ 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:139
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:152
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, and ChatHandler::SendErrorMessage().

Referenced by GetCommands().

◆ HandleGMFlyCommand()

static bool gm_commandscript::HandleGMFlyCommand ( ChatHandler handler,
bool  enable 
)
inlinestatic
96 {
97 Player* target = handler->getSelectedPlayer();
98 if (!target)
99 target = handler->GetSession()->GetPlayer();
100
101 WorldPacket data(12);
102 if (enable)
103 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
104 else
105 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
106
107 data << target->GetPackGUID();
108 data << uint32(0); // unknown
109 target->SendMessageToSet(&data, true);
110 handler->PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, handler->GetNameLink(target).c_str(), enable ? "on" : "off");
111 return true;
112 }
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:101
void PSendSysMessage(char const *fmt, Args &&... args)
Definition: Chat.h:60
Player * getSelectedPlayer() const
Definition: Chat.cpp:310
PackedGuid const & GetPackGUID() const
Definition: Object.h:108
Definition: Player.h:1056
void SendMessageToSet(WorldPacket const *data, bool self) const override
Definition: Player.h:1989
Definition: WorldPacket.h:27
Player * GetPlayer() const
Definition: WorldSession.h:364

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
156 {
159 stmt->SetData(0, uint8(SEC_MODERATOR));
160 stmt->SetData(1, int32(realm.Id.Realm));
161 PreparedQueryResult result = LoginDatabase.Query(stmt);
162
163 if (result)
164 {
165 handler->SendSysMessage(LANG_GMLIST);
166 handler->SendSysMessage("========================");
168 do
169 {
170 Field* fields = result->Fetch();
171 std::string name = fields[0].Get<std::string>();
172 uint8 security = fields[1].Get<uint8>();
173 uint8 max = (16 - name.length()) / 2;
174 uint8 max2 = max;
175 if ((max + max2 + name.length()) == 16)
176 max2 = max - 1;
177 if (handler->GetSession())
178 handler->PSendSysMessage("| %s GMLevel %u", name.c_str(), security);
179 else
180 handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name.c_str(), max2, " ", security);
181 } while (result->NextRow());
182 handler->SendSysMessage("========================");
183 }
184 else
186 return true;
187 }
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:112
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
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:101
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
115 {
116 bool first = true;
117 bool footer = false;
118
119 std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
120 for (auto const& [playerGuid, player] : ObjectAccessor::GetPlayers())
121 {
122 AccountTypes playerSec = player->GetSession()->GetSecurity();
123 if ((player->IsGameMaster() ||
124 (!AccountMgr::IsPlayerAccount(playerSec) && playerSec <= AccountTypes(sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_GM_LIST)))) &&
125 (!handler->GetSession() || player->IsVisibleGloballyFor(handler->GetSession()->GetPlayer())))
126 {
127 if (first)
128 {
129 first = false;
130 footer = true;
132 handler->SendSysMessage("========================");
133 }
134 std::string const& name = player->GetName();
135 uint8 size = uint8(name.size());
136 uint8 security = playerSec;
137 uint8 max = ((16 - size) / 2);
138 uint8 max2 = max;
139 if ((max + max2 + size) == 16)
140 max2 = max - 1;
141 if (handler->GetSession())
142 handler->PSendSysMessage("| %s GMLevel %u", name.c_str(), security);
143 else
144 handler->PSendSysMessage("|%*s%s%*s| %u |", max, " ", name.c_str(), max2, " ", security);
145 }
146 }
147 if (footer)
148 handler->SendSysMessage("========================");
149 if (first)
151 return true;
152 }
AccountTypes
Definition: Common.h:58
@ 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:259
#define sWorld
Definition: World.h:447
HashMapHolder< Player >::MapType const & GetPlayers()
Definition: ObjectAccessor.cpp:78
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
231 {
232 handler->GetPlayer()->SetGameMaster(false);
235 return true;
236 }
@ LANG_GM_OFF
Definition: Language.h:374
Player * GetPlayer() const
Definition: Chat.cpp:37
void SetGameMaster(bool on)
Definition: Player.cpp:2190
void UpdateTriggerVisibility()
Definition: PlayerUpdates.cpp:1700
void SendNotification(const char *format,...) ATTR_PRINTF(2
Definition: WorldSession.cpp:785

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
223 {
224 handler->GetPlayer()->SetGameMaster(true);
227 return true;
228 }
@ 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
191 {
192 Player* _player = handler->GetSession()->GetPlayer();
193
194 if (!visibleArg)
195 {
197 return true;
198 }
199
200 const uint32 VISUAL_AURA = 37800;
201
202 if (*visibleArg)
203 {
204 if (_player->HasAura(VISUAL_AURA))
205 _player->RemoveAurasDueToSpell(VISUAL_AURA);
206
207 _player->SetGMVisible(true);
208 _player->UpdateObjectVisibility();
210 }
211 else
212 {
213 _player->AddAura(VISUAL_AURA, _player);
214 _player->SetGMVisible(false);
215 _player->UpdateObjectVisibility();
217 }
218
219 return true;
220 }
@ 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:1154
void UpdateObjectVisibility(bool forced=true, bool fromUpdate=false) override
Definition: PlayerUpdates.cpp:1571
void SetGMVisible(bool on)
Definition: Player.cpp:2259
Aura * AddAura(uint32 spellId, Unit *target)
Definition: Unit.cpp:19127
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint8 reqEffMask=0) const
Definition: Unit.cpp:5636
void RemoveAurasDueToSpell(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, uint8 reqEffMask=0, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition: Unit.cpp:4855

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().