refactor(Core/Cache): move the GlobalPlayerCache to its own class (#9166)

This commit is contained in:
Skjalf
2021-11-18 12:53:36 -03:00
committed by GitHub
parent 00dc369cb6
commit 731d256420
47 changed files with 898 additions and 595 deletions

View File

@@ -20,6 +20,7 @@
#include "AuctionHouseMgr.h"
#include "Battleground.h"
#include "CalendarMgr.h"
#include "CharacterCache.h"
#include "Chat.h"
#include "Common.h"
#include "DatabaseEnv.h"
@@ -521,7 +522,7 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket& recvData)
}
// Check name uniqueness in the same step as saving to database
if (sWorld->GetGlobalPlayerGUID(createInfo->Name))
if (sCharacterCache->GetCharacterGuidByName(createInfo->Name))
{
SendCharCreate(CHAR_CREATE_NAME_IN_USE);
return;
@@ -572,8 +573,7 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket& recvData)
{
LOG_INFO("entities.player.character", "Account: %u (IP: %s) Create Character: %s %s", GetAccountId(), GetRemoteAddress().c_str(), newChar->GetName().c_str(), newChar->GetGUID().ToString().c_str());
sScriptMgr->OnPlayerCreate(newChar.get());
sWorld->AddGlobalPlayerData(newChar->GetGUID().GetCounter(), GetAccountId(), newChar->GetName(), newChar->getGender(), newChar->getRace(), newChar->getClass(), newChar->getLevel(), 0, 0);
sCharacterCache->AddCharacterCacheEntry(newChar->GetGUID(), GetAccountId(), newChar->GetName(), newChar->getGender(), newChar->getRace(), newChar->getClass(), newChar->getLevel());
SendCharCreate(CHAR_CREATE_SUCCESS);
}
else
@@ -629,11 +629,11 @@ void WorldSession::HandleCharDeleteOpcode(WorldPacket& recvData)
return;
}
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid.GetCounter()))
if (CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(guid))
{
accountId = playerData->accountId;
name = playerData->name;
level = playerData->level;
accountId = playerData->AccountId;
name = playerData->Name;
level = playerData->Level;
}
// prevent deleting other players' characters using cheating tools
@@ -659,7 +659,7 @@ void WorldSession::HandleCharDeleteOpcode(WorldPacket& recvData)
sCalendarMgr->RemoveAllPlayerEventsAndInvites(guid);
Player::DeleteFromDB(guid.GetCounter(), GetAccountId(), true, false);
sWorld->DeleteGlobalPlayerData(guid.GetCounter(), name);
sCharacterCache->DeleteCharacterCacheEntry(guid, name);
SendCharDelete(CHAR_DELETE_SUCCESS);
}
@@ -836,7 +836,7 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder const& holder)
chH.PSendSysMessage("%s", GitRevision::GetFullVersion());
}
if (uint32 guildId = Player::GetGuildIdFromStorage(pCurrChar->GetGUID().GetCounter()))
if (uint32 guildId = sCharacterCache->GetCharacterGuildIdByGuid(pCurrChar->GetGUID()))
{
Guild* guild = sGuildMgr->GetGuildById(guildId);
Guild::Member const* member = guild ? guild->GetMember(pCurrChar->GetGUID()) : nullptr;
@@ -1394,8 +1394,7 @@ void WorldSession::HandleCharRenameCallBack(std::shared_ptr<CharacterRenameInfo>
SendCharRename(RESPONSE_SUCCESS, renameInfo.get());
// xinef: update global data
sWorld->UpdateGlobalNameData(guidLow, oldName, renameInfo->Name);
sWorld->UpdateGlobalPlayerData(guidLow, PLAYER_UPDATE_DATA_NAME, renameInfo->Name);
sCharacterCache->UpdateCharacterData(renameInfo->Guid, renameInfo->Name);
}
void WorldSession::HandleSetPlayerDeclinedNames(WorldPacket& recvData)
@@ -1409,7 +1408,7 @@ void WorldSession::HandleSetPlayerDeclinedNames(WorldPacket& recvData)
// not accept declined names for unsupported languages
std::string name;
if (!sObjectMgr->GetPlayerNameByGUID(guid.GetCounter(), name))
if (!sCharacterCache->GetCharacterNameByGuid(guid, name))
{
SendSetPlayerDeclinedNamesResult(DECLINED_NAMES_RESULT_ERROR, guid);
return;
@@ -1621,7 +1620,7 @@ void WorldSession::HandleCharCustomizeCallback(std::shared_ptr<CharacterCustomiz
}
// get the players old (at this moment current) race
GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(customizeInfo->Guid.GetCounter());
CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(customizeInfo->Guid);
if (!playerData)
{
SendCharCustomize(CHAR_CREATE_ERROR, customizeInfo.get());
@@ -1665,7 +1664,7 @@ void WorldSession::HandleCharCustomizeCallback(std::shared_ptr<CharacterCustomiz
}
// character with this name already exist
if (ObjectGuid newguid = sObjectMgr->GetPlayerGUIDByName(customizeInfo->Name))
if (ObjectGuid newguid = sCharacterCache->GetCharacterGuidByName(customizeInfo->Name))
{
if (newguid != customizeInfo->Guid)
{
@@ -1702,9 +1701,7 @@ void WorldSession::HandleCharCustomizeCallback(std::shared_ptr<CharacterCustomiz
CharacterDatabase.CommitTransaction(trans);
// xinef: update global data
sWorld->UpdateGlobalNameData(lowGuid, playerData->name, customizeInfo->Name);
sWorld->UpdateGlobalPlayerData(lowGuid, PLAYER_UPDATE_DATA_NAME | PLAYER_UPDATE_DATA_GENDER, customizeInfo->Name, 0, customizeInfo->Gender);
sCharacterCache->UpdateCharacterData(customizeInfo->Guid, customizeInfo->Name, customizeInfo->Gender);
SendCharCustomize(RESPONSE_SUCCESS, customizeInfo.get());
@@ -1916,16 +1913,16 @@ void WorldSession::HandleCharFactionOrRaceChangeCallback(std::shared_ptr<Charact
ObjectGuid::LowType lowGuid = factionChangeInfo->Guid.GetCounter();
// get the players old (at this moment current) race
GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(lowGuid);
if (!playerData) // pussywizard: restoring character via www spoils nameData (it's not restored so it may be null)
CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(factionChangeInfo->Guid);
if (!playerData)
{
SendCharFactionChange(CHAR_CREATE_ERROR, factionChangeInfo.get());
return;
}
uint8 oldRace = playerData->race;
uint8 playerClass = playerData->playerClass;
uint8 level = playerData->level;
uint8 oldRace = playerData->Race;
uint8 playerClass = playerData->Class;
uint8 level = playerData->Level;
if (!sObjectMgr->GetPlayerInfo(factionChangeInfo->Race, playerClass))
{
@@ -1949,7 +1946,7 @@ void WorldSession::HandleCharFactionOrRaceChangeCallback(std::shared_ptr<Charact
if (factionChangeInfo->FactionChange)
{
// if player is in a guild
if (playerData->guildId && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD))
if (playerData->GuildId && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD))
{
SendCharFactionChange(CHAR_CREATE_CHARACTER_IN_GUILD, factionChangeInfo.get());
return;
@@ -1963,7 +1960,7 @@ void WorldSession::HandleCharFactionOrRaceChangeCallback(std::shared_ptr<Charact
}
// check mailbox
if (playerData->mailCount)
if (playerData->MailCount)
{
SendCharFactionChange(CHAR_CREATE_CHARACTER_DELETE_MAIL, factionChangeInfo.get());
return;
@@ -1974,7 +1971,7 @@ void WorldSession::HandleCharFactionOrRaceChangeCallback(std::shared_ptr<Charact
for (uint8 i = 0; i < 2; ++i) // check both neutral and faction-specific AH
{
AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(i == 0 ? 0 : (((1 << (playerData->race - 1)) & RACEMASK_ALLIANCE) ? 12 : 29));
AuctionHouseObject* auctionHouse = sAuctionMgr->GetAuctionsMap(i == 0 ? 0 : (((1 << (playerData->Race - 1)) & RACEMASK_ALLIANCE) ? 12 : 29));
for (auto const& [auID, Aentry] : auctionHouse->GetAuctions())
{
@@ -2057,7 +2054,7 @@ void WorldSession::HandleCharFactionOrRaceChangeCallback(std::shared_ptr<Charact
}
// character with this name already exist
if (ObjectGuid newguid = sObjectMgr->GetPlayerGUIDByName(factionChangeInfo->Name))
if (ObjectGuid newguid = sCharacterCache->GetCharacterGuidByName(factionChangeInfo->Name))
{
if (newguid != factionChangeInfo->Guid)
{
@@ -2099,11 +2096,10 @@ void WorldSession::HandleCharFactionOrRaceChangeCallback(std::shared_ptr<Charact
}
LOG_INFO("entities.player.character", "Account: %d (IP: %s), Character [%s] (guid: %u) Changed Race/Faction to: %s",
GetAccountId(), GetRemoteAddress().c_str(), playerData->name.c_str(), lowGuid, factionChangeInfo->Name.c_str());
GetAccountId(), GetRemoteAddress().c_str(), playerData->Name.c_str(), lowGuid, factionChangeInfo->Name.c_str());
// xinef: update global data
sWorld->UpdateGlobalNameData(lowGuid, playerData->name, factionChangeInfo->Name);
sWorld->UpdateGlobalPlayerData(lowGuid, PLAYER_UPDATE_DATA_NAME | PLAYER_UPDATE_DATA_RACE | PLAYER_UPDATE_DATA_GENDER, factionChangeInfo->Name, 0, factionChangeInfo->Gender, factionChangeInfo->Race);
sCharacterCache->UpdateCharacterData(factionChangeInfo->Guid, factionChangeInfo->Name);
if (oldRace != factionChangeInfo->Race)
{
@@ -2201,7 +2197,7 @@ void WorldSession::HandleCharFactionOrRaceChangeCallback(std::shared_ptr<Charact
// Reset guild
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD))
{
if (uint32 guildId = playerData->guildId)
if (uint32 guildId = playerData->GuildId)
if (Guild* guild = sGuildMgr->GetGuildById(guildId))
guild->DeleteMember(factionChangeInfo->Guid, false, false, true);
}