diff options
author | Peter Keresztes Schmidt <carbenium@outlook.com> | 2020-09-10 13:10:01 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-02-05 21:25:23 +0100 |
commit | bdd4ccbd7882f4006717522a6d250e48943ba854 (patch) | |
tree | 208388b750a47772bd478fa88c2b6d6c8364be1e /src | |
parent | fd41de7ce3d62ee7cc29b11e33452364ac760d3b (diff) |
Core/ChatCommands: Drop PlayerIdentifier's cast operators which could return nullptr (PR #25431)
(cherry picked from commit 8985fc4046e9a9b43d873e4d7b89a71afb910517)
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Chat/ChatCommands/ChatCommandTags.h | 14 | ||||
-rw-r--r-- | src/server/scripts/Commands/cs_character.cpp | 19 | ||||
-rw-r--r-- | src/server/scripts/Commands/cs_misc.cpp | 2 |
3 files changed, 15 insertions, 20 deletions
diff --git a/src/server/game/Chat/ChatCommands/ChatCommandTags.h b/src/server/game/Chat/ChatCommands/ChatCommandTags.h index 6fbfa187f55..be21c5e0506 100644 --- a/src/server/game/Chat/ChatCommands/ChatCommandTags.h +++ b/src/server/game/Chat/ChatCommands/ChatCommandTags.h @@ -149,15 +149,11 @@ namespace Trinity::ChatCommands PlayerIdentifier() : _name(), _guid(), _player(nullptr) {} PlayerIdentifier(Player& player); - template <typename T> - operator std::enable_if_t<std::is_base_of_v<T, Player>, T*>() const { return static_cast<T*>(_player); } - operator value_type() const { return _player; } - operator ObjectGuid() { return _guid; } - Player* operator->() const { return _player; } - explicit operator bool() const { return (_player != nullptr); } - bool operator!() const { return (_player == nullptr); } - - std::string const& GetName() { return _name; } + operator ObjectGuid() const { return _guid; } + operator std::string const&() const { return _name; } + operator std::string_view() const { return _name; } + + std::string const& GetName() const { return _name; } ObjectGuid GetGUID() const { return _guid; } bool IsConnected() const { return (_player != nullptr); } Player* GetConnectedPlayer() const { return _player; } diff --git a/src/server/scripts/Commands/cs_character.cpp b/src/server/scripts/Commands/cs_character.cpp index a05b670b9e1..65b4e619770 100644 --- a/src/server/scripts/Commands/cs_character.cpp +++ b/src/server/scripts/Commands/cs_character.cpp @@ -246,7 +246,6 @@ public: Player const* target = player->GetConnectedPlayer(); LocaleConstant loc = handler->GetSessionDbcLocale(); - std::string const& targetName = player->GetName(); char const* knownStr = handler->GetTrinityString(LANG_KNOWN); // Search in CharTitles.dbc @@ -266,7 +265,7 @@ public: if (*target->m_playerData->PlayerTitle == titleInfo->MaskID) activeStr = handler->GetTrinityString(LANG_ACTIVE); - std::string titleName = Trinity::StringFormat(name, targetName.c_str()); + std::string titleName = Trinity::StringFormat(name, player->GetName().c_str()); // send title in "id (idx:idx) - [namedlink locale]" format if (handler->GetSession()) @@ -375,7 +374,7 @@ public: if (handler->HasLowerSecurity(nullptr, player->GetGUID())) return false; - handler->PSendSysMessage(LANG_RENAME_PLAYER_GUID, handler->playerLink(player->GetName()).c_str(), player->GetGUID().ToString().c_str()); + handler->PSendSysMessage(LANG_RENAME_PLAYER_GUID, handler->playerLink(*player).c_str(), player->GetGUID().ToString().c_str()); CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG); stmt->setUInt16(0, uint16(AT_LOGIN_RENAME)); @@ -402,7 +401,7 @@ public: } else { - handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, handler->playerLink(player->GetName()).c_str(), player->GetGUID().GetCounter()); + handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, handler->playerLink(*player).c_str(), player->GetGUID().GetCounter()); CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG); stmt->setUInt16(0, static_cast<uint16>(AT_LOGIN_CUSTOMIZE)); stmt->setUInt64(1, player->GetGUID().GetCounter()); @@ -426,7 +425,7 @@ public: } else { - handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, handler->playerLink(player->GetName()).c_str(), player->GetGUID().GetCounter()); + handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, handler->playerLink(*player).c_str(), player->GetGUID().GetCounter()); CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG); stmt->setUInt16(0, uint16(AT_LOGIN_CHANGE_FACTION)); stmt->setUInt64(1, player->GetGUID().GetCounter()); @@ -450,7 +449,7 @@ public: } else { - handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, handler->playerLink(player->GetName()).c_str(), player->GetGUID().GetCounter()); + handler->PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID, handler->playerLink(*player).c_str(), player->GetGUID().GetCounter()); CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG); stmt->setUInt16(0, uint16(AT_LOGIN_CHANGE_RACE)); stmt->setUInt64(1, player->GetGUID().GetCounter()); @@ -713,10 +712,10 @@ public: static bool HandleCharacterEraseCommand(ChatHandler* handler, PlayerIdentifier player) { uint32 accountId; - if (player.IsConnected()) + if (Player* target = player.GetConnectedPlayer()) { - accountId = player->GetSession()->GetAccountId(); - player->GetSession()->KickPlayer("HandleCharacterEraseCommand GM Command deleting character"); + accountId = target->GetSession()->GetAccountId(); + target->GetSession()->KickPlayer("HandleCharacterEraseCommand GM Command deleting character"); } else accountId = sCharacterCache->GetCharacterAccountIdByGuid(player); @@ -772,7 +771,7 @@ public: } if (!handler->GetSession() || (handler->GetSession()->GetPlayer() != player->GetConnectedPlayer())) // including chr == NULL - handler->PSendSysMessage(LANG_YOU_CHANGE_LVL, handler->playerLink(player->GetName()).c_str(), newlevel); + handler->PSendSysMessage(LANG_YOU_CHANGE_LVL, handler->playerLink(*player).c_str(), newlevel); return true; } diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp index 97942206edb..a46df10186a 100644 --- a/src/server/scripts/Commands/cs_misc.cpp +++ b/src/server/scripts/Commands/cs_misc.cpp @@ -1971,7 +1971,7 @@ public: stmt->setString(3, muteReasonStr); LoginDatabase.Execute(stmt); - std::string nameLink = handler->playerLink(player->GetName()); + std::string nameLink = handler->playerLink(*player); if (sWorld->getBoolConfig(CONFIG_SHOW_MUTE_IN_WORLD)) sWorld->SendWorldText(LANG_COMMAND_MUTEMESSAGE_WORLD, muteBy.c_str(), nameLink.c_str(), muteTime, muteReasonStr.c_str()); if (target) |