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

@@ -172,7 +172,7 @@ void WorldSession::HandleArenaTeamAcceptOpcode(WorldPacket& /*recvData*/)
}
// Only allow members of the other faction to join the team if cross faction interaction is enabled
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && _player->GetTeamId() != sObjectMgr->GetPlayerTeamIdByGUID(arenaTeam->GetCaptain().GetCounter()))
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && _player->GetTeamId() != sCharacterCache->GetCharacterTeamByGuid(arenaTeam->GetCaptain()))
{
SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, "", "", ERR_ARENA_TEAM_NOT_ALLIED);
return;

View File

@@ -431,7 +431,7 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
// impossible have online own another character (use this for speedup check in case online owner)
Player* auction_owner = ObjectAccessor::FindConnectedPlayer(auction->owner);
if (!auction_owner && sObjectMgr->GetPlayerAccountIdByGUID(auction->owner.GetCounter()) == GetAccountId())
if (!auction_owner && sCharacterCache->GetCharacterAccountIdByGuid(auction->owner) == GetAccountId())
{
//you cannot bid your another character auction:
SendAuctionCommandResult(0, AUCTION_PLACE_BID, ERR_AUCTION_BID_OWN);

View File

@@ -549,13 +549,13 @@ void WorldSession::HandleCalendarEventInvite(WorldPacket& recvData)
else
{
// xinef: Get Data From global storage
if (ObjectGuid guid = sWorld->GetGlobalPlayerGUID(name))
if (ObjectGuid guid = sCharacterCache->GetCharacterGuidByName(name))
{
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid.GetCounter()))
if (CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(guid))
{
inviteeGuid = guid;
inviteeTeamId = Player::TeamIdForRace(playerData->race);
inviteeGuildId = playerData->guildId;
inviteeTeamId = Player::TeamIdForRace(playerData->Race);
inviteeGuildId = playerData->GuildId;
}
}
}

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);
}

View File

@@ -328,8 +328,7 @@ void WorldSession::HandleGroupUninviteGuidOpcode(WorldPacket& recvData)
return;
}
// Xinef: name is properly filled in packets
sObjectMgr->GetPlayerNameByGUID(guid.GetCounter(), name);
sCharacterCache->GetCharacterNameByGuid(guid, name);
PartyResult res = GetPlayer()->CanUninviteFromGroup(guid);
if (res != ERR_PARTY_RESULT_OK)
@@ -681,7 +680,7 @@ void WorldSession::HandleGroupChangeSubGroupOpcode(WorldPacket& recvData)
else
{
CharacterDatabase.EscapeString(name);
guid = sObjectMgr->GetPlayerGUIDByName(name.c_str());
guid = sCharacterCache->GetCharacterGuidByName(name);
}
group->ChangeMembersGroup(guid, groupNr);
@@ -1185,7 +1184,7 @@ void WorldSession::HandleGroupSwapSubGroupOpcode(WorldPacket& recv_data)
}
else
{
if (ObjectGuid guid = sObjectMgr->GetPlayerGUIDByName(playerName))
if (ObjectGuid guid = sCharacterCache->GetCharacterGuidByName(playerName))
{
return guid;
}

View File

@@ -16,6 +16,7 @@
*/
#include "AccountMgr.h"
#include "CharacterCache.h"
#include "DatabaseEnv.h"
#include "DBCStores.h"
#include "Item.h"
@@ -26,7 +27,6 @@
#include "Opcodes.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "World.h"
#include "WorldPacket.h"
#include "WorldSession.h"
@@ -122,7 +122,9 @@ void WorldSession::HandleSendMail(WorldPacket& recvData)
ObjectGuid receiverGuid;
if (normalizePlayerName(receiver))
receiverGuid = sObjectMgr->GetPlayerGUIDByName(receiver);
{
receiverGuid = sCharacterCache->GetCharacterGuidByName(receiver);
}
if (!receiverGuid)
{
@@ -178,10 +180,10 @@ void WorldSession::HandleSendMail(WorldPacket& recvData)
else
{
// xinef: get data from global storage
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(receiverGuid.GetCounter()))
if (CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(receiverGuid))
{
rc_teamId = Player::TeamIdForRace(playerData->race);
mails_count = playerData->mailCount;
rc_teamId = Player::TeamIdForRace(playerData->Race);
mails_count = playerData->MailCount;
}
}
//do not allow to have more than 100 mails in mailbox.. mails count is in opcode uint8!!! - so max can be 255..
@@ -207,7 +209,7 @@ void WorldSession::HandleSendMail(WorldPacket& recvData)
}
}*/
uint32 rc_account = receive ? receive->GetSession()->GetAccountId() : sObjectMgr->GetPlayerAccountIdByGUID(receiverGuid.GetCounter());
uint32 rc_account = receive ? receive->GetSession()->GetAccountId() : sCharacterCache->GetCharacterAccountIdByGuid(receiverGuid);
if (/*!accountBound*/ GetAccountId() != rc_account && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_MAIL) && player->GetTeamId() != rc_teamId && AccountMgr::IsPlayerAccount(GetSecurity()))
{
@@ -380,8 +382,8 @@ void WorldSession::HandleMailDelete(WorldPacket& recvData)
}
m->state = MAIL_STATE_DELETED;
// xinef: update global data
sWorld->UpdateGlobalPlayerMails(player->GetGUID().GetCounter(), -1);
sCharacterCache->DecreaseCharacterMailCount(player->GetGUID());
}
player->SendMailResult(mailId, MAIL_DELETED, MAIL_OK);
}
@@ -444,8 +446,7 @@ void WorldSession::HandleMailReturnToSender(WorldPacket& recvData)
delete m; //we can deallocate old mail
player->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_OK);
// xinef: update global data
sWorld->UpdateGlobalPlayerMails(player->GetGUID().GetCounter(), -1);
sCharacterCache->DecreaseCharacterMailCount(player->GetGUID());
}
//called when player takes item attached in mail
@@ -506,9 +507,13 @@ void WorldSession::HandleMailTakeItem(WorldPacket& recvData)
uint32 sender_accId = 0;
Player* sender = ObjectAccessor::FindPlayerByLowGUID(m->sender);
if (sender)
{
sender_accId = sender->GetSession()->GetAccountId();
}
else
sender_accId = sObjectMgr->GetPlayerAccountIdByGUID(m->sender);
{
sender_accId = sCharacterCache->GetCharacterAccountIdByGuid(ObjectGuid(HighGuid::Player, m->sender));
}
// check player existence
if (sender || sender_accId)
@@ -520,8 +525,10 @@ void WorldSession::HandleMailTakeItem(WorldPacket& recvData)
if( m->COD >= 10 * GOLD )
{
std::string senderName;
if (!sObjectMgr->GetPlayerNameByGUID(m->sender, senderName))
if (!sCharacterCache->GetCharacterNameByGuid(ObjectGuid(HighGuid::Player, m->sender), senderName))
{
senderName = sObjectMgr->GetAcoreStringForDBCLocale(LANG_UNKNOWN);
}
std::string subj = m->subject;
CleanStringForMysqlQuery(subj);
CharacterDatabase.PExecute("INSERT INTO log_money VALUES(%u, %u, \"%s\", \"%s\", %u, \"%s\", %u, \"<COD> %s\", NOW())",

View File

@@ -415,7 +415,7 @@ void WorldSession::HandlePetitionSignOpcode(WorldPacket& recvData)
return;
// not let enemies sign guild charter
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && GetPlayer()->GetTeamId() != sObjectMgr->GetPlayerTeamIdByGUID(petition->ownerGuid.GetCounter()))
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && GetPlayer()->GetTeamId() != sCharacterCache->GetCharacterTeamByGuid(petition->ownerGuid))
{
if (type != GUILD_CHARTER_TYPE)
SendArenaTeamCommandResult(ERR_ARENA_TEAM_INVITE_SS, "", "", ERR_ARENA_TEAM_NOT_ALLIED);

View File

@@ -29,7 +29,7 @@
void WorldSession::SendNameQueryOpcode(ObjectGuid guid)
{
GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid.GetCounter());
CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(guid);
WorldPacket data(SMSG_NAME_QUERY_RESPONSE, (8 + 1 + 1 + 1 + 1 + 1 + 10));
data << guid.WriteAsPacked();
@@ -43,11 +43,11 @@ void WorldSession::SendNameQueryOpcode(ObjectGuid guid)
Player* player = ObjectAccessor::FindConnectedPlayer(guid);
data << uint8(0); // name known
data << playerData->name; // played name
data << playerData->Name; // played name
data << uint8(0); // realm name - only set for cross realm interaction (such as Battlegrounds)
data << uint8(player ? player->getRace() : playerData->race);
data << uint8(playerData->gender);
data << uint8(playerData->playerClass);
data << uint8(player ? player->getRace() : playerData->Race);
data << uint8(playerData->Sex);
data << uint8(playerData->Class);
// pussywizard: optimization
/*Player* player = ObjectAccessor::FindConnectedPlayer(guid);

View File

@@ -51,17 +51,16 @@ void WorldSession::HandleAddFriendOpcode(WorldPacket& recv_data)
LOG_DEBUG("network", "WORLD: %s asked to add friend : '%s'", GetPlayer()->GetName().c_str(), friendName.c_str());
// xinef: Get Data From global storage
ObjectGuid friendGuid = sWorld->GetGlobalPlayerGUID(friendName);
ObjectGuid friendGuid = sCharacterCache->GetCharacterGuidByName(friendName);
if (!friendGuid)
return;
GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(friendGuid.GetCounter());
CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(friendGuid);
if (!playerData)
return;
uint32 friendAccountId = playerData->accountId;
TeamId teamId = Player::TeamIdForRace(playerData->race);
uint32 friendAccountId = playerData->AccountId;
TeamId teamId = Player::TeamIdForRace(playerData->Race);
FriendsResult friendResult = FRIEND_NOT_FOUND;
if (!AccountMgr::IsPlayerAccount(GetSecurity()) || sWorld->getBoolConfig(CONFIG_ALLOW_GM_FRIEND)|| AccountMgr::IsPlayerAccount(AccountMgr::GetSecurity(friendAccountId, realm.Id.Realm)))
@@ -118,7 +117,7 @@ void WorldSession::HandleAddIgnoreOpcode(WorldPacket& recv_data)
LOG_DEBUG("network", "WORLD: %s asked to Ignore: '%s'", GetPlayer()->GetName().c_str(), ignoreName.c_str());
ObjectGuid ignoreGuid = sWorld->GetGlobalPlayerGUID(ignoreName);
ObjectGuid ignoreGuid = sCharacterCache->GetCharacterGuidByName(ignoreName);
if (!ignoreGuid)
return;