27#include <unordered_map>
31 std::unordered_map<ObjectGuid, CharacterCacheEntry> _characterCacheStore;
32 std::unordered_map<std::string, CharacterCacheEntry*> _characterCacheByNameStore;
72 _characterCacheStore.clear();
78 TC_LOG_INFO(
"server.loading",
"No character name data loaded, empty query");
84 Field* fields = result->Fetch();
85 AddCharacterCacheEntry(ObjectGuid::Create<HighGuid::Player>(fields[0].GetUInt32()) , fields[2].GetUInt32() , fields[1].GetString() ,
86 fields[4].GetUInt8() , fields[3].GetUInt8() , fields[5].GetUInt8() , fields[6].GetUInt8() );
87 }
while (result->NextRow());
89 TC_LOG_INFO(
"server.loading",
"Loaded character infos for {} characters in {} ms", _characterCacheStore.size(),
GetMSTimeDiffToNow(oldMSTime));
103 data.
Class = playerClass;
110 _characterCacheByNameStore[name] = &data;
115 _characterCacheStore.erase(guid);
116 _characterCacheByNameStore.erase(name);
121 auto itr = _characterCacheStore.find(guid);
122 if (itr == _characterCacheStore.end())
125 std::string oldName = itr->second.
Name;
126 itr->second.Name = name;
129 itr->second.Sex = *gender;
132 itr->second.Race = *race;
135 invalidatePlayer.
Guid = guid;
136 sWorld->SendGlobalMessage(invalidatePlayer.
Write());
139 _characterCacheByNameStore.erase(oldName);
140 _characterCacheByNameStore[name] = &itr->second;
145 auto itr = _characterCacheStore.find(guid);
146 if (itr == _characterCacheStore.end())
149 itr->second.Level = level;
154 auto itr = _characterCacheStore.find(guid);
155 if (itr == _characterCacheStore.end())
158 itr->second.AccountId = accountId;
163 auto itr = _characterCacheStore.find(guid);
164 if (itr == _characterCacheStore.end())
167 itr->second.GuildId = guildId;
172 auto itr = _characterCacheStore.find(guid);
173 if (itr == _characterCacheStore.end())
177 itr->second.ArenaTeamId[slot] = arenaTeamId;
185 return _characterCacheStore.find(guid) != _characterCacheStore.end();
190 auto itr = _characterCacheStore.find(guid);
191 if (itr != _characterCacheStore.end())
199 auto itr = _characterCacheByNameStore.find(name);
200 if (itr != _characterCacheByNameStore.end())
208 auto itr = _characterCacheByNameStore.find(name);
209 if (itr != _characterCacheByNameStore.end())
210 return itr->second->Guid;
217 auto itr = _characterCacheStore.find(guid);
218 if (itr == _characterCacheStore.end())
221 name = itr->second.Name;
227 auto itr = _characterCacheStore.find(guid);
228 if (itr == _characterCacheStore.end())
236 auto itr = _characterCacheStore.find(guid);
237 if (itr == _characterCacheStore.end())
240 return itr->second.AccountId;
245 auto itr = _characterCacheByNameStore.find(name);
246 if (itr != _characterCacheByNameStore.end())
247 return itr->second->AccountId;
254 auto itr = _characterCacheStore.find(guid);
255 if (itr == _characterCacheStore.end())
258 return itr->second.Level;
263 auto itr = _characterCacheStore.find(guid);
264 if (itr == _characterCacheStore.end())
267 return itr->second.GuildId;
272 auto itr = _characterCacheStore.find(guid);
273 if (itr == _characterCacheStore.end())
278 return itr->second.ArenaTeamId[slot];
std::shared_ptr< ResultSet > QueryResult
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
#define TC_LOG_INFO(filterType__,...)
std::optional< T > Optional
Optional helper class to wrap optional values within.
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
static uint8 GetSlotByType(uint32 type)
uint32 GetCharacterTeamByGuid(ObjectGuid guid) const
ObjectGuid GetCharacterGuidByName(std::string const &name) const
uint8 GetCharacterLevelByGuid(ObjectGuid guid) const
void AddCharacterCacheEntry(ObjectGuid const &guid, uint32 accountId, std::string const &name, uint8 gender, uint8 race, uint8 playerClass, uint8 level)
void UpdateCharacterAccountId(ObjectGuid const &guid, uint32 accountId)
bool HasCharacterCacheEntry(ObjectGuid const &guid) const
CharacterCacheEntry const * GetCharacterCacheByName(std::string const &name) const
static CharacterCache * instance()
void DeleteCharacterCacheEntry(ObjectGuid const &guid, std::string const &name)
uint32 GetCharacterAccountIdByGuid(ObjectGuid guid) const
void UpdateCharacterData(ObjectGuid const &guid, std::string const &name, Optional< uint8 > gender={}, Optional< uint8 > race={})
uint32 GetCharacterArenaTeamIdByGuid(ObjectGuid guid, uint8 type) const
void UpdateCharacterLevel(ObjectGuid const &guid, uint8 level)
uint32 GetCharacterAccountIdByName(std::string const &name) const
void LoadCharacterCacheStorage()
Loads several pieces of information on server startup with the GUID There is no further database quer...
CharacterCacheEntry const * GetCharacterCacheByGuid(ObjectGuid const &guid) const
ObjectGuid::LowType GetCharacterGuildIdByGuid(ObjectGuid guid) const
void UpdateCharacterGuildId(ObjectGuid const &guid, ObjectGuid::LowType guildId)
void UpdateCharacterArenaTeamId(ObjectGuid const &guid, uint8 slot, uint32 arenaTeamId)
bool GetCharacterNameByGuid(ObjectGuid guid, std::string &name) const
Class used to access individual fields of database query result.
static ObjectGuid const Empty
static uint32 TeamForRace(uint8 race)
WorldPacket const * Write() override
ObjectGuid::LowType GuildId