Core/Players: Fixed CharacterCache by-name storage holding data for deleted characters

Port From (https://github.com/TrinityCore/TrinityCore/commit/d03e0d69353852636e12911a7f7149cb0bca40ef)
This commit is contained in:
hondacrx
2024-02-06 16:05:00 -05:00
parent 3ec159ebe1
commit 1fc1153f67
2 changed files with 12 additions and 7 deletions
+11 -6
View File
@@ -51,7 +51,8 @@ namespace Game.Cache
data.IsDeleted = isDeleted; data.IsDeleted = isDeleted;
// Fill Name to Guid Store // Fill Name to Guid Store
_characterCacheByNameStore[name] = data; if (!isDeleted)
_characterCacheByNameStore[name] = data;
_characterCacheStore[guid] = data; _characterCacheStore[guid] = data;
} }
@@ -92,7 +93,7 @@ namespace Game.Cache
_characterCacheStore[guid].Sex = (Gender)gender; _characterCacheStore[guid].Sex = (Gender)gender;
} }
public void UpdateCharacterLevel(ObjectGuid guid, byte level) public void UpdateCharacterLevel(ObjectGuid guid, byte level)
{ {
if (!_characterCacheStore.ContainsKey(guid)) if (!_characterCacheStore.ContainsKey(guid))
@@ -125,14 +126,18 @@ namespace Game.Cache
_characterCacheStore[guid].ArenaTeamId[slot] = arenaTeamId; _characterCacheStore[guid].ArenaTeamId[slot] = arenaTeamId;
} }
public void UpdateCharacterInfoDeleted(ObjectGuid guid, bool deleted, string name = null) public void UpdateCharacterInfoDeleted(ObjectGuid guid, bool deleted, string name)
{ {
if (!_characterCacheStore.ContainsKey(guid)) if (!_characterCacheStore.TryGetValue(guid, out var cacheEntry))
return; return;
if (deleted)
_characterCacheByNameStore.Remove(cacheEntry.Name);
else
_characterCacheByNameStore[name] = cacheEntry;
_characterCacheStore[guid].Name = name;
_characterCacheStore[guid].IsDeleted = deleted; _characterCacheStore[guid].IsDeleted = deleted;
if (!name.IsEmpty())
_characterCacheStore[guid].Name = name;
} }
public bool HasCharacterCacheEntry(ObjectGuid guid) public bool HasCharacterCacheEntry(ObjectGuid guid)
+1 -1
View File
@@ -4521,7 +4521,7 @@ namespace Game.Entities
stmt.AddValue(0, guid); stmt.AddValue(0, guid);
trans.Append(stmt); trans.Append(stmt);
Global.CharacterCacheStorage.UpdateCharacterInfoDeleted(playerGuid, true); Global.CharacterCacheStorage.UpdateCharacterInfoDeleted(playerGuid, true, "");
break; break;
} }
default: default: