feat(Core/Account): Add account flags support (#22533)

This commit is contained in:
Kitzunu
2025-07-24 15:09:30 +02:00
committed by GitHub
parent 603249c046
commit 1e68280691
8 changed files with 109 additions and 13 deletions

View File

@@ -16,6 +16,7 @@
*/
#include "AccountMgr.h"
#include "Common.h"
#include "DatabaseEnv.h"
#include "ObjectAccessor.h"
#include "Player.h"
@@ -298,6 +299,39 @@ namespace AccountMgr
return false;
}
bool HasAccountFlag(uint32 accountId, uint32 flag)
{
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_FLAG);
stmt->SetData(0, accountId);
if (PreparedQueryResult result = LoginDatabase.Query(stmt))
{
uint32 flags = (*result)[0].Get<uint32>();
return (flags & flag) != 0;
}
return false;
}
void UpdateAccountFlag(uint32 accountId, uint32 flag, bool remove /*= false*/)
{
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(
remove ? LOGIN_UPD_REMOVE_ACCOUNT_FLAG : LOGIN_UPD_ADD_ACCOUNT_FLAG
);
stmt->SetData(0, flag);
stmt->SetData(1, accountId);
LoginDatabase.Execute(stmt);
}
void ValidateAccountFlags(uint32 accountId, uint32 flags, uint32 security)
{
bool hasGMFlag = (flags & ACCOUNT_FLAG_GM) != 0;
if (IsGMAccount(security) && !hasGMFlag)
UpdateAccountFlag(accountId, ACCOUNT_FLAG_GM);
else if (hasGMFlag && !IsGMAccount(security))
UpdateAccountFlag(accountId, ACCOUNT_FLAG_GM, true);
}
uint32 GetCharactersCount(uint32 accountId)
{
// check character count
@@ -313,6 +347,11 @@ namespace AccountMgr
return gmlevel == SEC_PLAYER;
}
bool IsGMAccount(uint32 gmlevel)
{
return gmlevel >= SEC_GAMEMASTER;
}
bool IsAdminAccount(uint32 gmlevel)
{
return gmlevel >= SEC_ADMINISTRATOR && gmlevel <= SEC_CONSOLE;

View File

@@ -19,6 +19,7 @@
#define _ACCMGR_H
#include "Define.h"
#include "Common.h"
#include <string>
enum AccountOpResult
@@ -52,8 +53,13 @@ namespace AccountMgr
uint32 GetCharactersCount(uint32 accountId);
bool IsPlayerAccount(uint32 gmlevel);
bool IsGMAccount(uint32 gmlevel);
bool IsAdminAccount(uint32 gmlevel);
bool IsConsoleAccount(uint32 gmlevel);
bool HasAccountFlag(uint32 accountId, uint32 flag);
void UpdateAccountFlag(uint32 accountId, uint32 flag, bool remove = false);
void ValidateAccountFlags(uint32 accountId, uint32 flags, uint32 security);
};
#endif

View File

@@ -352,6 +352,7 @@ struct AccountInfo
bool IsLockedToIP;
std::string LockCountry;
uint8 Expansion;
uint32 Flags;
int64 MuteTime;
LocaleConstant Locale;
uint32 Recruiter;
@@ -363,9 +364,9 @@ struct AccountInfo
explicit AccountInfo(Field* fields)
{
// 0 1 2 3 4 5 6 7 8 9 10 11
// SELECT a.id, a.sessionkey, a.last_ip, a.locked, a.lock_country, a.expansion, a.mutetime, a.locale, a.recruiter, a.os, a.totaltime, aa.gmLevel,
// 12 13
// 0 1 2 3 4 5 6 7 8 9 10 11 12
// SELECT a.id, a.sessionkey, a.last_ip, a.locked, a.lock_country, a.expansion, a.Flags a.mutetime, a.locale, a.recruiter, a.os, a.totaltime, aa.gmLevel,
// 13 14
// ab.unbandate > UNIX_TIMESTAMP() OR ab.unbandate = ab.bandate, r.id
// FROM account a
// LEFT JOIN account_access aa ON a.id = aa.AccountID AND aa.RealmID IN (-1, ?)
@@ -378,14 +379,15 @@ struct AccountInfo
IsLockedToIP = fields[3].Get<bool>();
LockCountry = fields[4].Get<std::string>();
Expansion = fields[5].Get<uint8>();
MuteTime = fields[6].Get<int64>();
Locale = LocaleConstant(fields[7].Get<uint8>());
Recruiter = fields[8].Get<uint32>();
OS = fields[9].Get<std::string>();
TotalTime = fields[10].Get<uint32>();
Security = AccountTypes(fields[11].Get<uint8>());
IsBanned = fields[12].Get<uint64>() != 0;
IsRectuiter = fields[13].Get<uint32>() != 0;
Flags = fields[6].Get<uint32>();
MuteTime = fields[7].Get<int64>();
Locale = LocaleConstant(fields[8].Get<uint8>());
Recruiter = fields[9].Get<uint32>();
OS = fields[10].Get<std::string>();
TotalTime = fields[11].Get<uint32>();
Security = AccountTypes(fields[12].Get<uint8>());
IsBanned = fields[13].Get<uint64>() != 0;
IsRectuiter = fields[14].Get<uint32>() != 0;
uint32 world_expansion = sWorld->getIntConfig(CONFIG_EXPANSION);
if (Expansion > world_expansion)
@@ -696,6 +698,8 @@ 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);