diff options
Diffstat (limited to 'src')
6 files changed, 37 insertions, 14 deletions
diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index c5a9b63b423..d01a0e05ba7 100755 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -2571,19 +2571,29 @@ void World::SendAutoBroadcast() void World::UpdateRealmCharCount(uint32 accountId) { - m_realmCharCallback.SetParam(accountId); - m_realmCharCallback.SetFutureResult(CharacterDatabase.AsyncPQuery("SELECT COUNT(guid) FROM characters WHERE account = '%u'", accountId)); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_GET_CHARACTER_COUNT); + stmt->setUInt32(0, accountId); + m_realmCharCallbacks.insert(CharacterDatabase.AsyncQuery(stmt)); } -void World::_UpdateRealmCharCount(QueryResult resultCharCount, uint32 accountId) +void World::_UpdateRealmCharCount(PreparedQueryResult resultCharCount) { if (resultCharCount) { Field *fields = resultCharCount->Fetch(); - uint32 charCount = fields[0].GetUInt32(); + uint32 accountId = fields[0].GetUInt32(); + uint32 charCount = fields[1].GetUInt32(); - LoginDatabase.PExecute("DELETE FROM realmcharacters WHERE acctid= '%d' AND realmid = '%d'", accountId, realmID); - LoginDatabase.PExecute("INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (%u, %u, %u)", charCount, accountId, realmID); + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_REALMCHARACTERS); + stmt->setUInt32(0, accountId); + stmt->setUInt32(1, realmID); + LoginDatabase.Execute(stmt); + + stmt = LoginDatabase.GetPreparedStatement(LOGIN_ADD_REALMCHARACTERS); + stmt->setUInt32(0, charCount); + stmt->setUInt32(1, accountId); + stmt->setUInt32(2, realmID); + LoginDatabase.Execute(stmt); } } @@ -2802,13 +2812,20 @@ uint64 World::getWorldState(uint32 index) const void World::ProcessQueryCallbacks() { - QueryResult result; + PreparedQueryResult result; - if (m_realmCharCallback.IsReady()) + while (!m_realmCharCallbacks.is_empty()) { - uint32 param = m_realmCharCallback.GetParam(); - m_realmCharCallback.GetResult(result); - _UpdateRealmCharCount(result, param); - m_realmCharCallback.FreeResult(); + ACE_Future<PreparedQueryResult> lResult; + ACE_Time_Value timeout = ACE_Time_Value::zero; + if (m_realmCharCallbacks.next_readable(lResult, &timeout) != 1) + break; + + if (lResult.ready()) + { + lResult.get(result); + _UpdateRealmCharCount(result); + lResult.cancel(); + } } } diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h index 2a1b69b6063..b793325b17b 100755 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -735,7 +735,7 @@ class World protected: void _UpdateGameTime(); // callback for UpdateRealmCharacters - void _UpdateRealmCharCount(QueryResult resultCharCount, uint32 accountId); + void _UpdateRealmCharCount(PreparedQueryResult resultCharCount); void InitDailyQuestResetTime(); void InitWeeklyQuestResetTime(); @@ -819,7 +819,7 @@ class World private: void ProcessQueryCallbacks(); - QueryCallback<QueryResult, uint32> m_realmCharCallback; + ACE_Future_Set<PreparedQueryResult> m_realmCharCallbacks; }; extern uint32 realmID; diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.cpp b/src/server/shared/Database/Implementation/CharacterDatabase.cpp index f2e9b431f7d..a666eac4da2 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp @@ -109,6 +109,7 @@ void CharacterDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(CHAR_ADD_ACCOUNT_INSTANCE_LOCK_TIMES, "INSERT INTO account_instance_times (accountId, instanceId, releaseTime) VALUES (?, ?, ?)", CONNECTION_ASYNC) PREPARE_STATEMENT(CHAR_LOAD_PLAYER_NAME_CLASS, "SELECT name, class FROM characters WHERE guid = ?", CONNECTION_SYNCH); PREPARE_STATEMENT(CHAR_LOAD_MATCH_MAKER_RATING, "SELECT matchMakerRating FROM character_arena_stats WHERE guid = ? AND slot = ?", CONNECTION_SYNCH); + PREPARE_STATEMENT(CHAR_GET_CHARACTER_COUNT, "SELECT account, COUNT(guid) FROM characters WHERE account = ?", CONNECTION_ASYNC); // Guild handling // 0: uint32, 1: string, 2: uint32, 3: string, 4: string, 5: uint64, 6-10: uint32, 11: uint64 diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.h b/src/server/shared/Database/Implementation/CharacterDatabase.h index 91290bbd4a0..2d9ebd93a3f 100755 --- a/src/server/shared/Database/Implementation/CharacterDatabase.h +++ b/src/server/shared/Database/Implementation/CharacterDatabase.h @@ -118,6 +118,7 @@ enum CharacterDatabaseStatements CHAR_ADD_ACCOUNT_INSTANCE_LOCK_TIMES, CHAR_LOAD_PLAYER_NAME_CLASS, CHAR_LOAD_MATCH_MAKER_RATING, + CHAR_GET_CHARACTER_COUNT, CHAR_ADD_GUILD, CHAR_DEL_GUILD, diff --git a/src/server/shared/Database/Implementation/LoginDatabase.cpp b/src/server/shared/Database/Implementation/LoginDatabase.cpp index 50f5f8df70f..f40be21fcf9 100755 --- a/src/server/shared/Database/Implementation/LoginDatabase.cpp +++ b/src/server/shared/Database/Implementation/LoginDatabase.cpp @@ -42,4 +42,6 @@ void LoginDatabaseConnection::DoPrepareStatements() PREPARE_STATEMENT(LOGIN_SET_IP_NOT_BANNED, "DELETE FROM ip_banned WHERE ip = ?", CONNECTION_ASYNC) PREPARE_STATEMENT(LOGIN_SET_ACCOUNT_BANNED, "INSERT INTO account_banned VALUES (?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+?, ?, ?, 1)", CONNECTION_ASYNC) PREPARE_STATEMENT(LOGIN_SET_ACCOUNT_NOT_BANNED, "UPDATE account_banned SET active = 0 WHERE id = ? AND active != 0", CONNECTION_ASYNC) + PREPARE_STATEMENT(LOGIN_DEL_REALMCHARACTERS, "DELETE FROM realmcharacters WHERE acctid = ? AND realmid = ?", CONNECTION_ASYNC) + PREPARE_STATEMENT(LOGIN_ADD_REALMCHARACTERS, "INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (?, ?, ?)", CONNECTION_ASYNC) } diff --git a/src/server/shared/Database/Implementation/LoginDatabase.h b/src/server/shared/Database/Implementation/LoginDatabase.h index a371e115b68..cb7cb2b83d1 100755 --- a/src/server/shared/Database/Implementation/LoginDatabase.h +++ b/src/server/shared/Database/Implementation/LoginDatabase.h @@ -62,6 +62,8 @@ enum LoginDatabaseStatements LOGIN_SET_IP_NOT_BANNED, LOGIN_SET_ACCOUNT_BANNED, LOGIN_SET_ACCOUNT_NOT_BANNED, + LOGIN_DEL_REALMCHARACTERS, + LOGIN_ADD_REALMCHARACTERS, MAX_LOGINDATABASE_STATEMENTS, }; |
