26#include <unordered_map>
30 std::unordered_map<ObjectGuid, CharacterCacheEntry> _characterCacheStore;
31 std::unordered_map<std::string, CharacterCacheEntry*> _characterCacheByNameStore;
71 _characterCacheStore.clear();
77 TC_LOG_INFO(
"server.loading",
"No character name data loaded, empty query");
83 Field* fields = result->Fetch();
84 AddCharacterCacheEntry(ObjectGuid::Create<HighGuid::Player>(fields[0].GetUInt64()) , fields[2].GetUInt32() , fields[1].GetString() ,
85 fields[4].GetUInt8() , fields[3].GetUInt8() , fields[5].GetUInt8() , fields[6].GetUInt8() , fields[7].GetUInt32() != 0);
86 }
while (result->NextRow());
88 TC_LOG_INFO(
"server.loading",
"Loaded character infos for {} characters in {} ms", _characterCacheStore.size(),
GetMSTimeDiffToNow(oldMSTime));
102 data.
Class = playerClass;
111 _characterCacheByNameStore[name] = &data;
116 _characterCacheStore.erase(guid);
117 _characterCacheByNameStore.erase(name);
122 auto itr = _characterCacheStore.find(guid);
123 if (itr == _characterCacheStore.end())
126 std::string oldName = itr->second.Name;
127 itr->second.Name = name;
130 itr->second.Sex = *gender;
133 itr->second.Race = *race;
136 invalidatePlayer.
Guid = guid;
137 sWorld->SendGlobalMessage(invalidatePlayer.
Write());
140 _characterCacheByNameStore.erase(oldName);
141 _characterCacheByNameStore[name] = &itr->second;
146 auto itr = _characterCacheStore.find(guid);
147 if (itr == _characterCacheStore.end())
150 itr->second.Sex = gender;
155 auto itr = _characterCacheStore.find(guid);
156 if (itr == _characterCacheStore.end())
159 itr->second.Level = level;
164 auto itr = _characterCacheStore.find(guid);
165 if (itr == _characterCacheStore.end())
168 itr->second.AccountId = accountId;
173 auto itr = _characterCacheStore.find(guid);
174 if (itr == _characterCacheStore.end())
177 itr->second.GuildId = guildId;
182 auto itr = _characterCacheStore.find(guid);
183 if (itr == _characterCacheStore.end())
187 itr->second.ArenaTeamId[slot] = arenaTeamId;
192 auto itr = _characterCacheStore.find(guid);
193 if (itr == _characterCacheStore.end())
197 _characterCacheByNameStore.erase(itr->second.Name);
199 _characterCacheByNameStore[name] = &itr->second;
201 itr->second.Name = name;
202 itr->second.IsDeleted = deleted;
210 return _characterCacheStore.find(guid) != _characterCacheStore.end();
215 auto itr = _characterCacheStore.find(guid);
216 if (itr != _characterCacheStore.end())
224 auto itr = _characterCacheByNameStore.find(name);
225 if (itr != _characterCacheByNameStore.end())
233 auto itr = _characterCacheByNameStore.find(name);
234 if (itr != _characterCacheByNameStore.end())
235 return itr->second->Guid;
242 auto itr = _characterCacheStore.find(guid);
243 if (itr == _characterCacheStore.end())
246 name = itr->second.Name;
252 auto itr = _characterCacheStore.find(guid);
253 if (itr == _characterCacheStore.end())
261 auto itr = _characterCacheStore.find(guid);
262 if (itr == _characterCacheStore.end())
265 return itr->second.AccountId;
270 auto itr = _characterCacheByNameStore.find(name);
271 if (itr != _characterCacheByNameStore.end())
272 return itr->second->AccountId;
279 auto itr = _characterCacheStore.find(guid);
280 if (itr == _characterCacheStore.end())
283 return itr->second.Level;
288 auto itr = _characterCacheStore.find(guid);
289 if (itr == _characterCacheStore.end())
292 return itr->second.GuildId;
297 auto itr = _characterCacheStore.find(guid);
298 if (itr == _characterCacheStore.end())
303 return itr->second.ArenaTeamId[slot];
308 auto itr = _characterCacheStore.find(guid);
309 if (itr == _characterCacheStore.end())
312 name = itr->second.Name;
313 _class = itr->second.Class;
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.
if(posix_memalign(&__mallocedMemory, __align, __size)) return NULL
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
static uint8 GetSlotByType(uint32 type)
ObjectGuid GetCharacterGuidByName(std::string const &name) const
uint8 GetCharacterLevelByGuid(ObjectGuid guid) const
bool GetCharacterNameAndClassByGUID(ObjectGuid guid, std::string &name, uint8 &_class) const
void UpdateCharacterAccountId(ObjectGuid const &guid, uint32 accountId)
bool HasCharacterCacheEntry(ObjectGuid const &guid) const
void AddCharacterCacheEntry(ObjectGuid const &guid, uint32 accountId, std::string const &name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, bool isDeleted)
CharacterCacheEntry const * GetCharacterCacheByName(std::string const &name) const
static CharacterCache * instance()
void UpdateCharacterGender(ObjectGuid const &guid, uint8 gender)
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={})
Team GetCharacterTeamByGuid(ObjectGuid guid) const
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)
void UpdateCharacterInfoDeleted(ObjectGuid const &guid, bool deleted, std::string const &name)
bool GetCharacterNameByGuid(ObjectGuid guid, std::string &name) const
Class used to access individual fields of database query result.
static ObjectGuid const Empty
static Team TeamForRace(uint8 race)
WorldPacket const * Write() override
ObjectGuid::LowType GuildId