Core/World: Fixed realm character count queries getting lost

This commit is contained in:
Shauren
2011-04-25 13:31:02 +02:00
parent 2bbf83d695
commit b7353f38b0
6 changed files with 37 additions and 14 deletions
+29 -12
View File
@@ -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();
}
}
}
+2 -2
View File
@@ -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;
@@ -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
@@ -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,
@@ -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)
}
@@ -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,
};