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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
47 changed files with 898 additions and 595 deletions

View file

@ -0,0 +1,15 @@
INSERT INTO `version_db_world` (`sql_rev`) VALUES ('1636767869228265200');
DELETE FROM `command` WHERE `name` IN ('cache', 'cache info', 'cache delete', 'cache refresh');
INSERT INTO `command` (`name`, `security`, `help`) VALUES
('cache', 1, 'Character data cached during start up.\nType .cache to see a list of subcommands or .help $subcommand to see info on subcommands.'),
('cache info', 1, 'Syntax: .cache info $playerName\nDisplays cached data for the selected character.'),
('cache delete', 3, 'Syntax: .cache delete $playerName\nDeletes the cached data for the selected character. Use for debugging only!'),
('cache refresh', 1, 'Syntax: .cache refresh $playerName\nDeletes the current cache and refreshes it with updated data.');
DELETE FROM `acore_string` WHERE `entry` IN (5063, 5064, 5065, 5066);
INSERT INTO `acore_string` (`entry`, `content_default`) VALUES
(5063, 'Displaying cached info for character: \n|- Name: %s (Guid: %u) \n|- Account: %u \n|- Class: %u \n|- Race: %u \n|- Gender: %u \n|- Level: %u \n|- Mail Count: %u \n|- Guild: %u \n|- Group ID: %u \n|- ArenaTeam 2x2: %u \n|- ArenaTeam 3x3: %u \n|- ArenaTeam 5x5: %u'),
(5064, 'Cached data for character %s (%u) has been cleared.'),
(5065, 'Cached data for character %s (%u) has been refreshed.'),
(5066, 'Cache not found for character %s');

View file

@ -297,9 +297,13 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, CharacterDatabas
uint32 bidder_accId = 0;
Player* bidder = ObjectAccessor::FindConnectedPlayer(auction->bidder);
if (bidder)
{
bidder_accId = bidder->GetSession()->GetAccountId();
}
else
bidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->bidder.GetCounter());
{
bidder_accId = sCharacterCache->GetCharacterAccountIdByGuid(auction->bidder);
}
// receiver exist
if (bidder || bidder_accId)
@ -333,7 +337,7 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, CharacterDatabas
void AuctionHouseMgr::SendAuctionSalePendingMail(AuctionEntry* auction, CharacterDatabaseTransaction trans, bool sendMail)
{
Player* owner = ObjectAccessor::FindConnectedPlayer(auction->owner);
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->owner.GetCounter());
uint32 owner_accId = sCharacterCache->GetCharacterAccountIdByGuid(auction->owner);
// owner exist (online or offline)
if (owner || owner_accId)
{
@ -355,7 +359,7 @@ void AuctionHouseMgr::SendAuctionSalePendingMail(AuctionEntry* auction, Characte
void AuctionHouseMgr::SendAuctionSuccessfulMail(AuctionEntry* auction, CharacterDatabaseTransaction trans, bool sendNotification, bool updateAchievementCriteria, bool sendMail)
{
Player* owner = ObjectAccessor::FindConnectedPlayer(auction->owner);
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->owner.GetCounter());
uint32 owner_accId = sCharacterCache->GetCharacterAccountIdByGuid(auction->owner);
// owner exist
if (owner || owner_accId)
{
@ -380,18 +384,18 @@ void AuctionHouseMgr::SendAuctionSuccessfulMail(AuctionEntry* auction, Character
.SendMailTo(trans, MailReceiver(owner, auction->owner.GetCounter()), auction, MAIL_CHECK_MASK_COPIED, sWorld->getIntConfig(CONFIG_MAIL_DELIVERY_DELAY), 0, false, true, auction->Id);
if (auction->bid >= 500 * GOLD)
if (const GlobalPlayerData* gpd = sWorld->GetGlobalPlayerData(auction->bidder.GetCounter()))
if (CharacterCacheEntry const* gpd = sCharacterCache->GetCharacterCacheByGuid(auction->bidder))
{
Player* bidder = ObjectAccessor::FindConnectedPlayer(auction->bidder);
std::string owner_name = "";
uint8 owner_level = 0;
if (const GlobalPlayerData* gpd_owner = sWorld->GetGlobalPlayerData(auction->owner.GetCounter()))
if (CharacterCacheEntry const* gpd_owner = sCharacterCache->GetCharacterCacheByGuid(auction->owner))
{
owner_name = gpd_owner->name;
owner_level = gpd_owner->level;
owner_name = gpd_owner->Name;
owner_level = gpd_owner->Level;
}
CharacterDatabase.PExecute("INSERT INTO log_money VALUES(%u, %u, \"%s\", \"%s\", %u, \"%s\", %u, \"<AH> profit: %ug, bidder: %s %u lvl (guid: %u), seller: %s %u lvl (guid: %u), item %u (%u)\", NOW())",
gpd->accountId, auction->bidder.GetCounter(), gpd->name.c_str(), bidder ? bidder->GetSession()->GetRemoteAddress().c_str() : "", owner_accId, owner_name.c_str(), auction->bid, (profit / GOLD), gpd->name.c_str(), gpd->level, auction->bidder.GetCounter(), owner_name.c_str(), owner_level, auction->owner.GetCounter(), auction->item_template, auction->itemCount);
gpd->AccountId, auction->bidder.GetCounter(), gpd->Name.c_str(), bidder ? bidder->GetSession()->GetRemoteAddress().c_str() : "", owner_accId, owner_name.c_str(), auction->bid, (profit / GOLD), gpd->Name.c_str(), gpd->Level, auction->bidder.GetCounter(), owner_name.c_str(), owner_level, auction->owner.GetCounter(), auction->item_template, auction->itemCount);
}
}
}
@ -405,7 +409,7 @@ void AuctionHouseMgr::SendAuctionExpiredMail(AuctionEntry* auction, CharacterDat
return;
Player* owner = ObjectAccessor::FindConnectedPlayer(auction->owner);
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->owner.GetCounter());
uint32 owner_accId = sCharacterCache->GetCharacterAccountIdByGuid(auction->owner);
// owner exist
if (owner || owner_accId)
@ -431,7 +435,7 @@ void AuctionHouseMgr::SendAuctionOutbiddedMail(AuctionEntry* auction, uint32 new
uint32 oldBidder_accId = 0;
if (!oldBidder)
oldBidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->bidder.GetCounter());
oldBidder_accId = sCharacterCache->GetCharacterAccountIdByGuid(auction->bidder);
// old bidder exist
if (oldBidder || oldBidder_accId)
@ -455,7 +459,9 @@ void AuctionHouseMgr::SendAuctionCancelledToBidderMail(AuctionEntry* auction, Ch
uint32 bidder_accId = 0;
if (!bidder)
bidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->bidder.GetCounter());
{
bidder_accId = sCharacterCache->GetCharacterAccountIdByGuid(auction->bidder);
}
// bidder exist
if (bidder || bidder_accId)

View file

@ -18,6 +18,7 @@
#include "ArenaTeam.h"
#include "ArenaTeamMgr.h"
#include "BattlegroundMgr.h"
#include "CharacterCache.h"
#include "Group.h"
#include "ObjectMgr.h"
#include "Opcodes.h"
@ -103,19 +104,21 @@ bool ArenaTeam::AddMember(ObjectGuid playerGuid)
}
else
{
GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(playerGuid.GetCounter());
CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(playerGuid);
if (!playerData)
{
return false;
}
playerName = playerData->name;
playerClass = playerData->playerClass;
playerName = playerData->Name;
playerClass = playerData->Class;
}
if (!sScriptMgr->CanAddMember(this, playerGuid))
return false;
// Check if player is already in a similar arena team
if ((player && player->GetArenaTeamId(GetSlot())) || Player::GetArenaTeamIdFromStorage(playerGuid.GetCounter(), GetSlot()) != 0)
if ((player && player->GetArenaTeamId(GetSlot())) || sCharacterCache->GetCharacterArenaTeamIdByGuid(playerGuid, GetSlot()) != 0)
{
LOG_ERROR("bg.arena", "Arena: Player %s (%s) already has an arena team of type %u", playerName.c_str(), playerGuid.ToString().c_str(), GetType());
return false;
@ -168,7 +171,7 @@ bool ArenaTeam::AddMember(ObjectGuid playerGuid)
newMember.MaxMMR = maxMMR;
Members.push_back(newMember);
sWorld->UpdateGlobalPlayerArenaTeam(playerGuid.GetCounter(), GetSlot(), GetId());
sCharacterCache->UpdateCharacterArenaTeamId(playerGuid, GetSlot(), GetId());
// Save player's arena team membership to db
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ARENA_TEAM_MEMBER);
@ -263,7 +266,7 @@ bool ArenaTeam::LoadMembersFromDB(QueryResult result)
// Put the player in the team
Members.push_back(newMember);
sWorld->UpdateGlobalPlayerArenaTeam(newMember.Guid.GetCounter(), GetSlot(), GetId());
sCharacterCache->UpdateCharacterArenaTeamId(newMember.Guid, GetSlot(), GetId());
} while (result->NextRow());
if (Empty() || !captainPresentInTeam)
@ -353,7 +356,7 @@ void ArenaTeam::DelMember(ObjectGuid guid, bool cleanDb)
if (itr->Guid == guid)
{
Members.erase(itr);
sWorld->UpdateGlobalPlayerArenaTeam(guid.GetCounter(), GetSlot(), 0);
sCharacterCache->UpdateCharacterArenaTeamId(guid, GetSlot(), 0);
break;
}
}
@ -449,7 +452,7 @@ void ArenaTeam::Roster(WorldSession* session)
data << itr->Guid; // guid
data << uint8((player ? 1 : 0)); // online flag
tempName = "";
sObjectMgr->GetPlayerNameByGUID(itr->Guid.GetCounter(), tempName);
sCharacterCache->GetCharacterNameByGuid(itr->Guid, tempName);
data << tempName; // member name
data << uint32((itr->Guid == GetCaptain() ? 0 : 1));// captain flag 0 captain 1 member
data << uint8((player ? player->getLevel() : 0)); // unknown, level?
@ -993,7 +996,7 @@ bool ArenaTeam::IsFighting() const
ArenaTeamMember* ArenaTeam::GetMember(const std::string& name)
{
return GetMember(sObjectMgr->GetPlayerGUIDByName(name));
return GetMember(sCharacterCache->GetCharacterGuidByName(name));
}
ArenaTeamMember* ArenaTeam::GetMember(ObjectGuid guid)

View file

@ -0,0 +1,383 @@
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CharacterCache.h"
#include "ArenaTeam.h"
#include "DatabaseEnv.h"
#include "Log.h"
#include "Player.h"
#include "Timer.h"
#include "World.h"
#include "WorldPacket.h"
#include <unordered_map>
namespace
{
std::unordered_map<ObjectGuid, CharacterCacheEntry> _characterCacheStore;
std::unordered_map<std::string, CharacterCacheEntry*> _characterCacheByNameStore;
}
CharacterCache* CharacterCache::instance()
{
static CharacterCache instance;
return &instance;
}
/**
* @brief Loads several pieces of information on server startup with the GUID
* There is no further database query necessary.
* These are a number of methods that work into the calling function.
*
* @param guid Requires a guid to call
* @return Name, Gender, Race, Class and Level of player character
* Example Usage:
* @code
* CharacterCacheEntry const* characterInfo = sCharacterCache->GetCharacterCacheByGuid(GUID);
* if (!characterInfo)
* return;
*
* std::string playerName = characterInfo->Name;
* uint8 playerGender = characterInfo->Sex;
* uint8 playerRace = characterInfo->Race;
* uint8 playerClass = characterInfo->Class;
* uint8 playerLevel = characterInfo->Level;
* @endcode
**/
void CharacterCache::LoadCharacterCacheStorage()
{
_characterCacheStore.clear();
uint32 oldMSTime = getMSTime();
QueryResult result = CharacterDatabase.Query("SELECT guid, name, account, race, gender, class, level FROM characters");
if (!result)
{
LOG_INFO("server.loading", "No character name data loaded, empty query!");
return;
}
do
{
Field* fields = result->Fetch();
AddCharacterCacheEntry(ObjectGuid::Create<HighGuid::Player>(fields[0].GetUInt32()) /*guid*/, fields[2].GetUInt32() /*account*/, fields[1].GetString() /*name*/,
fields[4].GetUInt8() /*gender*/, fields[3].GetUInt8() /*race*/, fields[5].GetUInt8() /*class*/, fields[6].GetUInt8() /*level*/);
} while (result->NextRow());
QueryResult mailCountResult = CharacterDatabase.Query("SELECT receiver, COUNT(receiver) FROM mail GROUP BY receiver");
if (mailCountResult)
{
do
{
Field* fields = mailCountResult->Fetch();
UpdateCharacterMailCount(ObjectGuid(HighGuid::Player, fields[0].GetUInt32()), static_cast<int8>(fields[1].GetUInt64()), true);
} while (mailCountResult->NextRow());
}
LOG_INFO("server.loading", "Loaded character infos for " SZFMTD " characters in %u ms", _characterCacheStore.size(), GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", " ");
}
void CharacterCache::RefreshCacheEntry(uint32 lowGuid)
{
QueryResult result = CharacterDatabase.PQuery("SELECT guid, name, account, race, gender, class, level FROM characters WHERE guid = %u", lowGuid);
if (!result)
{
return;
}
do
{
Field* fields = result->Fetch();
DeleteCharacterCacheEntry(ObjectGuid::Create<HighGuid::Player>(lowGuid), fields[1].GetString());
AddCharacterCacheEntry(ObjectGuid::Create<HighGuid::Player>(fields[0].GetUInt32()) /*guid*/, fields[2].GetUInt32() /*account*/, fields[1].GetString() /*name*/, fields[4].GetUInt8() /*gender*/, fields[3].GetUInt8() /*race*/, fields[5].GetUInt8() /*class*/, fields[6].GetUInt8() /*level*/);
} while (result->NextRow());
QueryResult mailCountResult = CharacterDatabase.PQuery("SELECT receiver, COUNT(receiver) FROM mail WHERE receiver = %u GROUP BY receiver", lowGuid);
if (mailCountResult)
{
do
{
Field* fields = mailCountResult->Fetch();
UpdateCharacterMailCount(ObjectGuid(HighGuid::Player, fields[0].GetUInt32()), static_cast<int8>(fields[1].GetUInt64()), true);
} while (mailCountResult->NextRow());
}
}
/*
Modifying functions
*/
void CharacterCache::AddCharacterCacheEntry(ObjectGuid const& guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level)
{
CharacterCacheEntry& data = _characterCacheStore[guid];
data.Guid = guid;
data.Name = name;
data.AccountId = accountId;
data.Race = race;
data.Sex = gender;
data.Class = playerClass;
data.Level = level;
data.GuildId = 0; // Will be set in guild loading or guild setting
for (uint8 i = 0; i < MAX_ARENA_SLOT; ++i)
{
data.ArenaTeamId[i] = 0; // Will be set in arena teams loading
}
// Fill Name to Guid Store
_characterCacheByNameStore[name] = &data;
}
void CharacterCache::DeleteCharacterCacheEntry(ObjectGuid const& guid, std::string const& name)
{
_characterCacheStore.erase(guid);
_characterCacheByNameStore.erase(name);
}
void CharacterCache::UpdateCharacterData(ObjectGuid const& guid, std::string const& name, Optional<uint8> gender /*= {}*/, Optional<uint8> race /*= {}*/)
{
auto itr = _characterCacheStore.find(guid);
if (itr == _characterCacheStore.end())
return;
std::string oldName = itr->second.Name;
itr->second.Name = name;
if (gender)
{
itr->second.Sex = *gender;
}
if (race)
{
itr->second.Race = *race;
}
//WorldPackets::Misc::InvalidatePlayer packet(guid);
//sWorld->SendGlobalMessage(packet.Write());
// Correct name -> pointer storage
_characterCacheByNameStore.erase(oldName);
_characterCacheByNameStore[name] = &itr->second;
}
void CharacterCache::UpdateCharacterLevel(ObjectGuid const& guid, uint8 level)
{
auto itr = _characterCacheStore.find(guid);
if (itr == _characterCacheStore.end())
{
return;
}
itr->second.Level = level;
}
void CharacterCache::UpdateCharacterAccountId(ObjectGuid const& guid, uint32 accountId)
{
auto itr = _characterCacheStore.find(guid);
if (itr == _characterCacheStore.end())
{
return;
}
itr->second.AccountId = accountId;
}
void CharacterCache::UpdateCharacterGuildId(ObjectGuid const& guid, ObjectGuid::LowType guildId)
{
auto itr = _characterCacheStore.find(guid);
if (itr == _characterCacheStore.end())
{
return;
}
itr->second.GuildId = guildId;
}
void CharacterCache::UpdateCharacterArenaTeamId(ObjectGuid const& guid, uint8 slot, uint32 arenaTeamId)
{
auto itr = _characterCacheStore.find(guid);
if (itr == _characterCacheStore.end())
{
return;
}
ASSERT(slot < 3);
itr->second.ArenaTeamId[slot] = arenaTeamId;
}
void CharacterCache::UpdateCharacterMailCount(ObjectGuid const& guid, int8 count, bool update)
{
auto itr = _characterCacheStore.find(guid);
if (itr == _characterCacheStore.end())
{
return;
}
if (update)
{
itr->second.MailCount = count;
return;
}
// Let's be safe and prevent overflow
if (!itr->second.MailCount && count < 0)
{
return;
}
itr->second.MailCount += count;
}
void CharacterCache::UpdateCharacterGroup(ObjectGuid const& guid, ObjectGuid groupGUID)
{
auto itr = _characterCacheStore.find(guid);
if (itr == _characterCacheStore.end())
{
return;
}
itr->second.GroupGuid = groupGUID;
}
/*
Getters
*/
bool CharacterCache::HasCharacterCacheEntry(ObjectGuid const& guid) const
{
return _characterCacheStore.find(guid) != _characterCacheStore.end();
}
CharacterCacheEntry const* CharacterCache::GetCharacterCacheByGuid(ObjectGuid const& guid) const
{
auto itr = _characterCacheStore.find(guid);
if (itr != _characterCacheStore.end())
{
return &itr->second;
}
return nullptr;
}
CharacterCacheEntry const* CharacterCache::GetCharacterCacheByName(std::string const& name) const
{
auto itr = _characterCacheByNameStore.find(name);
if (itr != _characterCacheByNameStore.end())
{
return itr->second;
}
return nullptr;
}
ObjectGuid CharacterCache::GetCharacterGuidByName(std::string const& name) const
{
auto itr = _characterCacheByNameStore.find(name);
if (itr != _characterCacheByNameStore.end())
{
return itr->second->Guid;
}
return ObjectGuid::Empty;
}
bool CharacterCache::GetCharacterNameByGuid(ObjectGuid guid, std::string& name) const
{
auto itr = _characterCacheStore.find(guid);
if (itr == _characterCacheStore.end())
{
return false;
}
name = itr->second.Name;
return true;
}
uint32 CharacterCache::GetCharacterTeamByGuid(ObjectGuid guid) const
{
auto itr = _characterCacheStore.find(guid);
if (itr == _characterCacheStore.end())
{
return 0;
}
return Player::TeamIdForRace(itr->second.Race);
}
uint32 CharacterCache::GetCharacterAccountIdByGuid(ObjectGuid guid) const
{
auto itr = _characterCacheStore.find(guid);
if (itr == _characterCacheStore.end())
{
return 0;
}
return itr->second.AccountId;
}
uint32 CharacterCache::GetCharacterAccountIdByName(std::string const& name) const
{
auto itr = _characterCacheByNameStore.find(name);
if (itr != _characterCacheByNameStore.end())
{
return itr->second->AccountId;
}
return 0;
}
uint8 CharacterCache::GetCharacterLevelByGuid(ObjectGuid guid) const
{
auto itr = _characterCacheStore.find(guid);
if (itr == _characterCacheStore.end())
{
return 0;
}
return itr->second.Level;
}
ObjectGuid::LowType CharacterCache::GetCharacterGuildIdByGuid(ObjectGuid guid) const
{
auto itr = _characterCacheStore.find(guid);
if (itr == _characterCacheStore.end())
{
return 0;
}
return itr->second.GuildId;
}
uint32 CharacterCache::GetCharacterArenaTeamIdByGuid(ObjectGuid guid, uint8 type) const
{
auto itr = _characterCacheStore.find(guid);
if (itr == _characterCacheStore.end())
{
return 0;
}
return itr->second.ArenaTeamId[type];
}
ObjectGuid CharacterCache::GetCharacterGroupGuidByGuid(ObjectGuid guid) const
{
auto itr = _characterCacheStore.find(guid);
if (itr == _characterCacheStore.end())
{
return ObjectGuid::Empty;
}
return itr->second.GroupGuid;
}

View file

@ -0,0 +1,85 @@
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CharacterCache_h__
#define CharacterCache_h__
#include "ArenaTeam.h"
#include "Define.h"
#include "ObjectGuid.h"
#include "Optional.h"
#include <string>
struct CharacterCacheEntry
{
ObjectGuid Guid;
std::string Name;
uint32 AccountId;
uint8 Class;
uint8 Race;
uint8 Sex;
uint8 Level;
uint8 MailCount;
ObjectGuid::LowType GuildId;
std::array<uint32, MAX_ARENA_SLOT> ArenaTeamId;
ObjectGuid GroupGuid;
};
class AC_GAME_API CharacterCache
{
public:
CharacterCache() noexcept = default;
~CharacterCache() noexcept = default;
static CharacterCache* instance();
void LoadCharacterCacheStorage();
void RefreshCacheEntry(uint32 lowGuid);
void AddCharacterCacheEntry(ObjectGuid const& guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level);
void DeleteCharacterCacheEntry(ObjectGuid const& guid, std::string const& name);
void UpdateCharacterData(ObjectGuid const& guid, std::string const& name, Optional<uint8> gender = {}, Optional<uint8> race = {});
void UpdateCharacterLevel(ObjectGuid const& guid, uint8 level);
void UpdateCharacterAccountId(ObjectGuid const& guid, uint32 accountId);
void UpdateCharacterGuildId(ObjectGuid const& guid, ObjectGuid::LowType guildId);
void UpdateCharacterArenaTeamId(ObjectGuid const& guid, uint8 slot, uint32 arenaTeamId);
void UpdateCharacterMailCount(ObjectGuid const& guid, int8 count, bool update = false);
void DecreaseCharacterMailCount(ObjectGuid const& guid) { UpdateCharacterMailCount(guid, -1); };
void IncreaseCharacterMailCount(ObjectGuid const& guid) { UpdateCharacterMailCount(guid, 1); };
bool HasCharacterCacheEntry(ObjectGuid const& guid) const;
CharacterCacheEntry const* GetCharacterCacheByGuid(ObjectGuid const& guid) const;
CharacterCacheEntry const* GetCharacterCacheByName(std::string const& name) const;
void UpdateCharacterGroup(ObjectGuid const& guid, ObjectGuid groupGUID);
void ClearCharacterGroup(ObjectGuid const& guid) { UpdateCharacterGroup(guid, ObjectGuid::Empty); };
ObjectGuid GetCharacterGuidByName(std::string const& name) const;
bool GetCharacterNameByGuid(ObjectGuid guid, std::string& name) const;
uint32 GetCharacterTeamByGuid(ObjectGuid guid) const;
uint32 GetCharacterAccountIdByGuid(ObjectGuid guid) const;
uint32 GetCharacterAccountIdByName(std::string const& name) const;
uint8 GetCharacterLevelByGuid(ObjectGuid guid) const;
ObjectGuid::LowType GetCharacterGuildIdByGuid(ObjectGuid guid) const;
uint32 GetCharacterArenaTeamIdByGuid(ObjectGuid guid, uint8 type) const;
ObjectGuid GetCharacterGroupGuidByGuid(ObjectGuid guid) const;
};
#define sCharacterCache CharacterCache::instance()
#endif // CharacterCache_h__

View file

@ -78,7 +78,9 @@ void CalendarMgr::LoadFromDB()
uint32 guildId = 0;
if (flags & CALENDAR_FLAG_GUILD_EVENT || flags & CALENDAR_FLAG_WITHOUT_INVITES)
guildId = Player::GetGuildIdFromStorage(creatorGUID.GetCounter());
{
guildId = sCharacterCache->GetCharacterGuildIdByGuid(creatorGUID);
}
CalendarEvent* calendarEvent = new CalendarEvent(eventId, creatorGUID, guildId, type, dungeonId, time_t(eventTime), flags, time_t(timezoneTime), title, description);
_events.insert(calendarEvent);
@ -479,7 +481,7 @@ void CalendarMgr::SendCalendarEventInvite(CalendarInvite const& invite)
ObjectGuid invitee = invite.GetInviteeGUID();
Player* player = ObjectAccessor::FindConnectedPlayer(invitee);
uint8 level = player ? player->getLevel() : Player::GetLevelFromStorage(invitee.GetCounter());
uint8 level = player ? player->getLevel() : sCharacterCache->GetCharacterLevelByGuid(invitee);
WorldPacket data(SMSG_CALENDAR_EVENT_INVITE, 8 + 8 + 8 + 1 + 1 + 1 + (statusTime ? 4 : 0) + 1);
data << invitee.WriteAsPacked();
@ -624,8 +626,8 @@ void CalendarMgr::SendCalendarEvent(ObjectGuid guid, CalendarEvent const& calend
ObjectGuid inviteeGuid = calendarInvite->GetInviteeGUID();
Player* invitee = ObjectAccessor::FindConnectedPlayer(inviteeGuid);
uint8 inviteeLevel = invitee ? invitee->getLevel() : Player::GetLevelFromStorage(inviteeGuid.GetCounter());
uint32 inviteeGuildId = invitee ? invitee->GetGuildId() : Player::GetGuildIdFromStorage(inviteeGuid.GetCounter());
uint8 inviteeLevel = invitee ? invitee->getLevel() : sCharacterCache->GetCharacterLevelByGuid(inviteeGuid);
uint32 inviteeGuildId = invitee ? invitee->GetGuildId() : sCharacterCache->GetCharacterGuildIdByGuid(inviteeGuid);
data << inviteeGuid.WriteAsPacked();
data << uint8(inviteeLevel);

View file

@ -17,6 +17,7 @@
#include "AccountMgr.h"
#include "ChannelMgr.h"
#include "CharacterCache.h"
#include "Chat.h"
#include "DatabaseEnv.h"
#include "ObjectMgr.h"
@ -356,14 +357,15 @@ void Channel::KickOrBan(Player const* player, std::string const& badname, bool b
{
if (ban && (AccountMgr::IsGMAccount(sec) || isGoodConstantModerator))
{
if (ObjectGuid guid = sWorld->GetGlobalPlayerGUID(badname))
if (const GlobalPlayerData* gpd = sWorld->GetGlobalPlayerData(guid.GetCounter()))
if (ObjectGuid guid = sCharacterCache->GetCharacterGuidByName(badname))
{
if (CharacterCacheEntry const* gpd = sCharacterCache->GetCharacterCacheByGuid(guid))
{
if (Player::TeamIdForRace(gpd->race) == Player::TeamIdForRace(player->getRace()))
if (Player::TeamIdForRace(gpd->Race) == Player::TeamIdForRace(player->getRace()))
{
banOffline = true;
victim = guid;
badAccId = gpd->accountId;
victim = guid;
badAccId = gpd->AccountId;
}
else
{
@ -371,6 +373,7 @@ void Channel::KickOrBan(Player const* player, std::string const& badname, bool b
return;
}
}
}
if (!banOffline)
{
@ -493,8 +496,10 @@ void Channel::UnBan(Player const* player, std::string const& badname)
}
ObjectGuid victim;
if (ObjectGuid guid = sWorld->GetGlobalPlayerGUID(badname))
if (ObjectGuid guid = sCharacterCache->GetCharacterGuidByName(badname))
{
victim = guid;
}
if (!victim || !IsBanned(victim))
{
@ -1042,7 +1047,7 @@ void Channel::MakeChannelOwner(WorldPacket* data)
{
std::string name = "";
if (!sObjectMgr->GetPlayerNameByGUID(_ownerGUID.GetCounter(), name) || name.empty())
if (!sCharacterCache->GetCharacterNameByGuid(_ownerGUID, name) || name.empty())
name = "PLAYER_NOT_FOUND";
MakeNotifyPacket(data, CHAT_CHANNEL_OWNER_NOTICE);

View file

@ -63,7 +63,7 @@ bool ChatHandler::HasLowerSecurity(Player* target, ObjectGuid guid, bool strong)
if (target)
target_session = target->GetSession();
else if (guid)
target_account = sObjectMgr->GetPlayerAccountIdByGUID(guid.GetCounter());
target_account = sCharacterCache->GetCharacterAccountIdByGuid(guid);
if (!target_session && !target_account)
{
@ -633,7 +633,7 @@ ObjectGuid::LowType ChatHandler::extractLowGuidFromLink(char* text, HighGuid& gu
if (Player* player = ObjectAccessor::FindPlayerByName(name, false))
return player->GetGUID().GetCounter();
if (ObjectGuid guid = sObjectMgr->GetPlayerGUIDByName(name))
if (ObjectGuid guid = sCharacterCache->GetCharacterGuidByName(name))
return guid.GetCounter();
return 0;
@ -699,7 +699,7 @@ bool ChatHandler::extractPlayerTarget(char* args, Player** player, ObjectGuid* p
*player = pl;
// if need guid value from DB (in name case for check player existence)
ObjectGuid guid = !pl && (player_guid || player_name) ? sObjectMgr->GetPlayerGUIDByName(name) : ObjectGuid::Empty;
ObjectGuid guid = !pl && (player_guid || player_name) ? sCharacterCache->GetCharacterGuidByName(name) : ObjectGuid::Empty;
// if allowed player guid (if no then only online players allowed)
if (player_guid)
@ -851,7 +851,9 @@ bool ChatHandler::GetPlayerGroupAndGUIDByName(const char* cname, Player*& player
player = ObjectAccessor::FindPlayerByName(name, false);
if (offline)
guid = sObjectMgr->GetPlayerGUIDByName(name.c_str());
{
guid = sCharacterCache->GetCharacterGuidByName(name);
}
}
}

View file

@ -99,9 +99,13 @@ ChatCommandResult Acore::ChatCommands::PlayerIdentifier::TryConsume(ChatHandler
_guid = ObjectGuid::Create<HighGuid::Player>(val.get<ObjectGuid::LowType>());
if ((_player = ObjectAccessor::FindPlayerByLowGUID(_guid.GetCounter())))
{
_name = _player->GetName();
else if (!sObjectMgr->GetPlayerNameByGUID(_guid.GetCounter(), _name))
}
else if (!sCharacterCache->GetCharacterNameByGuid(_guid, _name))
{
return FormatAcoreString(handler, LANG_CMDPARSER_CHAR_GUID_NO_EXIST, _guid.ToString().c_str());
}
return next;
}
@ -116,9 +120,13 @@ ChatCommandResult Acore::ChatCommands::PlayerIdentifier::TryConsume(ChatHandler
return FormatAcoreString(handler, LANG_CMDPARSER_CHAR_NAME_INVALID, STRING_VIEW_FMT_ARG(_name));
if ((_player = ObjectAccessor::FindPlayerByName(_name)))
{
_guid = _player->GetGUID();
else if (!(_guid = sObjectMgr->GetPlayerGUIDByName(_name)))
}
else if (!(_guid = sCharacterCache->GetCharacterGuidByName(_name)))
{
return FormatAcoreString(handler, LANG_CMDPARSER_CHAR_NAME_NO_EXIST, STRING_VIEW_FMT_ARG(_name));
}
return next;
}

View file

@ -15,6 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CharacterCache.h"
#include "Common.h"
#include "DBCStores.h"
#include "DisableMgr.h"
@ -1060,11 +1061,11 @@ namespace lfg
talents[0] = 0;
talents[1] = 0;
talents[2] = 0;
if (const GlobalPlayerData* gpd = sWorld->GetGlobalPlayerData(mitr->guid.GetCounter()))
if (CharacterCacheEntry const* gpd = sCharacterCache->GetCharacterCacheByGuid(mitr->guid))
{
level = gpd->level;
Class = gpd->playerClass;
race = gpd->race;
level = gpd->Level;
Class = gpd->Class;
race = gpd->Race;
}
Player* mplr = ObjectAccessor::FindConnectedPlayer(guid);
if (mplr)

View file

@ -15,6 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CharacterCache.h"
#include "Common.h"
#include "Corpse.h"
#include "DatabaseEnv.h"
@ -179,7 +180,7 @@ bool Corpse::LoadCorpseFromDB(ObjectGuid::LowType guid, Field* fields)
bool Corpse::IsExpired(time_t t) const
{
// Deleted character
if (!sWorld->GetGlobalPlayerData(GetOwnerGUID().GetCounter()))
if (!sCharacterCache->GetCharacterCacheByGuid(GetOwnerGUID()))
return true;
if (m_type == CORPSE_BONES)

View file

@ -29,6 +29,7 @@
#include "CellImpl.h"
#include "Channel.h"
#include "ChannelMgr.h"
#include "CharacterCache.h"
#include "CharacterDatabaseCleaner.h"
#include "Chat.h"
#include "Config.h"
@ -2785,8 +2786,6 @@ void Player::SendNewMail()
void Player::AddNewMailDeliverTime(time_t deliver_time)
{
sWorld->UpdateGlobalPlayerMails(GetGUID().GetCounter(), GetMailSize(), false);
if (deliver_time <= time(nullptr)) // ready now
{
++unReadMails;
@ -3876,10 +3875,10 @@ void Player::DeleteFromDB(ObjectGuid::LowType lowGuid, uint32 accountId, bool up
// if we want to finally delete the character or the character does not meet the level requirement,
// we set it to mode CHAR_DELETE_REMOVE
if (deleteFinally || Player::GetLevelFromStorage(lowGuid) < charDelete_minLvl)
if (deleteFinally || sCharacterCache->GetCharacterLevelByGuid(playerGuid) < charDelete_minLvl)
charDelete_method = CHAR_DELETE_REMOVE;
if (uint32 guildId = GetGuildIdFromStorage(lowGuid))
if (uint32 guildId = sCharacterCache->GetCharacterGuildIdByGuid(playerGuid))
if (Guild* guild = sGuildMgr->GetGuildById(guildId))
guild->DeleteMember(playerGuid, false, false, true);
@ -3892,7 +3891,7 @@ void Player::DeleteFromDB(ObjectGuid::LowType lowGuid, uint32 accountId, bool up
sTicketMgr->CloseTicket(ticket->GetId(), playerGuid);
// remove from group
if (uint32 groupId = GetGroupIdFromStorage(lowGuid))
if (uint32 groupId = sCharacterCache->GetCharacterGuildIdByGuid(playerGuid))
if (Group* group = sGroupMgr->GetGroupByGUID(groupId))
RemoveFromGroup(group, playerGuid);
@ -3984,7 +3983,7 @@ void Player::DeleteFromDB(ObjectGuid::LowType lowGuid, uint32 accountId, bool up
stmt->setUInt32(0, mail_id);
trans->Append(stmt);
uint32 pl_account = sObjectMgr->GetPlayerAccountIdByGUID(lowGuid);
uint32 pl_account = sCharacterCache->GetCharacterAccountIdByGuid(ObjectGuid(HighGuid::Player, lowGuid));
draft.AddMoney(money).SendReturnToSender(pl_account, lowGuid, sender, trans);
} while (resultMail->NextRow());
@ -6086,33 +6085,6 @@ void Player::ModifyArenaPoints(int32 value, CharacterDatabaseTransaction trans)
}
}
uint32 Player::GetGuildIdFromStorage(ObjectGuid::LowType guid)
{
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid))
return playerData->guildId;
return 0;
}
uint32 Player::GetGroupIdFromStorage(ObjectGuid::LowType guid)
{
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid))
return playerData->groupId;
return 0;
}
uint32 Player::GetArenaTeamIdFromStorage(ObjectGuid::LowType guid, uint8 slot)
{
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid))
{
auto itr = playerData->arenaTeamId.find(slot);
if (itr != playerData->arenaTeamId.end())
{
return itr->second;
}
}
return 0;
}
uint32 Player::GetArenaTeamIdFromDB(ObjectGuid guid, uint8 type)
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_ARENA_TEAM_ID_BY_PLAYER_GUID);
@ -6178,15 +6150,6 @@ uint32 Player::GetZoneIdFromDB(ObjectGuid guid)
return zone;
}
uint32 Player::GetLevelFromStorage(ObjectGuid::LowType guid)
{
// xinef: Get data from global storage
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid))
return playerData->level;
return 0;
}
//If players are too far away from the duel flag... they lose the duel
void Player::CheckDuelDistance(time_t currTime)
{

View file

@ -20,6 +20,7 @@
#include "ArenaTeam.h"
#include "Battleground.h"
#include "CharacterCache.h"
#include "DatabaseEnvFwd.h"
#include "DBCStores.h"
#include "GroupReference.h"
@ -1500,7 +1501,6 @@ public:
static uint32 GetUInt32ValueFromArray(Tokenizer const& data, uint16 index);
static float GetFloatValueFromArray(Tokenizer const& data, uint16 index);
static uint32 GetZoneIdFromDB(ObjectGuid guid);
static uint32 GetLevelFromStorage(ObjectGuid::LowType guid);
static bool LoadPositionFromDB(uint32& mapid, float& x, float& y, float& z, float& o, bool& in_flight, ObjectGuid::LowType guid);
static bool IsValidGender(uint8 Gender) { return Gender <= GENDER_FEMALE; }
@ -1832,16 +1832,13 @@ public:
{
SetUInt32Value(PLAYER_GUILDID, GuildId);
// xinef: update global storage
sWorld->UpdateGlobalPlayerGuild(GetGUID().GetCounter(), GuildId);
sCharacterCache->UpdateCharacterGuildId(GetGUID(), GetGuildId());
}
void SetRank(uint8 rankId) { SetUInt32Value(PLAYER_GUILDRANK, rankId); }
[[nodiscard]] uint8 GetRank() const { return uint8(GetUInt32Value(PLAYER_GUILDRANK)); }
void SetGuildIdInvited(uint32 GuildId) { m_GuildIdInvited = GuildId; }
[[nodiscard]] uint32 GetGuildId() const { return GetUInt32Value(PLAYER_GUILDID); }
[[nodiscard]] Guild* GetGuild() const;
static uint32 GetGuildIdFromStorage(ObjectGuid::LowType guid);
static uint32 GetGroupIdFromStorage(ObjectGuid::LowType guid);
static uint32 GetArenaTeamIdFromStorage(ObjectGuid::LowType guid, uint8 slot);
uint32 GetGuildIdInvited() { return m_GuildIdInvited; }
static void RemovePetitionsAndSigns(ObjectGuid guid, uint32 type);

View file

@ -4830,7 +4830,7 @@ void Player::_LoadArenaTeamInfo()
memset((void*)&m_uint32Values[PLAYER_FIELD_ARENA_TEAM_INFO_1_1], 0, sizeof(uint32) * MAX_ARENA_SLOT * ARENA_TEAM_END);
for (auto const& itr : ArenaTeam::ArenaSlotByType)
if (uint32 arenaTeamId = Player::GetArenaTeamIdFromStorage(GetGUID().GetCounter(), itr.second))
if (uint32 arenaTeamId = sCharacterCache->GetCharacterArenaTeamIdByGuid(GetGUID(), itr.second))
{
ArenaTeam* arenaTeam = sArenaTeamMgr->GetArenaTeamById(arenaTeamId);
if (!arenaTeam)
@ -6564,12 +6564,16 @@ void Player::_LoadSpells(PreparedQueryResult result)
void Player::_LoadGroup()
{
if (uint32 groupId = GetGroupIdFromStorage(GetGUID().GetCounter()))
if (Group* group = sGroupMgr->GetGroupByGUID(groupId))
if (ObjectGuid groupId = sCharacterCache->GetCharacterGroupGuidByGuid(GetGUID()))
{
if (Group* group = sGroupMgr->GetGroupByGUID(groupId.GetCounter()))
{
if (group->GetMemberGroup(GetGUID()) <= MAX_RAID_SUBGROUPS)
{
if (group->IsLeader(GetGUID()))
{
SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_GROUP_LEADER);
}
uint8 subgroup = group->GetMemberGroup(GetGUID());
SetGroup(group, subgroup);
@ -6578,6 +6582,8 @@ void Player::_LoadGroup()
SetDungeonDifficulty(group->GetDungeonDifficulty());
SetRaidDifficulty(group->GetRaidDifficulty());
}
}
}
if (!GetGroup() || !GetGroup()->IsLeader(GetGUID()))
RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_GROUP_LEADER);

View file

@ -21,6 +21,7 @@
#include "BattlefieldMgr.h"
#include "Battleground.h"
#include "CellImpl.h"
#include "CharacterCache.h"
#include "Chat.h"
#include "ChatTextBuilder.h"
#include "Common.h"
@ -14611,9 +14612,10 @@ void Unit::SetLevel(uint8 lvl, bool showLevelChange)
if (GetTypeId() == TYPEID_PLAYER && ToPlayer()->GetGroup())
ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL);
// xinef: update global data
if (GetTypeId() == TYPEID_PLAYER)
sWorld->UpdateGlobalPlayerData(ToPlayer()->GetGUID().GetCounter(), PLAYER_UPDATE_DATA_LEVEL, "", lvl);
{
sCharacterCache->UpdateCharacterLevel(GetGUID(), lvl);
}
}
void Unit::SetHealth(uint32 val)

View file

@ -18,6 +18,7 @@
#include "AccountMgr.h"
#include "AchievementMgr.h"
#include "ArenaTeamMgr.h"
#include "CharacterCache.h"
#include "Chat.h"
#include "Common.h"
#include "DatabaseEnv.h"
@ -2344,56 +2345,6 @@ void ObjectMgr::RemoveGameobjectFromGrid(ObjectGuid::LowType guid, GameObjectDat
}
}
ObjectGuid ObjectMgr::GetPlayerGUIDByName(std::string const& name) const
{
// Get data from global storage
if (ObjectGuid guid = sWorld->GetGlobalPlayerGUID(name))
return guid;
// No player found
return ObjectGuid::Empty;
}
bool ObjectMgr::GetPlayerNameByGUID(ObjectGuid::LowType lowGuid, std::string& name) const
{
// Get data from global storage
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(lowGuid))
{
name = playerData->name;
return true;
}
return false;
}
TeamId ObjectMgr::GetPlayerTeamIdByGUID(ObjectGuid::LowType guid) const
{
// xinef: Get data from global storage
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid))
return Player::TeamIdForRace(playerData->race);
return TEAM_NEUTRAL;
}
uint32 ObjectMgr::GetPlayerAccountIdByGUID(ObjectGuid::LowType guid) const
{
// xinef: Get data from global storage
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid))
return playerData->accountId;
return 0;
}
uint32 ObjectMgr::GetPlayerAccountIdByPlayerName(const std::string& name) const
{
// Get data from global storage
if (ObjectGuid guid = sWorld->GetGlobalPlayerGUID(name))
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guid.GetCounter()))
return playerData->accountId;
return 0;
}
void ObjectMgr::LoadItemLocales()
{
uint32 oldMSTime = getMSTime();
@ -5820,8 +5771,8 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)
}
// xinef: update global data
sWorld->UpdateGlobalPlayerMails(m->sender, 1);
sWorld->UpdateGlobalPlayerMails(m->receiver, -1);
sCharacterCache->IncreaseCharacterMailCount(ObjectGuid(HighGuid::Player, m->sender));
sCharacterCache->DecreaseCharacterMailCount(ObjectGuid(HighGuid::Player, m->receiver));
delete m;
++returnedCount;
@ -5829,8 +5780,7 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)
}
}
// xinef: update global data
sWorld->UpdateGlobalPlayerMails(m->receiver, -1);
sCharacterCache->DecreaseCharacterMailCount(ObjectGuid(HighGuid::Player, m->receiver));
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_MAIL_BY_ID);
stmt->setUInt32(0, m->messageID);

View file

@ -777,12 +777,6 @@ public:
void GetPlayerLevelInfo(uint32 race, uint32 class_, uint8 level, PlayerLevelInfo* info) const;
[[nodiscard]] ObjectGuid GetPlayerGUIDByName(std::string const& name) const;
bool GetPlayerNameByGUID(ObjectGuid::LowType lowGuid, std::string& name) const;
[[nodiscard]] TeamId GetPlayerTeamIdByGUID(ObjectGuid::LowType guid) const;
[[nodiscard]] uint32 GetPlayerAccountIdByGUID(ObjectGuid::LowType guid) const;
[[nodiscard]] uint32 GetPlayerAccountIdByPlayerName(std::string const& name) const;
uint32 GetNearestTaxiNode(float x, float y, float z, uint32 mapid, uint32 teamId);
void GetTaxiPath(uint32 source, uint32 destination, uint32& path, uint32& cost);
uint32 GetTaxiMountDisplayId(uint32 id, TeamId teamId, bool allowed_alt_team = false);

View file

@ -177,7 +177,7 @@ bool Group::LoadGroupFromDB(Field* fields)
m_leaderGuid = ObjectGuid::Create<HighGuid::Player>(fields[0].GetUInt32());
// group leader not exist
if (!sObjectMgr->GetPlayerNameByGUID(fields[0].GetUInt32(), m_leaderName))
if (!sCharacterCache->GetCharacterNameByGuid(m_leaderGuid, m_leaderName))
{
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP);
@ -230,7 +230,7 @@ void Group::LoadMemberFromDB(ObjectGuid::LowType guidLow, uint8 memberFlags, uin
member.guid = ObjectGuid::Create<HighGuid::Player>(guidLow);
// skip non-existed member
if (!sObjectMgr->GetPlayerNameByGUID(member.guid.GetCounter(), member.name))
if (!sCharacterCache->GetCharacterNameByGuid(member.guid, member.name))
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_MEMBER);
stmt->setUInt32(0, guidLow);
@ -244,8 +244,11 @@ void Group::LoadMemberFromDB(ObjectGuid::LowType guidLow, uint8 memberFlags, uin
member.roles = roles;
m_memberSlots.push_back(member);
if (!isBGGroup() && !isBFGroup())
sWorld->UpdateGlobalPlayerGroup(guidLow, GetGUID().GetCounter());
{
sCharacterCache->UpdateCharacterGroup(ObjectGuid(HighGuid::Player, guidLow), GetGUID());
}
SubGroupCounterIncrease(subgroup);
@ -402,8 +405,11 @@ bool Group::AddMember(Player* player)
member.flags = 0;
member.roles = 0;
m_memberSlots.push_back(member);
if (!isBGGroup() && !isBFGroup())
sWorld->UpdateGlobalPlayerGroup(player->GetGUID().GetCounter(), GetGUID().GetCounter());
{
sCharacterCache->UpdateCharacterGroup(player->GetGUID(), GetGUID());
}
SubGroupCounterIncrease(subGroup);
@ -618,8 +624,11 @@ bool Group::RemoveMember(ObjectGuid guid, const RemoveMethod& method /*= GROUP_R
{
SubGroupCounterDecrease(slot->group);
m_memberSlots.erase(slot);
if (!isBGGroup() && !isBFGroup())
sWorld->UpdateGlobalPlayerGroup(guid.GetCounter(), 0);
{
sCharacterCache->ClearCharacterGroup(guid);
}
}
// Reevaluate group enchanter if the leaving player had enchanting skill or the player is offline
@ -737,7 +746,9 @@ void Group::Disband(bool hideDestroy /* = false */)
for (member_citerator citr = m_memberSlots.begin(); citr != m_memberSlots.end(); ++citr)
{
if (!isBGGroup() && !isBFGroup())
sWorld->UpdateGlobalPlayerGroup(citr->guid.GetCounter(), 0);
{
sCharacterCache->ClearCharacterGroup(citr->guid);
}
player = ObjectAccessor::FindConnectedPlayer(citr->guid);

View file

@ -17,6 +17,7 @@
#include "CalendarMgr.h"
#include "Chat.h"
#include "CharacterCache.h"
#include "Config.h"
#include "DatabaseEnv.h"
#include "Guild.h"
@ -1550,9 +1551,10 @@ void Guild::HandleInviteMember(WorldSession* session, std::string const& name)
void Guild::HandleAcceptMember(WorldSession* session)
{
Player* player = session->GetPlayer();
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) &&
player->GetTeamId() != sObjectMgr->GetPlayerTeamIdByGUID(GetLeaderGUID().GetCounter()))
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && player->GetTeamId() != sCharacterCache->GetCharacterTeamByGuid(GetLeaderGUID()))
{
return;
}
AddMember(player->GetGUID());
}
@ -1963,7 +1965,7 @@ bool Guild::LoadMemberFromDB(Field* fields)
return false;
}
m_members[memberGUID] = member;
sWorld->UpdateGlobalPlayerGuild(memberGUID.GetCounter(), GetId());
sCharacterCache->UpdateCharacterGuildId(memberGUID, GetId());
return true;
}
@ -2172,7 +2174,7 @@ void Guild::MassInviteToEvent(WorldSession* session, uint32 minLevel, uint32 max
}
Member* member = itr->second;
uint32 level = Player::GetLevelFromStorage(member->GetGUID().GetCounter());
uint32 level = sCharacterCache->GetCharacterLevelByGuid(member->GetGUID());
if (member->GetGUID() != session->GetPlayer()->GetGUID() && level >= minLevel && level <= maxLevel && member->IsRankNotLower(minRank))
{
@ -2197,7 +2199,7 @@ bool Guild::AddMember(ObjectGuid guid, uint8 rankId)
if (player->GetGuildId() != 0)
return false;
}
else if (Player::GetGuildIdFromStorage(guid.GetCounter()) != 0)
else if (sCharacterCache->GetCharacterGuildIdByGuid(guid) != 0)
return false;
// Remove all player signs from another petitions
@ -2249,7 +2251,7 @@ bool Guild::AddMember(ObjectGuid guid, uint8 rankId)
return false;
}
m_members[guid] = member;
sWorld->UpdateGlobalPlayerGuild(guid.GetCounter(), m_id);
sCharacterCache->UpdateCharacterGuildId(guid, m_id);
}
CharacterDatabaseTransaction trans(nullptr);
@ -2321,7 +2323,9 @@ void Guild::DeleteMember(ObjectGuid guid, bool isDisbanding, bool isKicked, bool
player->SetRank(0);
}
else
sWorld->UpdateGlobalPlayerGuild(guid.GetCounter(), 0);
{
sCharacterCache->UpdateCharacterGuildId(guid, 0);
}
_DeleteMemberFromDB(guid.GetCounter());
if (!isDisbanding)

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;

View file

@ -17,6 +17,7 @@
#include "AuctionHouseMgr.h"
#include "BattlegroundMgr.h"
#include "CharacterCache.h"
#include "CalendarMgr.h"
#include "DatabaseEnv.h"
#include "Item.h"
@ -146,7 +147,9 @@ void MailDraft::SendReturnToSender(uint32 /*sender_acc*/, ObjectGuid::LowType se
uint32 rc_account = 0;
if (!receiver)
rc_account = sObjectMgr->GetPlayerAccountIdByGUID(receiver_guid);
{
rc_account = sCharacterCache->GetCharacterAccountIdByGuid(ObjectGuid(HighGuid::Player, receiver_guid));
}
if (!receiver && !rc_account) // sender not exist
{
@ -250,8 +253,7 @@ void MailDraft::SendMailTo(CharacterDatabaseTransaction trans, MailReceiver cons
trans->Append(stmt);
}
// xinef: update global data
sWorld->UpdateGlobalPlayerMails(receiver.GetPlayerGUIDLow(), 1);
sCharacterCache->IncreaseCharacterMailCount(ObjectGuid(HighGuid::Player, receiver.GetPlayerGUIDLow()));
// For online receiver update in game mail status and data
if (pReceiver)

View file

@ -102,7 +102,7 @@ BanReturn BanMgr::BanAccountByPlayerName(std::string const& CharacterName, std::
uint32 DurationSecs = TimeStringToSecs(Duration);
uint32 AccountID = sObjectMgr->GetPlayerAccountIdByPlayerName(CharacterName);
uint32 AccountID = sCharacterCache->GetCharacterAccountIdByName(CharacterName);
if (!AccountID)
return BAN_NOTFOUND;
@ -228,7 +228,7 @@ BanReturn BanMgr::BanCharacter(std::string const& CharacterName, std::string con
/// Pick a player to ban if not online
if (!target)
{
TargetGUID = sWorld->GetGlobalPlayerGUID(CharacterName);
TargetGUID = sCharacterCache->GetCharacterGuidByName(CharacterName);
if (!TargetGUID)
return BAN_NOTFOUND;
}
@ -284,7 +284,7 @@ bool BanMgr::RemoveBanAccount(std::string const& AccountName)
/// Remove a ban from an player name
bool BanMgr::RemoveBanAccountByPlayerName(std::string const& CharacterName)
{
uint32 AccountID = sObjectMgr->GetPlayerAccountIdByPlayerName(CharacterName);
uint32 AccountID = sCharacterCache->GetCharacterAccountIdByName(CharacterName);
if (!AccountID)
return false;
@ -314,7 +314,7 @@ bool BanMgr::RemoveBanCharacter(std::string const& CharacterName)
/// Pick a player to ban if not online
if (!pBanned)
guid = sWorld->GetGlobalPlayerGUID(CharacterName);
guid = sCharacterCache->GetCharacterGuidByName(CharacterName);
else
guid = pBanned->GetGUID();

View file

@ -1220,6 +1220,11 @@ enum AcoreStrings
LANG_NPCINFO_SPELL_SCHOOL_IMMUNE = 5062,
LANG_COMMAND_CACHE_INFO = 5063,
LANG_COMMAND_CACHE_DELETE = 5064,
LANG_COMMAND_CACHE_REFRESH = 5065,
LANG_COMMAND_CACHE_NOT_FOUND = 5066,
// Room for more strings 5063-9999
// Level requirement notifications

View file

@ -167,8 +167,10 @@ std::string GmTicket::FormatMessageString(ChatHandler& handler, bool detailed) c
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTAGE, (secsToTimeString(curTime - _lastModifiedTime, true)).c_str());
std::string name;
if (sObjectMgr->GetPlayerNameByGUID(_assignedTo.GetCounter(), name))
if (sCharacterCache->GetCharacterNameByGuid(_assignedTo, name))
{
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTASSIGNEDTO, name.c_str());
}
if (detailed)
{

View file

@ -108,7 +108,9 @@ public:
std::string name;
// save queries if ticket is not assigned
if (_assignedTo)
sObjectMgr->GetPlayerNameByGUID(_assignedTo.GetCounter(), name);
{
sCharacterCache->GetCharacterNameByGuid(_assignedTo, name);
}
return name;
}

View file

@ -17,6 +17,7 @@
#include "AccountMgr.h"
#include "Common.h"
#include "CharacterCache.h"
#include "DatabaseEnv.h"
#include "ObjectMgr.h"
#include "PlayerDump.h"
@ -693,7 +694,7 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
CharacterDatabase.CommitTransaction(trans);
// in case of name conflict player has to rename at login anyway
sWorld->AddGlobalPlayerData(guid, account, name, gender, race, playerClass, level, mails.size(), 0);
sCharacterCache->AddCharacterCacheEntry(ObjectGuid(HighGuid::Player, guid), account, name, gender, race, playerClass, level);
sObjectMgr->GetGenerator<HighGuid::Item>().Set(sObjectMgr->GetGenerator<HighGuid::Item>().GetNextAfterMaxUsed() + items.size());
sObjectMgr->_mailId += mails.size();

View file

@ -485,22 +485,6 @@ enum Rates
MAX_RATES
};
// xinef: global storage
struct GlobalPlayerData
{
ObjectGuid::LowType guidLow;
uint32 accountId;
std::string name;
uint8 race;
uint8 playerClass;
uint8 gender;
uint8 level;
uint16 mailCount;
uint32 guildId;
uint32 groupId;
std::map<uint8, uint32> arenaTeamId;
};
class IWorld
{
public:
@ -582,17 +566,6 @@ public:
virtual void KickAll() = 0;
virtual void KickAllLess(AccountTypes sec) = 0;
virtual uint32 GetNextWhoListUpdateDelaySecs() = 0;
virtual void LoadGlobalPlayerDataStore() = 0;
virtual ObjectGuid GetGlobalPlayerGUID(std::string const& name) const = 0;
virtual GlobalPlayerData const* GetGlobalPlayerData(ObjectGuid::LowType guid) const = 0;
virtual void AddGlobalPlayerData(ObjectGuid::LowType guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, uint16 mailCount, uint32 guildId) = 0;
virtual void UpdateGlobalPlayerData(ObjectGuid::LowType guid, uint8 mask, std::string const& name, uint8 level = 0, uint8 gender = 0, uint8 race = 0, uint8 playerClass = 0) = 0;
virtual void UpdateGlobalPlayerMails(ObjectGuid::LowType guid, int16 count, bool add = true) = 0;
virtual void UpdateGlobalPlayerGuild(ObjectGuid::LowType guid, uint32 guildId) = 0;
virtual void UpdateGlobalPlayerGroup(ObjectGuid::LowType guid, uint32 groupId) = 0;
virtual void UpdateGlobalPlayerArenaTeam(ObjectGuid::LowType guid, uint8 slot, uint32 arenaTeamId) = 0;
virtual void UpdateGlobalNameData(ObjectGuid::LowType guidLow, std::string const& oldName, std::string const& newName) = 0;
virtual void DeleteGlobalPlayerData(ObjectGuid::LowType guid, std::string const& name) = 0;
virtual void ProcessCliCommands() = 0;
virtual void QueueCliCommand(CliCommandHolder* commandHolder) = 0;
virtual void ForceGameEventUpdate() = 0;

View file

@ -1564,9 +1564,8 @@ void World::SetInitialWorldSettings()
LOG_INFO("server.loading", "Loading Instance Template...");
sObjectMgr->LoadInstanceTemplate();
// xinef: Global Storage, should be loaded asap
LOG_INFO("server.loading", "Load Global Player Data...");
sWorld->LoadGlobalPlayerDataStore();
LOG_INFO("server.loading", "Load Character Cache...");
sCharacterCache->LoadCharacterCacheStorage();
// Must be called before `creature_respawn`/`gameobject_respawn` tables
LOG_INFO("server.loading", "Loading instances...");
@ -3334,260 +3333,6 @@ void World::ProcessQueryCallbacks()
_queryProcessor.ProcessReadyCallbacks();
}
void World::LoadGlobalPlayerDataStore()
{
uint32 oldMSTime = getMSTime();
_globalPlayerDataStore.clear();
QueryResult result = CharacterDatabase.Query("SELECT guid, account, name, gender, race, class, level FROM characters WHERE deleteDate IS NULL");
if (!result)
{
LOG_INFO("server.loading", ">> Loaded 0 Players data.");
return;
}
uint32 count = 0;
// query to load number of mails by receiver
std::map<uint32, uint16> _mailCountMap;
QueryResult mailCountResult = CharacterDatabase.Query("SELECT receiver, COUNT(receiver) FROM mail GROUP BY receiver");
if (mailCountResult)
{
do
{
Field* fields = mailCountResult->Fetch();
_mailCountMap[fields[0].GetUInt32()] = uint16(fields[1].GetUInt64());
} while (mailCountResult->NextRow());
}
do
{
Field* fields = result->Fetch();
ObjectGuid::LowType guidLow = fields[0].GetUInt32();
// count mails
uint16 mailCount = 0;
std::map<uint32, uint16>::const_iterator itr = _mailCountMap.find(guidLow);
if (itr != _mailCountMap.end())
mailCount = itr->second;
AddGlobalPlayerData(
guidLow, /*guid*/
fields[1].GetUInt32(), /*accountId*/
fields[2].GetString(), /*name*/
fields[3].GetUInt8(), /*gender*/
fields[4].GetUInt8(), /*race*/
fields[5].GetUInt8(), /*class*/
fields[6].GetUInt8(), /*level*/
mailCount, /*mail count*/
0 /*guild id*/);
++count;
} while (result->NextRow());
LOG_INFO("server.loading", ">> Loaded %d Players data in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server.loading", " ");
}
void World::AddGlobalPlayerData(ObjectGuid::LowType guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, uint16 mailCount, uint32 guildId)
{
GlobalPlayerData data;
data.guidLow = guid;
data.accountId = accountId;
data.name = name;
data.level = level;
data.race = race;
data.playerClass = playerClass;
data.gender = gender;
data.mailCount = mailCount;
data.guildId = guildId;
data.groupId = 0;
data.arenaTeamId[0] = 0;
data.arenaTeamId[1] = 0;
data.arenaTeamId[2] = 0;
_globalPlayerDataStore[guid] = data;
_globalPlayerNameStore[name] = guid;
}
void World::UpdateGlobalPlayerData(ObjectGuid::LowType guid, uint8 mask, std::string const& name, uint8 level, uint8 gender, uint8 race, uint8 playerClass)
{
GlobalPlayerDataMap::iterator itr = _globalPlayerDataStore.find(guid);
if (itr == _globalPlayerDataStore.end())
return;
if (mask & PLAYER_UPDATE_DATA_LEVEL)
itr->second.level = level;
if (mask & PLAYER_UPDATE_DATA_RACE)
itr->second.race = race;
if (mask & PLAYER_UPDATE_DATA_CLASS)
itr->second.playerClass = playerClass;
if (mask & PLAYER_UPDATE_DATA_GENDER)
itr->second.gender = gender;
if (mask & PLAYER_UPDATE_DATA_NAME)
itr->second.name = name;
WorldPacket data(SMSG_INVALIDATE_PLAYER, 8);
data << guid;
SendGlobalMessage(&data);
}
void World::UpdateGlobalPlayerMails(ObjectGuid::LowType guid, int16 count, bool add)
{
GlobalPlayerDataMap::iterator itr = _globalPlayerDataStore.find(guid);
if (itr == _globalPlayerDataStore.end())
return;
if (!add)
{
itr->second.mailCount = count;
return;
}
int16 icount = (int16)itr->second.mailCount;
if (count < 0 && abs(count) > icount)
count = -icount;
itr->second.mailCount = uint16(icount + count); // addition or subtraction
}
void World::UpdateGlobalPlayerGuild(ObjectGuid::LowType guid, uint32 guildId)
{
GlobalPlayerDataMap::iterator itr = _globalPlayerDataStore.find(guid);
if (itr == _globalPlayerDataStore.end())
return;
itr->second.guildId = guildId;
}
void World::UpdateGlobalPlayerGroup(ObjectGuid::LowType guid, uint32 groupId)
{
GlobalPlayerDataMap::iterator itr = _globalPlayerDataStore.find(guid);
if (itr == _globalPlayerDataStore.end())
return;
itr->second.groupId = groupId;
}
void World::UpdateGlobalPlayerArenaTeam(ObjectGuid::LowType guid, uint8 slot, uint32 arenaTeamId)
{
GlobalPlayerDataMap::iterator itr = _globalPlayerDataStore.find(guid);
if (itr == _globalPlayerDataStore.end())
return;
itr->second.arenaTeamId[slot] = arenaTeamId;
}
void World::UpdateGlobalNameData(ObjectGuid::LowType guidLow, std::string const& oldName, std::string const& newName)
{
_globalPlayerNameStore.erase(oldName);
_globalPlayerNameStore[newName] = guidLow;
}
void World::DeleteGlobalPlayerData(ObjectGuid::LowType guid, std::string const& name)
{
if (guid)
_globalPlayerDataStore.erase(guid);
if (!name.empty())
_globalPlayerNameStore.erase(name);
}
GlobalPlayerData const* World::GetGlobalPlayerData(ObjectGuid::LowType guid) const
{
// Get data from global storage
GlobalPlayerDataMap::const_iterator itr = _globalPlayerDataStore.find(guid);
if (itr != _globalPlayerDataStore.end())
return &itr->second;
// Player is not in the global storage, try to get it from the Database
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_DATA_BY_GUID);
stmt->setUInt32(0, guid);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
{
// Player was not in the global storage, but it was found in the database
// Let's add it to the global storage
Field* fields = result->Fetch();
std::string name = fields[2].GetString();
LOG_INFO("server.worldserver", "Player %s [GUID: %u] was not found in the global storage, but it was found in the database.", name.c_str(), guid);
sWorld->AddGlobalPlayerData(
fields[0].GetUInt32(), /*guid*/
fields[1].GetUInt32(), /*accountId*/
fields[2].GetString(), /*name*/
fields[3].GetUInt8(), /*gender*/
fields[4].GetUInt8(), /*race*/
fields[5].GetUInt8(), /*class*/
fields[6].GetUInt8(), /*level*/
0, /*mail count*/
0 /*guild id*/
);
itr = _globalPlayerDataStore.find(guid);
if (itr != _globalPlayerDataStore.end())
{
LOG_INFO("server.worldserver", "Player %s [GUID: %u] added to the global storage.", name.c_str(), guid);
return &itr->second;
}
}
// Player not found
return nullptr;
}
ObjectGuid World::GetGlobalPlayerGUID(std::string const& name) const
{
// Get data from global storage
GlobalPlayerNameMap::const_iterator itr = _globalPlayerNameStore.find(name);
if (itr != _globalPlayerNameStore.end())
return ObjectGuid::Create<HighGuid::Player>(itr->second);
// Player is not in the global storage, try to get it from the Database
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_DATA_BY_NAME);
stmt->setString(0, name);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result)
{
// Player was not in the global storage, but it was found in the database
// Let's add it to the global storage
Field* fields = result->Fetch();
ObjectGuid::LowType guidLow = fields[0].GetUInt32();
LOG_INFO("server.worldserver", "Player %s [GUID: %u] was not found in the global storage, but it was found in the database.", name.c_str(), guidLow);
sWorld->AddGlobalPlayerData(
guidLow, /*guid*/
fields[1].GetUInt32(), /*accountId*/
fields[2].GetString(), /*name*/
fields[3].GetUInt8(), /*gender*/
fields[4].GetUInt8(), /*race*/
fields[5].GetUInt8(), /*class*/
fields[6].GetUInt8(), /*level*/
0, /*mail count*/
0 /*guild id*/
);
itr = _globalPlayerNameStore.find(name);
if (itr != _globalPlayerNameStore.end())
{
LOG_INFO("server.worldserver", "Player %s [GUID: %u] added to the global storage.", name.c_str(), guidLow);
return ObjectGuid::Create<HighGuid::Player>(guidLow);
}
}
// Player not found
return ObjectGuid::Empty;
}
void World::RemoveOldCorpses()
{
m_timers[WUPDATE_CORPSES].SetCurrent(m_timers[WUPDATE_CORPSES].GetInterval());

View file

@ -143,18 +143,6 @@ enum WorldStates
#define WORLD_SLEEP_CONST 10
enum GlobalPlayerUpdateMask
{
PLAYER_UPDATE_DATA_LEVEL = 0x01,
PLAYER_UPDATE_DATA_RACE = 0x02,
PLAYER_UPDATE_DATA_CLASS = 0x04,
PLAYER_UPDATE_DATA_GENDER = 0x08,
PLAYER_UPDATE_DATA_NAME = 0x10,
};
typedef std::map<ObjectGuid::LowType, GlobalPlayerData> GlobalPlayerDataMap;
typedef std::map<std::string, ObjectGuid::LowType> GlobalPlayerNameMap;
// xinef: petitions storage
struct PetitionData
{
@ -350,19 +338,6 @@ public:
// our: needed for arena spectator subscriptions
uint32 GetNextWhoListUpdateDelaySecs();
// xinef: Global Player Data Storage system
void LoadGlobalPlayerDataStore();
ObjectGuid GetGlobalPlayerGUID(std::string const& name) const;
GlobalPlayerData const* GetGlobalPlayerData(ObjectGuid::LowType guid) const;
void AddGlobalPlayerData(ObjectGuid::LowType guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, uint16 mailCount, uint32 guildId);
void UpdateGlobalPlayerData(ObjectGuid::LowType guid, uint8 mask, std::string const& name, uint8 level = 0, uint8 gender = 0, uint8 race = 0, uint8 playerClass = 0);
void UpdateGlobalPlayerMails(ObjectGuid::LowType guid, int16 count, bool add = true);
void UpdateGlobalPlayerGuild(ObjectGuid::LowType guid, uint32 guildId);
void UpdateGlobalPlayerGroup(ObjectGuid::LowType guid, uint32 groupId);
void UpdateGlobalPlayerArenaTeam(ObjectGuid::LowType guid, uint8 slot, uint32 arenaTeamId);
void UpdateGlobalNameData(ObjectGuid::LowType guidLow, std::string const& oldName, std::string const& newName);
void DeleteGlobalPlayerData(ObjectGuid::LowType guid, std::string const& name);
void ProcessCliCommands();
void QueueCliCommand(CliCommandHolder* commandHolder) { cliCmdQueue.add(commandHolder); }
@ -460,10 +435,6 @@ private:
static float m_MaxVisibleDistanceInInstances;
static float m_MaxVisibleDistanceInBGArenas;
// our speed ups
GlobalPlayerDataMap _globalPlayerDataStore; // xinef
GlobalPlayerNameMap _globalPlayerNameStore; // xinef
std::string _realmName;
// CLI command holder to be thread safe

View file

@ -195,7 +195,7 @@ public:
}
std::string oldCaptainName;
sObjectMgr->GetPlayerNameByGUID(arena->GetCaptain().GetCounter(), oldCaptainName);
sCharacterCache->GetCharacterNameByGuid(arena->GetCaptain(), oldCaptainName);
arena->SetCaptain(target->GetGUID());
handler->PSendSysMessage(LANG_ARENA_CAPTAIN, arena->GetName().c_str(), arena->GetId(), oldCaptainName.c_str(), target->GetName().c_str());

View file

@ -24,6 +24,7 @@ EndScriptData */
#include "AccountMgr.h"
#include "BanMgr.h"
#include "CharacterCache.h"
#include "Chat.h"
#include "Language.h"
#include "ObjectAccessor.h"
@ -326,7 +327,7 @@ public:
if (!target)
{
targetGuid = sWorld->GetGlobalPlayerGUID(name);
targetGuid = sCharacterCache->GetCharacterGuidByName(name);
if (!targetGuid)
{
handler->PSendSysMessage(LANG_BANINFO_NOCHARACTER);

View file

@ -0,0 +1,157 @@
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ScriptMgr.h"
#include "Chat.h"
#include "Group.h"
#include "Language.h"
#include "Player.h"
using namespace Acore::ChatCommands;
class cache_commandscript : public CommandScript
{
public:
cache_commandscript() : CommandScript("cache_commandscript") { }
ChatCommandTable GetCommands() const override
{
static ChatCommandTable cacheCommandTable =
{
{ "info", HandleCacheInfoCommand, SEC_GAMEMASTER, Console::Yes },
{ "delete", HandleCacheDeleteCommand, SEC_ADMINISTRATOR, Console::Yes },
{ "refresh", HandleCacheRefreshCommand, SEC_GAMEMASTER, Console::Yes }
};
static ChatCommandTable commandTable =
{
{ "cache", cacheCommandTable },
};
return commandTable;
}
static bool HandleCacheInfoCommand(ChatHandler* handler, Optional<PlayerIdentifier> player)
{
if (!player)
{
player = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!player)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
CharacterCacheEntry const* cache = sCharacterCache->GetCharacterCacheByGuid(player->GetGUID());
if (!cache)
{
handler->PSendSysMessage(LANG_COMMAND_CACHE_NOT_FOUND, player->GetName());
handler->SetSentErrorMessage(true);
return false;
}
handler->PSendSysMessage(LANG_COMMAND_CACHE_INFO, cache->Name, cache->Guid.GetCounter(), cache->AccountId,
cache->Class, cache->Race, cache->Sex, cache->Level, cache->MailCount, cache->GuildId, cache->GroupGuid.GetCounter(),
cache->ArenaTeamId[ARENA_SLOT_2v2], cache->ArenaTeamId[ARENA_SLOT_3v3], cache->ArenaTeamId[ARENA_SLOT_5v5]);
handler->SetSentErrorMessage(false);
return true;
}
static bool HandleCacheDeleteCommand(ChatHandler* handler, Optional<PlayerIdentifier> player)
{
if (!player)
{
player = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!player)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
sCharacterCache->DeleteCharacterCacheEntry(player->GetGUID(), player->GetName());
handler->PSendSysMessage(LANG_COMMAND_CACHE_DELETE, player->GetName(), player->GetGUID().GetCounter());
handler->SetSentErrorMessage(false);
return true;
}
static bool HandleCacheRefreshCommand(ChatHandler* handler, Optional<PlayerIdentifier> player)
{
if (!player)
{
player = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!player)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (player->IsConnected())
{
if (Player* cPlayer = ObjectAccessor::FindConnectedPlayer(player->GetGUID()))
{
if (sCharacterCache->HasCharacterCacheEntry(cPlayer->GetGUID()))
{
sCharacterCache->UpdateCharacterData(cPlayer->GetGUID(), cPlayer->GetName(), cPlayer->getGender(), cPlayer->getRace());
}
else
{
sCharacterCache->AddCharacterCacheEntry(cPlayer->GetGUID(), cPlayer->GetSession()->GetAccountId(), cPlayer->GetName(),
cPlayer->getGender(), cPlayer->getRace(), cPlayer->getClass(), cPlayer->getLevel());
}
sCharacterCache->UpdateCharacterAccountId(cPlayer->GetGUID(), cPlayer->GetSession()->GetAccountId());
sCharacterCache->UpdateCharacterGuildId(cPlayer->GetGUID(), cPlayer->GetGuildId());
sCharacterCache->UpdateCharacterMailCount(cPlayer->GetGUID(), cPlayer->GetMailSize(), true);
sCharacterCache->UpdateCharacterArenaTeamId(cPlayer->GetGUID(), ARENA_SLOT_2v2, cPlayer->GetArenaTeamId(ARENA_SLOT_2v2));
sCharacterCache->UpdateCharacterArenaTeamId(cPlayer->GetGUID(), ARENA_SLOT_3v3, cPlayer->GetArenaTeamId(ARENA_SLOT_3v3));
sCharacterCache->UpdateCharacterArenaTeamId(cPlayer->GetGUID(), ARENA_SLOT_5v5, cPlayer->GetArenaTeamId(ARENA_SLOT_5v5));
if (Group* group = cPlayer->GetGroup())
{
sCharacterCache->UpdateCharacterGroup(cPlayer->GetGUID(), group->GetGUID());
}
else
{
sCharacterCache->ClearCharacterGroup(cPlayer->GetGUID());
}
}
}
else
{
sCharacterCache->RefreshCacheEntry(player->GetGUID().GetCounter());
}
handler->PSendSysMessage(LANG_COMMAND_CACHE_REFRESH, player->GetName(), player->GetGUID().GetCounter());
handler->SetSentErrorMessage(false);
return true;
}
};
void AddSC_cache_commandscript()
{
new cache_commandscript();
}

View file

@ -224,7 +224,7 @@ public:
return;
}
if (sObjectMgr->GetPlayerGUIDByName(delInfo.name))
if (sCharacterCache->GetCharacterGuidByName(delInfo.name))
{
handler->PSendSysMessage(LANG_CHARACTER_DELETED_SKIP_NAME, delInfo.name.c_str(), delInfo.lowGuid, delInfo.accountId);
return;
@ -239,7 +239,9 @@ public:
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_NAME_DATA);
stmt->setUInt32(0, delInfo.lowGuid);
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
sWorld->AddGlobalPlayerData(delInfo.lowGuid, delInfo.accountId, delInfo.name, (*result)[2].GetUInt8(), (*result)[0].GetUInt8(), (*result)[1].GetUInt8(), (*result)[3].GetUInt8(), 0, 0);
{
sCharacterCache->AddCharacterCacheEntry(ObjectGuid(HighGuid::Player, delInfo.lowGuid), delInfo.accountId, delInfo.name, (*result)[2].GetUInt8(), (*result)[0].GetUInt8(), (*result)[1].GetUInt8(), (*result)[3].GetUInt8());
}
}
static void HandleCharacterLevel(Player* player, ObjectGuid playerGuid, uint32 oldLevel, uint32 newLevel, ChatHandler* handler)
@ -268,8 +270,7 @@ public:
stmt->setUInt32(1, playerGuid.GetCounter());
CharacterDatabase.Execute(stmt);
// xinef: update global storage
sWorld->UpdateGlobalPlayerData(playerGuid.GetCounter(), PLAYER_UPDATE_DATA_LEVEL, "", newLevel);
sCharacterCache->UpdateCharacterLevel(playerGuid, newLevel);
}
}
@ -390,8 +391,7 @@ public:
CharacterDatabase.Execute(stmt);
}
sWorld->UpdateGlobalNameData(player->GetGUID().GetCounter(), player->GetName().c_str(), newName);
sWorld->UpdateGlobalPlayerData(player->GetGUID().GetCounter(), PLAYER_UPDATE_DATA_NAME, newName);
sCharacterCache->UpdateCharacterData(player->GetGUID(), newName);
handler->PSendSysMessage(LANG_RENAME_PLAYER_WITH_NEW_NAME, player->GetName().c_str(), newName.c_str());
}
@ -433,7 +433,7 @@ public:
if (!player)
return false;
uint8 oldlevel = player->IsConnected() ? player->GetConnectedPlayer()->getLevel() : static_cast<uint8>(Player::GetLevelFromStorage(player->GetGUID().GetCounter()));
uint8 oldlevel = player->IsConnected() ? player->GetConnectedPlayer()->getLevel() : sCharacterCache->GetCharacterLevelByGuid(player->GetGUID());
if (newlevel < 1)
return false; // invalid level
@ -737,7 +737,9 @@ public:
target->GetSession()->KickPlayer("HandleCharacterEraseCommand GM Command deleting character");
}
else
accountId = sObjectMgr->GetPlayerAccountIdByGUID(player.GetGUID().GetCounter());
{
accountId = sCharacterCache->GetCharacterAccountIdByGuid(player.GetGUID());
}
std::string accountName;
AccountMgr::GetName(accountId, accountName);
@ -756,7 +758,7 @@ public:
if (!player)
return false;
uint8 oldlevel = static_cast<uint8>(player->IsConnected() ? player->GetConnectedPlayer()->getLevel() : Player::GetLevelFromStorage(player->GetGUID().GetCounter()));
uint8 oldlevel = player->IsConnected() ? player->GetConnectedPlayer()->getLevel() : sCharacterCache->GetCharacterLevelByGuid(player->GetGUID());
int16 newlevel = static_cast<int16>(oldlevel) + level;
if (newlevel < 1)
@ -796,7 +798,7 @@ public:
if (characterGUID)
{
if (sObjectMgr->GetPlayerAccountIdByGUID(*characterGUID))
if (sCharacterCache->GetCharacterAccountIdByGuid(ObjectGuid(HighGuid::Player, *characterGUID)))
{
handler->PSendSysMessage(LANG_CHARACTER_GUID_IN_USE, *characterGUID);
handler->SetSentErrorMessage(true);

View file

@ -176,7 +176,7 @@ public:
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid))
return false;
uint32 guildId = target ? target->GetGuildId() : Player::GetGuildIdFromStorage(targetGuid.GetCounter());
uint32 guildId = target ? target->GetGuildId() : sCharacterCache->GetCharacterGuildIdByGuid(targetGuid);
if (!guildId)
return false;
@ -196,7 +196,7 @@ public:
if (!player)
return false;
uint32 guildId = player->IsConnected() ? player->GetConnectedPlayer()->GetGuildId() : Player::GetGuildIdFromStorage(player->GetGUID().GetCounter());
uint32 guildId = player->IsConnected() ? player->GetConnectedPlayer()->GetGuildId() : sCharacterCache->GetCharacterGuildIdByGuid(player->GetGUID());
if (!guildId)
return false;
@ -227,8 +227,10 @@ public:
// Display Guild Information
handler->PSendSysMessage(LANG_GUILD_INFO_NAME, guild->GetName().c_str(), guild->GetId()); // Guild Id + Name
std::string guildMasterName;
if (sObjectMgr->GetPlayerNameByGUID(guild->GetLeaderGUID().GetCounter(), guildMasterName))
if (sCharacterCache->GetCharacterNameByGuid(guild->GetLeaderGUID(), guildMasterName))
{
handler->PSendSysMessage(LANG_GUILD_INFO_GUILD_MASTER, guildMasterName.c_str(), guild->GetLeaderGUID().GetCounter()); // Guild Master
}
// Format creation date
char createdDateStr[20];

View file

@ -23,6 +23,7 @@ Category: commandscripts
EndScriptData */
#include "AccountMgr.h"
#include "CharacterCache.h"
#include "Chat.h"
#include "GameEventMgr.h"
#include "ObjectAccessor.h"
@ -1615,11 +1616,11 @@ public:
uint8 plevel = 0, prace = 0, pclass = 0;
bool online = ObjectAccessor::FindPlayerByLowGUID(guid) != nullptr;
if (const GlobalPlayerData* gpd = sWorld->GetGlobalPlayerData(guid))
if (CharacterCacheEntry const* gpd = sCharacterCache->GetCharacterCacheByName(name))
{
plevel = gpd->level;
prace = gpd->race;
pclass = gpd->playerClass;
plevel = gpd->Level;
prace = gpd->Race;
pclass = gpd->Class;
}
if (plevel > 0 && prace > 0 && prace <= RACE_DRAENEI && pclass > 0 && pclass <= CLASS_DRUID)

View file

@ -19,6 +19,7 @@
#include "ArenaTeamMgr.h"
#include "BattlegroundMgr.h"
#include "CellImpl.h"
#include "CharacterCache.h"
#include "Chat.h"
#include "GameGraveyard.h"
#include "GridNotifiers.h"
@ -1869,7 +1870,7 @@ public:
ObjectGuid parseGUID = ObjectGuid::Create<HighGuid::Player>(atol((char*)args));
if (sObjectMgr->GetPlayerNameByGUID(parseGUID.GetCounter(), targetName))
if (sCharacterCache->GetCharacterNameByGuid(parseGUID, targetName))
{
target = ObjectAccessor::FindConnectedPlayer(parseGUID);
targetGuid = parseGUID;
@ -2317,7 +2318,7 @@ public:
}
Player* target = player->GetConnectedPlayer();
uint32 accountId = target ? target->GetSession()->GetAccountId() : sObjectMgr->GetPlayerAccountIdByGUID(player->GetGUID().GetCounter());
uint32 accountId = target ? target->GetSession()->GetAccountId() : sCharacterCache->GetCharacterAccountIdByGuid(player->GetGUID());
// find only player from same account if any
if (!target)
@ -2393,7 +2394,7 @@ public:
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
return false;
uint32 accountId = target ? target->GetSession()->GetAccountId() : sObjectMgr->GetPlayerAccountIdByGUID(targetGuid.GetCounter());
uint32 accountId = target ? target->GetSession()->GetAccountId() : sCharacterCache->GetCharacterAccountIdByGuid(targetGuid);
// find only player from same account if any
if (!target)
@ -3193,7 +3194,7 @@ public:
}
else if (targetName)
{
if (ObjectGuid playerGUID = sWorld->GetGlobalPlayerGUID(name))
if (ObjectGuid playerGUID = sCharacterCache->GetCharacterGuidByName(name))
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_AURA_FROZEN);
stmt->setUInt32(0, playerGUID.GetCounter());
@ -3315,7 +3316,7 @@ public:
ObjectGuid parseGUID = ObjectGuid::Create<HighGuid::Player>(atol((char*)args));
if (sObjectMgr->GetPlayerNameByGUID(parseGUID.GetCounter(), nameTarget))
if (sCharacterCache->GetCharacterNameByGuid(parseGUID, nameTarget))
{
playerTarget = ObjectAccessor::FindConnectedPlayer(parseGUID);
guidTarget = parseGUID;
@ -3328,8 +3329,12 @@ public:
groupTarget = playerTarget->GetGroup();
if (!groupTarget && guidTarget)
if (uint32 groupGUID = Player::GetGroupIdFromStorage(guidTarget.GetCounter()))
groupTarget = sGroupMgr->GetGroupByGUID(groupGUID);
{
if (ObjectGuid groupGUID = sCharacterCache->GetCharacterGroupGuidByGuid(guidTarget))
{
groupTarget = sGroupMgr->GetGroupByGUID(groupGUID.GetCounter());
}
}
if (groupTarget)
{

View file

@ -53,6 +53,7 @@ void AddSC_ticket_commandscript();
void AddSC_titles_commandscript();
void AddSC_wp_commandscript();
void AddSC_player_commandscript();
void AddSC_cache_commandscript();
// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
@ -95,4 +96,5 @@ void AddCommandsScripts()
AddSC_titles_commandscript();
AddSC_wp_commandscript();
AddSC_player_commandscript();
AddSC_cache_commandscript();
}

View file

@ -100,8 +100,8 @@ public:
}
// Get target information
ObjectGuid targetGuid = sObjectMgr->GetPlayerGUIDByName(target.c_str());
uint32 targetAccountId = sObjectMgr->GetPlayerAccountIdByGUID(targetGuid.GetCounter());
ObjectGuid targetGuid = sCharacterCache->GetCharacterGuidByName(target);
uint32 targetAccountId = sCharacterCache->GetCharacterAccountIdByGuid(targetGuid);
uint32 targetGmLevel = AccountMgr::GetSecurity(targetAccountId, realm.Id.Realm);
// Target must exist and have administrative rights
@ -399,7 +399,7 @@ public:
else
{
ObjectGuid guid = ticket->GetAssignedToGUID();
uint32 accountId = sObjectMgr->GetPlayerAccountIdByGUID(guid.GetCounter());
uint32 accountId = sCharacterCache->GetCharacterAccountIdByGuid(guid);
security = AccountMgr::GetSecurity(accountId, realm.Id.Realm);
}
@ -458,9 +458,13 @@ public:
// Detect target's GUID
ObjectGuid guid;
if (Player* player = ObjectAccessor::FindPlayerByName(name, false))
{
guid = player->GetGUID();
}
else
guid = sObjectMgr->GetPlayerGUIDByName(name);
{
guid = sCharacterCache->GetCharacterGuidByName(name);
}
// Target must exist
if (!guid)

View file

@ -107,17 +107,6 @@ public:
MOCK_METHOD(void, KickAll, ());
MOCK_METHOD(void, KickAllLess, (AccountTypes sec), ());
MOCK_METHOD(uint32, GetNextWhoListUpdateDelaySecs, ());
MOCK_METHOD(void, LoadGlobalPlayerDataStore, ());
MOCK_METHOD(ObjectGuid, GetGlobalPlayerGUID, (std::string const& name), (const));
MOCK_METHOD(GlobalPlayerData const*, GetGlobalPlayerData, (ObjectGuid::LowType guid), (const));
MOCK_METHOD(void, AddGlobalPlayerData, (ObjectGuid::LowType guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, uint16 mailCount, uint32 guildId), ());
MOCK_METHOD(void, UpdateGlobalPlayerData, (ObjectGuid::LowType guid, uint8 mask, std::string const& name, uint8 level, uint8 gender, uint8 race, uint8 playerClass), ());
MOCK_METHOD(void, UpdateGlobalPlayerMails, (ObjectGuid::LowType guid, int16 count, bool add), ());
MOCK_METHOD(void, UpdateGlobalPlayerGuild, (ObjectGuid::LowType guid, uint32 guildId), ());
MOCK_METHOD(void, UpdateGlobalPlayerGroup, (ObjectGuid::LowType guid, uint32 groupId), ());
MOCK_METHOD(void, UpdateGlobalPlayerArenaTeam, (ObjectGuid::LowType guid, uint8 slot, uint32 arenaTeamId), ());
MOCK_METHOD(void, UpdateGlobalNameData, (ObjectGuid::LowType guidLow, std::string const& oldName, std::string const& newName), ());
MOCK_METHOD(void, DeleteGlobalPlayerData, (ObjectGuid::LowType guid, std::string const& name), ());
MOCK_METHOD(void, ProcessCliCommands, ());
MOCK_METHOD(void, QueueCliCommand, (CliCommandHolder* commandHolder), ());
MOCK_METHOD(void, ForceGameEventUpdate, ());