fix(Core/Session): Fixed loading global account data and tutorials. S… (#14038)

fix(Core/Session): Fixed loading global account data and tutorials. Source: TrinityCore.

Fixes #11974
This commit is contained in:
UltraNix
2022-12-06 13:08:46 +01:00
committed by GitHub
parent 590ad4e3e7
commit b9ea8b16af
4 changed files with 84 additions and 36 deletions

View File

@@ -842,13 +842,6 @@ void WorldSession::SendAuthWaitQueue(uint32 position)
}
}
void WorldSession::LoadGlobalAccountData()
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_ACCOUNT_DATA);
stmt->SetData(0, GetAccountId());
LoadAccountData(CharacterDatabase.Query(stmt), GLOBAL_CACHE_MASK);
}
void WorldSession::LoadAccountData(PreparedQueryResult result, uint32 mask)
{
for (uint32 i = 0; i < NUM_ACCOUNT_DATA_TYPES; ++i)
@@ -921,15 +914,17 @@ void WorldSession::SendAccountDataTimes(uint32 mask)
SendPacket(&data);
}
void WorldSession::LoadTutorialsData()
void WorldSession::LoadTutorialsData(PreparedQueryResult result)
{
memset(m_Tutorials, 0, sizeof(uint32) * MAX_ACCOUNT_TUTORIAL_VALUES);
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_TUTORIALS);
stmt->SetData(0, GetAccountId());
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
if (result)
{
for (uint8 i = 0; i < MAX_ACCOUNT_TUTORIAL_VALUES; ++i)
{
m_Tutorials[i] = (*result)[i].Get<uint32>();
}
}
m_TutorialsChanged = false;
}
@@ -1627,3 +1622,72 @@ void WorldSession::SendTimeSync()
_timeSyncTimer = _timeSyncNextCounter == 0 ? 5000 : 10000;
_timeSyncNextCounter++;
}
class AccountInfoQueryHolderPerRealm : public CharacterDatabaseQueryHolder
{
public:
enum
{
GLOBAL_ACCOUNT_DATA = 0,
TUTORIALS,
MAX_QUERIES
};
AccountInfoQueryHolderPerRealm() { SetSize(MAX_QUERIES); }
bool Initialize(uint32 accountId)
{
bool ok = true;
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_ACCOUNT_DATA);
stmt->SetData(0, accountId);
ok = SetPreparedQuery(GLOBAL_ACCOUNT_DATA, stmt) && ok;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_TUTORIALS);
stmt->SetData(0, accountId);
ok = SetPreparedQuery(TUTORIALS, stmt) && ok;
return ok;
}
};
void WorldSession::InitializeSession()
{
uint32 cacheVersion = sWorld->getIntConfig(CONFIG_CLIENTCACHE_VERSION);
sScriptMgr->OnBeforeFinalizePlayerWorldSession(cacheVersion);
std::shared_ptr<AccountInfoQueryHolderPerRealm> realmHolder = std::make_shared<AccountInfoQueryHolderPerRealm>();
if (!realmHolder->Initialize(GetAccountId()))
{
SendAuthResponse(AUTH_SYSTEM_ERROR, false);
return;
}
AddQueryHolderCallback(CharacterDatabase.DelayQueryHolder(realmHolder)).AfterComplete([this, cacheVersion](SQLQueryHolderBase const& holder)
{
InitializeSessionCallback(static_cast<AccountInfoQueryHolderPerRealm const&>(holder), cacheVersion);
});
}
void WorldSession::InitializeSessionCallback(CharacterDatabaseQueryHolder const& realmHolder, uint32 clientCacheVersion)
{
LoadAccountData(realmHolder.GetPreparedResult(AccountInfoQueryHolderPerRealm::GLOBAL_ACCOUNT_DATA), GLOBAL_CACHE_MASK);
LoadTutorialsData(realmHolder.GetPreparedResult(AccountInfoQueryHolderPerRealm::TUTORIALS));
if (!m_inQueue)
{
SendAuthResponse(AUTH_OK, true);
}
else
{
SendAuthWaitQueue(0);
}
SetInQueue(false);
ResetTimeOutTime(false);
SendAddonsInfo();
SendClientCacheVersion(clientCacheVersion);
SendTutorialsData();
}