chore(Core/Account): move AccountMgr::IsGMAccount() to class WorldSession (#17845)

This commit is contained in:
Tristan 'Natrist' Cormier
2023-11-28 15:44:48 -05:00
committed by GitHub
parent 9da7657147
commit 4c94f62144
10 changed files with 29 additions and 35 deletions
-5
View File
@@ -278,11 +278,6 @@ namespace AccountMgr
return gmlevel == SEC_PLAYER; return gmlevel == SEC_PLAYER;
} }
bool IsGMAccount(uint32 gmlevel)
{
return gmlevel >= SEC_MODERATOR && gmlevel <= SEC_CONSOLE;
}
bool IsAdminAccount(uint32 gmlevel) bool IsAdminAccount(uint32 gmlevel)
{ {
return gmlevel >= SEC_ADMINISTRATOR && gmlevel <= SEC_CONSOLE; return gmlevel >= SEC_ADMINISTRATOR && gmlevel <= SEC_CONSOLE;
-1
View File
@@ -49,7 +49,6 @@ namespace AccountMgr
uint32 GetCharactersCount(uint32 accountId); uint32 GetCharactersCount(uint32 accountId);
bool IsPlayerAccount(uint32 gmlevel); bool IsPlayerAccount(uint32 gmlevel);
bool IsGMAccount(uint32 gmlevel);
bool IsAdminAccount(uint32 gmlevel); bool IsAdminAccount(uint32 gmlevel);
bool IsConsoleAccount(uint32 gmlevel); bool IsConsoleAccount(uint32 gmlevel);
}; };
+15 -22
View File
@@ -221,7 +221,7 @@ void Channel::JoinChannel(Player* player, std::string const& pass)
JoinNotify(player); JoinNotify(player);
playersStore[guid].SetOwnerGM(AccountMgr::IsGMAccount(player->GetSession()->GetSecurity())); playersStore[guid].SetOwnerGM(player->GetSession()->IsGMAccount());
// Custom channel handling // Custom channel handling
if (!IsConstant()) if (!IsConstant())
@@ -299,7 +299,7 @@ void Channel::LeaveChannel(Player* player, bool send)
for (Channel::PlayerContainer::const_iterator itr = playersStore.begin(); itr != playersStore.end(); ++itr) for (Channel::PlayerContainer::const_iterator itr = playersStore.begin(); itr != playersStore.end(); ++itr)
{ {
newowner = itr->second.player; newowner = itr->second.player;
if (AccountMgr::IsGMAccount(itr->second.plrPtr->GetSession()->GetSecurity())) if (itr->second.plrPtr->GetSession()->IsGMAccount())
_isOwnerGM = true; _isOwnerGM = true;
else else
_isOwnerGM = false; _isOwnerGM = false;
@@ -317,7 +317,6 @@ void Channel::LeaveChannel(Player* player, bool send)
void Channel::KickOrBan(Player const* player, std::string const& badname, bool ban) void Channel::KickOrBan(Player const* player, std::string const& badname, bool ban)
{ {
AccountTypes sec = player->GetSession()->GetSecurity();
ObjectGuid good = player->GetGUID(); ObjectGuid good = player->GetGUID();
if (!IsOn(good)) if (!IsOn(good))
@@ -328,7 +327,7 @@ void Channel::KickOrBan(Player const* player, std::string const& badname, bool b
return; return;
} }
if (!playersStore[good].IsModerator() && !AccountMgr::IsGMAccount(sec)) if (!playersStore[good].IsModerator() && !player->GetSession()->IsGMAccount())
{ {
WorldPacket data; WorldPacket data;
MakeNotModerator(&data); MakeNotModerator(&data);
@@ -341,19 +340,17 @@ void Channel::KickOrBan(Player const* player, std::string const& badname, bool b
ObjectGuid victim; ObjectGuid victim;
uint32 badAccId = 0; uint32 badAccId = 0;
uint32 badSecurity = 0;
Player* bad = ObjectAccessor::FindPlayerByName(badname, false); Player* bad = ObjectAccessor::FindPlayerByName(badname, false);
if (bad) if (bad)
{ {
victim = bad->GetGUID(); victim = bad->GetGUID();
badAccId = bad->GetSession()->GetAccountId(); badAccId = bad->GetSession()->GetAccountId();
badSecurity = bad->GetSession()->GetSecurity();
} }
bool isOnChannel = victim && IsOn(victim); bool isOnChannel = victim && IsOn(victim);
if (!isOnChannel) if (!isOnChannel)
{ {
if (ban && (AccountMgr::IsGMAccount(sec) || isGoodConstantModerator)) if (ban && (player->GetSession()->IsGMAccount() || isGoodConstantModerator))
{ {
if (ObjectGuid guid = sCharacterCache->GetCharacterGuidByName(badname)) if (ObjectGuid guid = sCharacterCache->GetCharacterGuidByName(badname))
{ {
@@ -393,7 +390,7 @@ void Channel::KickOrBan(Player const* player, std::string const& badname, bool b
bool changeowner = _ownerGUID == victim; bool changeowner = _ownerGUID == victim;
bool isBadConstantModerator = _channelRights.moderators.find(badAccId) != _channelRights.moderators.end(); bool isBadConstantModerator = _channelRights.moderators.find(badAccId) != _channelRights.moderators.end();
if (!AccountMgr::IsGMAccount(sec) && !isGoodConstantModerator) if (!player->GetSession()->IsGMAccount() && !isGoodConstantModerator)
{ {
if (changeowner && good != _ownerGUID) if (changeowner && good != _ownerGUID)
{ {
@@ -411,7 +408,7 @@ void Channel::KickOrBan(Player const* player, std::string const& badname, bool b
return; return;
} }
if (isBadConstantModerator || AccountMgr::IsGMAccount(badSecurity)) if (isBadConstantModerator || bad->GetSession()->IsGMAccount())
{ {
WorldPacket data; WorldPacket data;
MakeNotModerator(&data); MakeNotModerator(&data);
@@ -472,7 +469,6 @@ void Channel::KickOrBan(Player const* player, std::string const& badname, bool b
void Channel::UnBan(Player const* player, std::string const& badname) void Channel::UnBan(Player const* player, std::string const& badname)
{ {
uint32 sec = player->GetSession()->GetSecurity();
ObjectGuid good = player->GetGUID(); ObjectGuid good = player->GetGUID();
if (!IsOn(good)) if (!IsOn(good))
@@ -483,7 +479,7 @@ void Channel::UnBan(Player const* player, std::string const& badname)
return; return;
} }
if (!playersStore[good].IsModerator() && !AccountMgr::IsGMAccount(sec)) if (!playersStore[good].IsModerator() && !player->GetSession()->IsGMAccount())
{ {
WorldPacket data; WorldPacket data;
MakeNotModerator(&data); MakeNotModerator(&data);
@@ -506,7 +502,7 @@ void Channel::UnBan(Player const* player, std::string const& badname)
} }
bool isConstantModerator = _channelRights.moderators.find(player->GetSession()->GetAccountId()) != _channelRights.moderators.end(); bool isConstantModerator = _channelRights.moderators.find(player->GetSession()->GetAccountId()) != _channelRights.moderators.end();
if (!AccountMgr::IsGMAccount(sec) && !isConstantModerator) if (!player->GetSession()->IsGMAccount() && !isConstantModerator)
{ {
if (_channelRights.flags & CHANNEL_RIGHT_CANT_BAN) if (_channelRights.flags & CHANNEL_RIGHT_CANT_BAN)
{ {
@@ -551,7 +547,7 @@ void Channel::Password(Player const* player, std::string const& pass)
return; return;
} }
if (!playersStore[guid].IsModerator() && !AccountMgr::IsGMAccount(player->GetSession()->GetSecurity())) if (!playersStore[guid].IsModerator() && !player->GetSession()->IsGMAccount())
{ {
WorldPacket data; WorldPacket data;
MakeNotModerator(&data); MakeNotModerator(&data);
@@ -579,7 +575,6 @@ void Channel::Password(Player const* player, std::string const& pass)
void Channel::SetMode(Player const* player, std::string const& p2n, bool mod, bool set) void Channel::SetMode(Player const* player, std::string const& p2n, bool mod, bool set)
{ {
ObjectGuid guid = player->GetGUID(); ObjectGuid guid = player->GetGUID();
uint32 sec = player->GetSession()->GetSecurity();
if (!IsOn(guid)) if (!IsOn(guid))
{ {
@@ -589,7 +584,7 @@ void Channel::SetMode(Player const* player, std::string const& p2n, bool mod, bo
return; return;
} }
if (!playersStore[guid].IsModerator() && !AccountMgr::IsGMAccount(sec)) if (!playersStore[guid].IsModerator() && !player->GetSession()->IsGMAccount())
{ {
WorldPacket data; WorldPacket data;
MakeNotModerator(&data); MakeNotModerator(&data);
@@ -606,7 +601,7 @@ void Channel::SetMode(Player const* player, std::string const& p2n, bool mod, bo
if (!victim || !IsOn(victim) || if (!victim || !IsOn(victim) ||
// allow make moderator from another team only if both is GMs // allow make moderator from another team only if both is GMs
// at this moment this only way to show channel post for GM from another team // at this moment this only way to show channel post for GM from another team
((!AccountMgr::IsGMAccount(sec) || !AccountMgr::IsGMAccount(newp->GetSession()->GetSecurity())) && player->GetTeamId() != newp->GetTeamId() && ((!player->GetSession()->IsGMAccount() || !newp->GetSession()->IsGMAccount()) && player->GetTeamId() != newp->GetTeamId() &&
!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL))) !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL)))
{ {
WorldPacket data; WorldPacket data;
@@ -632,7 +627,7 @@ void Channel::SetMode(Player const* player, std::string const& p2n, bool mod, bo
else else
{ {
bool isGoodConstantModerator = _channelRights.moderators.find(player->GetSession()->GetAccountId()) != _channelRights.moderators.end(); bool isGoodConstantModerator = _channelRights.moderators.find(player->GetSession()->GetAccountId()) != _channelRights.moderators.end();
if (!AccountMgr::IsGMAccount(sec) && !isGoodConstantModerator) if (!player->GetSession()->IsGMAccount() && !isGoodConstantModerator)
{ {
if (_channelRights.flags & CHANNEL_RIGHT_CANT_MUTE) if (_channelRights.flags & CHANNEL_RIGHT_CANT_MUTE)
{ {
@@ -650,7 +645,6 @@ void Channel::SetMode(Player const* player, std::string const& p2n, bool mod, bo
void Channel::SetOwner(Player const* player, std::string const& newname) void Channel::SetOwner(Player const* player, std::string const& newname)
{ {
ObjectGuid guid = player->GetGUID(); ObjectGuid guid = player->GetGUID();
uint32 sec = player->GetSession()->GetSecurity();
if (!IsOn(guid)) if (!IsOn(guid))
{ {
@@ -661,7 +655,7 @@ void Channel::SetOwner(Player const* player, std::string const& newname)
} }
bool isGoodConstantModerator = _channelRights.moderators.find(player->GetSession()->GetAccountId()) != _channelRights.moderators.end(); bool isGoodConstantModerator = _channelRights.moderators.find(player->GetSession()->GetAccountId()) != _channelRights.moderators.end();
if (!AccountMgr::IsGMAccount(sec) && guid != _ownerGUID && !isGoodConstantModerator) if (!player->GetSession()->IsGMAccount() && guid != _ownerGUID && !isGoodConstantModerator)
{ {
WorldPacket data; WorldPacket data;
MakeNotOwner(&data); MakeNotOwner(&data);
@@ -733,7 +727,6 @@ void Channel::List(Player const* player)
void Channel::Announce(Player const* player) void Channel::Announce(Player const* player)
{ {
ObjectGuid guid = player->GetGUID(); ObjectGuid guid = player->GetGUID();
uint32 sec = player->GetSession()->GetSecurity();
if (!IsOn(guid)) if (!IsOn(guid))
{ {
@@ -743,7 +736,7 @@ void Channel::Announce(Player const* player)
return; return;
} }
if (!playersStore[guid].IsModerator() && !AccountMgr::IsGMAccount(sec)) if (!playersStore[guid].IsModerator() && !player->GetSession()->IsGMAccount())
{ {
WorldPacket data; WorldPacket data;
MakeNotModerator(&data); MakeNotModerator(&data);
@@ -940,7 +933,7 @@ void Channel::SendToAllWatching(WorldPacket* data)
bool Channel::ShouldAnnouncePlayer(Player const* player) const bool Channel::ShouldAnnouncePlayer(Player const* player) const
{ {
return !(AccountMgr::IsGMAccount(player->GetSession()->GetSecurity()) && sWorld->getBoolConfig(CONFIG_SILENTLY_GM_JOIN_TO_CHANNEL)); return !(player->GetSession()->IsGMAccount() && sWorld->getBoolConfig(CONFIG_SILENTLY_GM_JOIN_TO_CHANNEL));
} }
void Channel::Voice(ObjectGuid /*guid1*/, ObjectGuid /*guid2*/) void Channel::Voice(ObjectGuid /*guid1*/, ObjectGuid /*guid2*/)
@@ -2798,7 +2798,7 @@ void GameObject::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* t
return; return;
bool forcedFlags = GetGoType() == GAMEOBJECT_TYPE_CHEST && GetGOInfo()->chest.groupLootRules && HasLootRecipient(); bool forcedFlags = GetGoType() == GAMEOBJECT_TYPE_CHEST && GetGOInfo()->chest.groupLootRules && HasLootRecipient();
bool targetIsGM = target->IsGameMaster() && AccountMgr::IsGMAccount(target->GetSession()->GetSecurity()); bool targetIsGM = target->IsGameMaster() && target->GetSession()->IsGMAccount();
ByteBuffer fieldBuffer; ByteBuffer fieldBuffer;
+2 -2
View File
@@ -2192,14 +2192,14 @@ void Player::SetGameMaster(bool on)
if (on) if (on)
{ {
m_ExtraFlags |= PLAYER_EXTRA_GM_ON; m_ExtraFlags |= PLAYER_EXTRA_GM_ON;
if (AccountMgr::IsGMAccount(GetSession()->GetSecurity())) if (GetSession()->IsGMAccount())
SetFaction(FACTION_FRIENDLY); SetFaction(FACTION_FRIENDLY);
SetPlayerFlag(PLAYER_FLAGS_GM); SetPlayerFlag(PLAYER_FLAGS_GM);
SetUnitFlag2(UNIT_FLAG2_ALLOW_CHEAT_SPELLS); SetUnitFlag2(UNIT_FLAG2_ALLOW_CHEAT_SPELLS);
if (Pet* pet = GetPet()) if (Pet* pet = GetPet())
{ {
if (AccountMgr::IsGMAccount(GetSession()->GetSecurity())) if (GetSession()->IsGMAccount())
pet->SetFaction(FACTION_FRIENDLY); pet->SetFaction(FACTION_FRIENDLY);
pet->getHostileRefMgr().setOnlineOfflineState(false); pet->getHostileRefMgr().setOnlineOfflineState(false);
} }
@@ -220,7 +220,7 @@ void SocialMgr::GetFriendInfo(Player* player, ObjectGuid friendGUID, FriendInfo&
friendInfo.Class = 0; friendInfo.Class = 0;
Player* pFriend = ObjectAccessor::FindConnectedPlayer(friendGUID); Player* pFriend = ObjectAccessor::FindConnectedPlayer(friendGUID);
if (!pFriend || AccountMgr::IsGMAccount(pFriend->GetSession()->GetSecurity())) if (!pFriend || pFriend->GetSession()->IsGMAccount())
return; return;
TeamId teamId = player->GetTeamId(); TeamId teamId = player->GetTeamId();
+2 -2
View File
@@ -21142,7 +21142,7 @@ void Unit::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* target)
else if (index == UNIT_FIELD_FLAGS) else if (index == UNIT_FIELD_FLAGS)
{ {
uint32 appendValue = m_uint32Values[UNIT_FIELD_FLAGS]; uint32 appendValue = m_uint32Values[UNIT_FIELD_FLAGS];
if (target->IsGameMaster() && AccountMgr::IsGMAccount(target->GetSession()->GetSecurity())) if (target->IsGameMaster() && target->GetSession()->IsGMAccount())
appendValue &= ~UNIT_FLAG_NOT_SELECTABLE; appendValue &= ~UNIT_FLAG_NOT_SELECTABLE;
fieldBuffer << uint32(appendValue); fieldBuffer << uint32(appendValue);
@@ -21167,7 +21167,7 @@ void Unit::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* target)
if (cinfo->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER) if (cinfo->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER)
{ {
if (target->IsGameMaster() && AccountMgr::IsGMAccount(target->GetSession()->GetSecurity())) if (target->IsGameMaster() && target->GetSession()->IsGMAccount())
{ {
if (cinfo->Modelid1) if (cinfo->Modelid1)
displayId = cinfo->Modelid1; // Modelid1 is a visible model for gms displayId = cinfo->Modelid1; // Modelid1 is a visible model for gms
+1 -1
View File
@@ -70,7 +70,7 @@ void WorldSession::HandleAddFriendOpcode(WorldPacket& recv_data)
else else
{ {
Player* pFriend = ObjectAccessor::FindConnectedPlayer(friendGuid); Player* pFriend = ObjectAccessor::FindConnectedPlayer(friendGuid);
if (pFriend && pFriend->IsVisibleGloballyFor(GetPlayer()) && !AccountMgr::IsGMAccount(pFriend->GetSession()->GetSecurity())) if (pFriend && pFriend->IsVisibleGloballyFor(GetPlayer()) && !pFriend->GetSession()->IsGMAccount())
friendResult = FRIEND_ADDED_ONLINE; friendResult = FRIEND_ADDED_ONLINE;
else else
friendResult = FRIEND_ADDED_OFFLINE; friendResult = FRIEND_ADDED_OFFLINE;
+5
View File
@@ -175,6 +175,11 @@ WorldSession::~WorldSession()
LoginDatabase.Execute("UPDATE account SET online = 0 WHERE id = {};", GetAccountId()); // One-time query LoginDatabase.Execute("UPDATE account SET online = 0 WHERE id = {};", GetAccountId()); // One-time query
} }
bool WorldSession::IsGMAccount() const
{
return GetSecurity() >= SEC_GAMEMASTER;
}
std::string const& WorldSession::GetPlayerName() const std::string const& WorldSession::GetPlayerName() const
{ {
return _player ? _player->GetName() : DefaultPlayerName; return _player ? _player->GetName() : DefaultPlayerName;
+2
View File
@@ -332,6 +332,8 @@ public:
WorldSession(uint32 id, std::string&& name, std::shared_ptr<WorldSocket> sock, AccountTypes sec, uint8 expansion, time_t mute_time, LocaleConstant locale, uint32 recruiter, bool isARecruiter, bool skipQueue, uint32 TotalTime); WorldSession(uint32 id, std::string&& name, std::shared_ptr<WorldSocket> sock, AccountTypes sec, uint8 expansion, time_t mute_time, LocaleConstant locale, uint32 recruiter, bool isARecruiter, bool skipQueue, uint32 TotalTime);
~WorldSession(); ~WorldSession();
bool IsGMAccount() const;
bool PlayerLoading() const { return m_playerLoading; } bool PlayerLoading() const { return m_playerLoading; }
bool PlayerLogout() const { return m_playerLogout; } bool PlayerLogout() const { return m_playerLogout; }
bool PlayerRecentlyLoggedOut() const { return m_playerRecentlyLogout; } bool PlayerRecentlyLoggedOut() const { return m_playerRecentlyLogout; }