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;
138 _characterCacheByNameStore.erase(oldName);
139 _characterCacheByNameStore[name] = &itr->second;
144 auto itr = _characterCacheStore.find(guid);
145 if (itr == _characterCacheStore.end())
148 itr->second.Level = level;
153 auto itr = _characterCacheStore.find(guid);
154 if (itr == _characterCacheStore.end())
157 itr->second.AccountId = accountId;
162 auto itr = _characterCacheStore.find(guid);
163 if (itr == _characterCacheStore.end())
166 itr->second.GuildId = guildId;
171 auto itr = _characterCacheStore.find(guid);
172 if (itr == _characterCacheStore.end())
176 itr->second.ArenaTeamId[slot] = arenaTeamId;
184 return _characterCacheStore.find(guid) != _characterCacheStore.end();
189 auto itr = _characterCacheStore.find(guid);
190 if (itr != _characterCacheStore.end())
198 auto itr = _characterCacheByNameStore.find(name);
199 if (itr != _characterCacheByNameStore.end())
207 auto itr = _characterCacheByNameStore.find(name);
208 if (itr != _characterCacheByNameStore.end())
209 return itr->second->Guid;
216 auto itr = _characterCacheStore.find(guid);
217 if (itr == _characterCacheStore.end())
220 name = itr->second.Name;
226 auto itr = _characterCacheStore.find(guid);
227 if (itr == _characterCacheStore.end())
235 auto itr = _characterCacheStore.find(guid);
236 if (itr == _characterCacheStore.end())
239 return itr->second.AccountId;
244 auto itr = _characterCacheByNameStore.find(name);
245 if (itr != _characterCacheByNameStore.end())
246 return itr->second->AccountId;
253 auto itr = _characterCacheStore.find(guid);
254 if (itr == _characterCacheStore.end())
257 return itr->second.Level;
262 auto itr = _characterCacheStore.find(guid);
263 if (itr == _characterCacheStore.end())
266 return itr->second.GuildId;
271 auto itr = _characterCacheStore.find(guid);
272 if (itr == _characterCacheStore.end())
277 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