refactor(Core/Account): Move account flag logic from AccountMgr to WorldSession (#22558)

This commit is contained in:
Kitzunu
2025-07-27 08:54:16 +02:00
committed by GitHub
parent 24d1a4808f
commit 3f46e05d36
7 changed files with 38 additions and 46 deletions

View File

@@ -104,7 +104,7 @@ bool WorldSessionFilter::Process(WorldPacket* packet)
}
/// WorldSession constructor
WorldSession::WorldSession(uint32 id, std::string&& name, std::shared_ptr<WorldSocket> sock, AccountTypes sec, uint8 expansion,
WorldSession::WorldSession(uint32 id, std::string&& name, uint32 accountFlags, std::shared_ptr<WorldSocket> sock, AccountTypes sec, uint8 expansion,
time_t mute_time, LocaleConstant locale, uint32 recruiter, bool isARecruiter, bool skipQueue, uint32 TotalTime) :
m_muteTime(mute_time),
m_timeOutTime(0),
@@ -116,6 +116,7 @@ WorldSession::WorldSession(uint32 id, std::string&& name, std::shared_ptr<WorldS
_skipQueue(skipQueue),
_accountId(id),
_accountName(std::move(name)),
_accountFlags(accountFlags),
m_expansion(expansion),
m_total_time(TotalTime),
_logoutTime(0),
@@ -177,6 +178,30 @@ WorldSession::~WorldSession()
LoginDatabase.Execute("UPDATE account SET online = 0 WHERE id = {};", GetAccountId()); // One-time query
}
void WorldSession::UpdateAccountFlag(uint32 flag, bool remove /*= flase*/)
{
if (remove)
_accountFlags &= ~flag;
else
_accountFlags |= flag;
// Async update
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_SET_ACCOUNT_FLAG);
stmt->SetData(0, _accountFlags);
stmt->SetData(1, GetAccountId());
LoginDatabase.Execute(stmt);
}
void WorldSession::ValidateAccountFlags()
{
bool hasGMFlag = HasAccountFlag(ACCOUNT_FLAG_GM);
if (IsGMAccount() && !hasGMFlag)
UpdateAccountFlag(ACCOUNT_FLAG_GM);
else if (hasGMFlag && !IsGMAccount())
UpdateAccountFlag(ACCOUNT_FLAG_GM, true);
}
bool WorldSession::IsGMAccount() const
{
return GetSecurity() >= SEC_GAMEMASTER;

View File

@@ -329,9 +329,14 @@ struct PacketCounter
class WorldSession
{
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, uint32 accountFlags, 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 GetAccountFlags() const { return _accountFlags; }
bool HasAccountFlag(uint32 flag) const { return (_accountFlags & flag) != 0; }
void UpdateAccountFlag(uint32 flag, bool remove = false);
void ValidateAccountFlags();
bool IsGMAccount() const;
bool PlayerLoading() const { return m_playerLoading; }
@@ -1158,6 +1163,7 @@ private:
bool _skipQueue;
uint32 _accountId;
std::string _accountName;
uint32 _accountFlags;
uint8 m_expansion;
uint32 m_total_time;

View File

@@ -698,8 +698,6 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<AuthSession> authSes
LoginDatabase.Execute(stmt);
AccountMgr::ValidateAccountFlags(account.Id, account.Flags, account.Security);
// At this point, we can safely hook a successful login
sScriptMgr->OnAccountLogin(account.Id);
@@ -707,7 +705,7 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<AuthSession> authSes
sScriptMgr->OnLastIpUpdate(account.Id, address);
_worldSession = new WorldSession(account.Id, std::move(authSession->Account), shared_from_this(), account.Security,
_worldSession = new WorldSession(account.Id, std::move(authSession->Account), account.Flags, shared_from_this(), account.Security,
account.Expansion, account.MuteTime, account.Locale, account.Recruiter, account.IsRectuiter, account.Security ? true : false, account.TotalTime);
_worldSession->ReadAddonsInfo(authSession->AddonInfo);
@@ -718,6 +716,8 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<AuthSession> authSes
_worldSession->InitWarden(account.SessionKey, account.OS);
}
_worldSession->ValidateAccountFlags();
sWorldSessionMgr->AddSession(_worldSession);
AsyncRead();