diff options
author | Peter Keresztes Schmidt <carbenium@outlook.com> | 2020-08-19 14:53:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-19 14:53:04 +0200 |
commit | 9c9e8c7d58cd0e939330089cfb555945ebbf73eb (patch) | |
tree | ca2964c45c388c8c0029b0857e492bcd0b0970a5 /src | |
parent | 1aadf6c6d173e593eef0e9976e51a7189a54a8ce (diff) |
Scripts/Commands: Convert argument parsing of gm commands to new system (#25279)
Diffstat (limited to 'src')
-rw-r--r-- | src/server/scripts/Commands/cs_gm.cpp | 72 |
1 files changed, 28 insertions, 44 deletions
diff --git a/src/server/scripts/Commands/cs_gm.cpp b/src/server/scripts/Commands/cs_gm.cpp index 7268ff2925c..f24bcd843a4 100644 --- a/src/server/scripts/Commands/cs_gm.cpp +++ b/src/server/scripts/Commands/cs_gm.cpp @@ -57,12 +57,12 @@ public: return commandTable; } - // Enables or disables hiding of the staff badge - static bool HandleGMChatCommand(ChatHandler* handler, char const* args) + // Enables or disables the staff badge + static bool HandleGMChatCommand(ChatHandler* handler, Optional<bool> enableArg) { if (WorldSession* session = handler->GetSession()) { - if (!*args) + if (!enableArg) { if (session->HasPermission(rbac::RBAC_PERM_CHAT_USE_STAFF_BADGE) && session->GetPlayer()->isGMChat()) session->SendNotification(LANG_GM_CHAT_ON); @@ -71,16 +71,13 @@ public: return true; } - std::string param = (char*)args; - - if (param == "on") + if (*enableArg) { session->GetPlayer()->SetGMChat(true); session->SendNotification(LANG_GM_CHAT_ON); return true; } - - if (param == "off") + else { session->GetPlayer()->SetGMChat(false); session->SendNotification(LANG_GM_CHAT_OFF); @@ -93,46 +90,38 @@ public: return false; } - static bool HandleGMFlyCommand(ChatHandler* handler, char const* args) + static bool HandleGMFlyCommand(ChatHandler* handler, bool enable) { - if (!*args) - return false; - Player* target = handler->getSelectedPlayer(); if (!target) target = handler->GetSession()->GetPlayer(); WorldPacket data(12); - if (strncmp(args, "on", 3) == 0) + if (enable) data.SetOpcode(SMSG_MOVE_SET_CAN_FLY); - else if (strncmp(args, "off", 4) == 0) - data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY); else - { - handler->SendSysMessage(LANG_USE_BOL); - return false; - } + data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY); + data << target->GetPackGUID(); data << uint32(0); // unknown target->SendMessageToSet(&data, true); - handler->PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, handler->GetNameLink(target).c_str(), args); + handler->PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, handler->GetNameLink(target).c_str(), enable ? "on" : "off"); return true; } - static bool HandleGMListIngameCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleGMListIngameCommand(ChatHandler* handler) { bool first = true; bool footer = false; std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock()); - HashMapHolder<Player>::MapType const& m = ObjectAccessor::GetPlayers(); - for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) + for (auto const [playerGuid, player] : ObjectAccessor::GetPlayers()) { - AccountTypes itrSec = itr->second->GetSession()->GetSecurity(); - if ((itr->second->IsGameMaster() || - (itr->second->GetSession()->HasPermission(rbac::RBAC_PERM_COMMANDS_APPEAR_IN_GM_LIST) && - itrSec <= AccountTypes(sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_GM_LIST)))) && - (!handler->GetSession() || itr->second->IsVisibleGloballyFor(handler->GetSession()->GetPlayer()))) + AccountTypes playerSec = player->GetSession()->GetSecurity(); + if ((player->IsGameMaster() || + (player->GetSession()->HasPermission(rbac::RBAC_PERM_COMMANDS_APPEAR_IN_GM_LIST) && + playerSec <= AccountTypes(sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_GM_LIST)))) && + (!handler->GetSession() || player->IsVisibleGloballyFor(handler->GetSession()->GetPlayer()))) { if (first) { @@ -141,9 +130,9 @@ public: handler->SendSysMessage(LANG_GMS_ON_SRV); handler->SendSysMessage("========================"); } - std::string const& name = itr->second->GetName(); + std::string const& name = player->GetName(); uint8 size = uint8(name.size()); - uint8 security = itrSec; + uint8 security = playerSec; uint8 max = ((16 - size) / 2); uint8 max2 = max; if ((max + max2 + size) == 16) @@ -162,7 +151,7 @@ public: } /// Display the list of GMs - static bool HandleGMListFullCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleGMListFullCommand(ChatHandler* handler) { ///- Get the accounts with GM Level >0 LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_GM_ACCOUNTS); @@ -197,20 +186,19 @@ public: } //Enable\Disable Invisible mode - static bool HandleGMVisibleCommand(ChatHandler* handler, char const* args) + static bool HandleGMVisibleCommand(ChatHandler* handler, Optional<bool> visibleArg) { Player* _player = handler->GetSession()->GetPlayer(); - if (!*args) + if (!visibleArg) { handler->PSendSysMessage(LANG_YOU_ARE, _player->isGMVisible() ? handler->GetTrinityString(LANG_VISIBLE) : handler->GetTrinityString(LANG_INVISIBLE)); return true; } const uint32 VISUAL_AURA = 37800; - std::string param = (char*)args; - if (param == "on") + if (*visibleArg) { if (_player->HasAura(VISUAL_AURA)) _player->RemoveAurasDueToSpell(VISUAL_AURA); @@ -220,8 +208,7 @@ public: handler->GetSession()->SendNotification(LANG_INVISIBLE_VISIBLE); return true; } - - if (param == "off") + else { _player->AddAura(VISUAL_AURA, _player); _player->SetGMVisible(false); @@ -236,27 +223,24 @@ public: } //Enable\Disable GM Mode - static bool HandleGMCommand(ChatHandler* handler, char const* args) + static bool HandleGMCommand(ChatHandler* handler, Optional<bool> enableArg) { Player* _player = handler->GetSession()->GetPlayer(); - if (!*args) + if (!enableArg) { handler->GetSession()->SendNotification(_player->IsGameMaster() ? LANG_GM_ON : LANG_GM_OFF); return true; } - std::string param = (char*)args; - - if (param == "on") + if (*enableArg) { _player->SetGameMaster(true); handler->GetSession()->SendNotification(LANG_GM_ON); _player->UpdateTriggerVisibility(); return true; } - - if (param == "off") + else { _player->SetGameMaster(false); handler->GetSession()->SendNotification(LANG_GM_OFF); |