mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/World: Store account id in CharacterInfo to reduce the amount of database queries
This commit is contained in:
@@ -168,7 +168,6 @@ void CharacterDatabaseConnection::DoPrepareStatements()
|
||||
PrepareStatement(CHAR_DEL_GIFT, "DELETE FROM character_gifts WHERE item_guid = ?", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_SEL_CHARACTER_GIFT_BY_ITEM, "SELECT entry, flags FROM character_gifts WHERE item_guid = ?", CONNECTION_SYNCH);
|
||||
PrepareStatement(CHAR_SEL_ACCOUNT_BY_NAME, "SELECT account FROM characters WHERE name = ?", CONNECTION_SYNCH);
|
||||
PrepareStatement(CHAR_SEL_ACCOUNT_BY_GUID, "SELECT account FROM characters WHERE guid = ?", CONNECTION_SYNCH);
|
||||
PrepareStatement(CHAR_SEL_CHARACTER_DATA_BY_GUID, "SELECT account, name, level FROM characters WHERE guid = ?", CONNECTION_SYNCH);
|
||||
PrepareStatement(CHAR_DEL_ACCOUNT_INSTANCE_LOCK_TIMES, "DELETE FROM account_instance_times WHERE accountId = ?", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_INS_ACCOUNT_INSTANCE_LOCK_TIMES, "INSERT INTO account_instance_times (accountId, instanceId, releaseTime) VALUES (?, ?, ?)", CONNECTION_ASYNC);
|
||||
|
||||
@@ -148,7 +148,6 @@ enum CharacterDatabaseStatements
|
||||
CHAR_DEL_GIFT,
|
||||
CHAR_SEL_CHARACTER_GIFT_BY_ITEM,
|
||||
CHAR_SEL_ACCOUNT_BY_NAME,
|
||||
CHAR_SEL_ACCOUNT_BY_GUID,
|
||||
CHAR_DEL_ACCOUNT_INSTANCE_LOCK_TIMES,
|
||||
CHAR_INS_ACCOUNT_INSTANCE_LOCK_TIMES,
|
||||
CHAR_SEL_MATCH_MAKER_RATING,
|
||||
|
||||
@@ -2254,9 +2254,6 @@ bool ObjectMgr::GetPlayerNameAndClassByGUID(ObjectGuid const& guid, std::string&
|
||||
|
||||
uint32 ObjectMgr::GetPlayerTeamByGUID(ObjectGuid const& guid)
|
||||
{
|
||||
if (Player* player = ObjectAccessor::FindConnectedPlayer(guid))
|
||||
return player->GetTeam();
|
||||
|
||||
if (CharacterInfo const* characterInfo = sWorld->GetCharacterInfo(guid))
|
||||
return Player::TeamForRace(characterInfo->Race);
|
||||
|
||||
@@ -2265,15 +2262,8 @@ uint32 ObjectMgr::GetPlayerTeamByGUID(ObjectGuid const& guid)
|
||||
|
||||
uint32 ObjectMgr::GetPlayerAccountIdByGUID(ObjectGuid const& guid)
|
||||
{
|
||||
// prevent DB access for online player
|
||||
if (Player* player = ObjectAccessor::FindConnectedPlayer(guid))
|
||||
return player->GetSession()->GetAccountId();
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_ACCOUNT_BY_GUID);
|
||||
stmt->setUInt64(0, guid.GetCounter());
|
||||
|
||||
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
|
||||
return (*result)[0].GetUInt32();
|
||||
if (CharacterInfo const* characterInfo = sWorld->GetCharacterInfo(guid))
|
||||
return characterInfo->AccountId;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ void WorldSession::HandleCharEnum(PreparedQueryResult result)
|
||||
_legitCharacters.insert(charInfo.Guid);
|
||||
|
||||
if (!sWorld->HasCharacterInfo(charInfo.Guid)) // This can happen if characters are inserted into the database manually. Core hasn't loaded name data yet.
|
||||
sWorld->AddCharacterInfo(charInfo.Guid, charInfo.Name, charInfo.Sex, charInfo.Race, charInfo.Class, charInfo.Level, false);
|
||||
sWorld->AddCharacterInfo(charInfo.Guid, GetAccountId(), charInfo.Name, charInfo.Sex, charInfo.Race, charInfo.Class, charInfo.Level, false);
|
||||
|
||||
charEnum.Characters.emplace_back(charInfo);
|
||||
}
|
||||
@@ -345,7 +345,7 @@ void WorldSession::HandleCharUndeleteEnum(PreparedQueryResult result)
|
||||
TC_LOG_INFO("network", "Loading undeleted char guid %s from account %u.", charInfo.Guid.ToString().c_str(), GetAccountId());
|
||||
|
||||
if (!sWorld->HasCharacterInfo(charInfo.Guid)) // This can happen if characters are inserted into the database manually. Core hasn't loaded name data yet.
|
||||
sWorld->AddCharacterInfo(charInfo.Guid, charInfo.Name, charInfo.Sex, charInfo.Race, charInfo.Class, charInfo.Level, true);
|
||||
sWorld->AddCharacterInfo(charInfo.Guid, GetAccountId(), charInfo.Name, charInfo.Sex, charInfo.Race, charInfo.Class, charInfo.Level, true);
|
||||
|
||||
charEnum.Characters.emplace_back(charInfo);
|
||||
}
|
||||
@@ -749,7 +749,7 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, WorldPac
|
||||
|
||||
TC_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Create Character: %s %s", GetAccountId(), GetRemoteAddress().c_str(), createInfo->Name.c_str(), newChar.GetGUID().ToString().c_str());
|
||||
sScriptMgr->OnPlayerCreate(&newChar);
|
||||
sWorld->AddCharacterInfo(newChar.GetGUID(), newChar.GetName(), newChar.getGender(), newChar.getRace(), newChar.getClass(), newChar.getLevel(), false);
|
||||
sWorld->AddCharacterInfo(newChar.GetGUID(), GetAccountId(), newChar.GetName(), newChar.getGender(), newChar.getRace(), newChar.getClass(), newChar.getLevel(), false);
|
||||
|
||||
newChar.CleanupsBeforeDelete();
|
||||
_charCreateCallback.Reset();
|
||||
|
||||
@@ -681,7 +681,7 @@ DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, s
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
|
||||
// in case of name conflict player has to rename at login anyway
|
||||
sWorld->AddCharacterInfo(ObjectGuid::Create<HighGuid::Player>(guid), name, gender, race, playerClass, level, false);
|
||||
sWorld->AddCharacterInfo(ObjectGuid::Create<HighGuid::Player>(guid), account, name, gender, race, playerClass, level, false);
|
||||
|
||||
sObjectMgr->GetGenerator<HighGuid::Item>().Set(sObjectMgr->GetGenerator<HighGuid::Item>().GetNextAfterMaxUsed() + items.size());
|
||||
sObjectMgr->_mailId += mails.size();
|
||||
|
||||
@@ -3365,7 +3365,7 @@ void World::LoadCharacterInfoStore()
|
||||
|
||||
_characterInfoStore.clear();
|
||||
|
||||
QueryResult result = CharacterDatabase.Query("SELECT guid, name, race, gender, class, level, deleteDate FROM characters");
|
||||
QueryResult result = CharacterDatabase.Query("SELECT guid, name, account, race, gender, class, level, deleteDate FROM characters");
|
||||
if (!result)
|
||||
{
|
||||
TC_LOG_INFO("server.loading", "No character name data loaded, empty query");
|
||||
@@ -3375,18 +3375,19 @@ void World::LoadCharacterInfoStore()
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
AddCharacterInfo(ObjectGuid::Create<HighGuid::Player>(fields[0].GetUInt64()), fields[1].GetString(),
|
||||
fields[3].GetUInt8() /*gender*/, fields[2].GetUInt8() /*race*/, fields[4].GetUInt8() /*class*/, fields[5].GetUInt8() /*level*/, fields[6].GetUInt32() != 0);
|
||||
AddCharacterInfo(ObjectGuid::Create<HighGuid::Player>(fields[0].GetUInt64()), fields[2].GetUInt32(), fields[1].GetString(),
|
||||
fields[4].GetUInt8() /*gender*/, fields[3].GetUInt8() /*race*/, fields[5].GetUInt8() /*class*/, fields[6].GetUInt8() /*level*/, fields[7].GetUInt32() != 0);
|
||||
}
|
||||
while (result->NextRow());
|
||||
|
||||
TC_LOG_INFO("server.loading", "Loaded character infos for " SZFMTD " characters", _characterInfoStore.size());
|
||||
}
|
||||
|
||||
void World::AddCharacterInfo(ObjectGuid const& guid, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, bool isDeleted)
|
||||
void World::AddCharacterInfo(ObjectGuid const& guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, bool isDeleted)
|
||||
{
|
||||
CharacterInfo& data = _characterInfoStore[guid];
|
||||
data.Name = name;
|
||||
data.AccountId = accountId;
|
||||
data.Race = race;
|
||||
data.Sex = gender;
|
||||
data.Class = playerClass;
|
||||
|
||||
@@ -551,6 +551,7 @@ typedef std::unordered_map<uint32, WorldSession*> SessionMap;
|
||||
struct CharacterInfo
|
||||
{
|
||||
std::string Name;
|
||||
uint32 AccountId;
|
||||
uint8 Class;
|
||||
uint8 Race;
|
||||
uint8 Sex;
|
||||
@@ -777,7 +778,7 @@ class World
|
||||
void UpdateAreaDependentAuras();
|
||||
|
||||
CharacterInfo const* GetCharacterInfo(ObjectGuid const& guid) const;
|
||||
void AddCharacterInfo(ObjectGuid const& guid, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, bool isDeleted);
|
||||
void AddCharacterInfo(ObjectGuid const& guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, bool isDeleted);
|
||||
void DeleteCharacterInfo(ObjectGuid const& guid) { _characterInfoStore.erase(guid); }
|
||||
bool HasCharacterInfo(ObjectGuid const& guid) { return _characterInfoStore.find(guid) != _characterInfoStore.end(); }
|
||||
void UpdateCharacterInfo(ObjectGuid const& guid, std::string const& name, uint8 gender = GENDER_NONE, uint8 race = RACE_NONE);
|
||||
|
||||
Reference in New Issue
Block a user