Core/ChatCommands: Drop PlayerIdentifier's cast operators which could return nullptr (PR #25431)
(cherry picked from commit 8985fc4046e9a9b43d873e4d7b89a71afb910517)
This commit is contained in:
committed by
Shauren
parent
fd41de7ce3
commit
bdd4ccbd78
@@ -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); }
|
||||
operator ObjectGuid() const { return _guid; }
|
||||
operator std::string const&() const { return _name; }
|
||||
operator std::string_view() const { return _name; }
|
||||
|
||||
std::string const& GetName() { 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; }
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user