From 70c34bd403962e2b678ba60d1462f2ddb209fe2a Mon Sep 17 00:00:00 2001 From: Tralenor <76077537+Tralenor@users.noreply.github.com> Date: Thu, 9 Jan 2025 20:20:02 +0100 Subject: [PATCH] fix(Core/World): edge case when last Char on realm was deleted (#20864) --- src/server/game/World/World.cpp | 24 ++++++++++++------------ src/server/game/World/World.h | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index f0893f3f16ab6e..a6bf64577d55da 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -2884,27 +2884,27 @@ void World::UpdateRealmCharCount(uint32 accountId) { CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_COUNT); stmt->SetData(0, accountId); - _queryProcessor.AddCallback(CharacterDatabase.AsyncQuery(stmt).WithPreparedCallback(std::bind(&World::_UpdateRealmCharCount, this, std::placeholders::_1))); + _queryProcessor.AddCallback(CharacterDatabase.AsyncQuery(stmt).WithPreparedCallback(std::bind(&World::_UpdateRealmCharCount, this, std::placeholders::_1,accountId))); } -void World::_UpdateRealmCharCount(PreparedQueryResult resultCharCount) +void World::_UpdateRealmCharCount(PreparedQueryResult resultCharCount,uint32 accountId) { + uint8 charCount{0}; if (resultCharCount) { Field* fields = resultCharCount->Fetch(); - uint32 accountId = fields[0].Get(); - uint8 charCount = uint8(fields[1].Get()); + charCount = uint8(fields[1].Get()); + } - LoginDatabaseTransaction trans = LoginDatabase.BeginTransaction(); + LoginDatabaseTransaction trans = LoginDatabase.BeginTransaction(); - LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_REP_REALM_CHARACTERS); - stmt->SetData(0, charCount); - stmt->SetData(1, accountId); - stmt->SetData(2, realm.Id.Realm); - trans->Append(stmt); + LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_REP_REALM_CHARACTERS); + stmt->SetData(0, charCount); + stmt->SetData(1, accountId); + stmt->SetData(2, realm.Id.Realm); + trans->Append(stmt); - LoginDatabase.CommitTransaction(trans); - } + LoginDatabase.CommitTransaction(trans); } void World::InitWeeklyQuestResetTime() diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h index 76869e8f35c962..fa0e1302a2a80e 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -347,7 +347,7 @@ class World: public IWorld protected: void _UpdateGameTime(); // callback for UpdateRealmCharacters - void _UpdateRealmCharCount(PreparedQueryResult resultCharCount); + void _UpdateRealmCharCount(PreparedQueryResult resultCharCount,uint32 accountId); void InitDailyQuestResetTime(); void InitWeeklyQuestResetTime();