From 42a902c118055045e96e18ee840655568e620b53 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 2 May 2023 17:22:16 -0400 Subject: [PATCH] Core/Realms: Remove duplicate realm names storage Port From (https://github.com/TrinityCore/TrinityCore/commit/7f5e47c396e49da2530aabac05f7ca3c0f177298) --- Source/Framework/Realm/RealmManager.cs | 16 +++++++++- Source/Game/Globals/ObjectManager.cs | 42 -------------------------- Source/Game/Handlers/QueryHandler.cs | 4 +-- Source/Game/World/WorldManager.cs | 3 -- 4 files changed, 17 insertions(+), 48 deletions(-) diff --git a/Source/Framework/Realm/RealmManager.cs b/Source/Framework/Realm/RealmManager.cs index eacaafe34..9fac67866 100644 --- a/Source/Framework/Realm/RealmManager.cs +++ b/Source/Framework/Realm/RealmManager.cs @@ -139,7 +139,21 @@ public class RealmManager : Singleton return _realms.LookupByKey(id); } - public RealmBuildInfo GetBuildInfo(uint build) + public bool GetRealmNames(RealmId id, out string name, out string normalizedName) + { + name = null; + normalizedName = null; + + Realm realm = GetRealm(id); + if (realm == null) + return false; + + name = realm.Name; + normalizedName = realm.NormalizedName; + return true; + } + +public RealmBuildInfo GetBuildInfo(uint build) { foreach (var clientBuild in _builds) if (clientBuild.Build == build) diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index d1ca009ca..48ae8784d 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -436,32 +436,6 @@ namespace Game else Log.outInfo(LogFilter.ServerLoading, "Loaded 0 class expansion requirements. DB table `class_expansion_requirement` is empty."); } - public void LoadRealmNames() - { - uint oldMSTime = Time.GetMSTime(); - _realmNameStorage.Clear(); - - // 0 1 - SQLResult result = DB.Login.Query("SELECT id, name FROM `realmlist`"); - if (result.IsEmpty()) - { - Log.outInfo(LogFilter.ServerLoading, "Loaded 0 realm names. DB table `realmlist` is empty."); - return; - } - - uint count = 0; - do - { - uint realm = result.Read(0); - string realmName = result.Read(1); - - _realmNameStorage[realm] = realmName; - - ++count; - } - while (result.NextRow()); - Log.outInfo(LogFilter.ServerLoading, "Loaded {0} realm names in {1} ms.", count, Time.GetMSTimeDiffToNow(oldMSTime)); - } public string GetCypherString(uint entry, Locale locale = Locale.enUS) { @@ -482,21 +456,6 @@ namespace Game return GetCypherString((uint)cmd, locale); } - public string GetRealmName(uint realm) - { - return _realmNameStorage.LookupByKey(realm); - } - public bool GetRealmName(uint realmId, ref string name, ref string normalizedName) - { - var realmName = _realmNameStorage.LookupByKey(realmId); - if (realmName != null) - { - name = realmName; - normalizedName = realmName.Normalize(); - return true; - } - return false; - } public Dictionary GetRaceUnlockRequirements() { return _raceUnlockRequirementStorage; } public RaceUnlockRequirement GetRaceUnlockRequirement(Race race) { return _raceUnlockRequirementStorage.LookupByKey((byte)race); } public List GetClassExpansionRequirements() { return _classExpansionRequirementStorage; } @@ -11000,7 +10959,6 @@ namespace Game Dictionary _raceUnlockRequirementStorage = new(); List _classExpansionRequirementStorage = new(); - Dictionary _realmNameStorage = new(); //Quest Dictionary _questTemplates = new(); diff --git a/Source/Game/Handlers/QueryHandler.cs b/Source/Game/Handlers/QueryHandler.cs index c759f6648..52049f82d 100644 --- a/Source/Game/Handlers/QueryHandler.cs +++ b/Source/Game/Handlers/QueryHandler.cs @@ -346,11 +346,11 @@ namespace Game realmQueryResponse.VirtualRealmAddress = queryRealmName.VirtualRealmAddress; RealmId realmHandle = new(queryRealmName.VirtualRealmAddress); - if (Global.ObjectMgr.GetRealmName(realmHandle.Index, ref realmQueryResponse.NameInfo.RealmNameActual, ref realmQueryResponse.NameInfo.RealmNameNormalized)) + if (Global.RealmMgr.GetRealmNames(realmHandle, out realmQueryResponse.NameInfo.RealmNameActual, out realmQueryResponse.NameInfo.RealmNameNormalized)) { realmQueryResponse.LookupState = (byte)ResponseCodes.Success; realmQueryResponse.NameInfo.IsInternalRealm = false; - realmQueryResponse.NameInfo.IsLocal = queryRealmName.VirtualRealmAddress == Global.WorldMgr.GetRealm().Id.GetAddress(); + realmQueryResponse.NameInfo.IsLocal = queryRealmName.VirtualRealmAddress == Global.WorldMgr.GetVirtualRealmAddress(); } else realmQueryResponse.LookupState = (byte)ResponseCodes.Failure; diff --git a/Source/Game/World/WorldManager.cs b/Source/Game/World/WorldManager.cs index e2d8249e3..1a176d66f 100644 --- a/Source/Game/World/WorldManager.cs +++ b/Source/Game/World/WorldManager.cs @@ -1104,9 +1104,6 @@ namespace Game Log.outInfo(LogFilter.ServerLoading, "Loading character templates..."); Global.CharacterTemplateDataStorage.LoadCharacterTemplates(); - Log.outInfo(LogFilter.ServerLoading, "Loading realm names..."); - Global.ObjectMgr.LoadRealmNames(); - Log.outInfo(LogFilter.ServerLoading, "Loading battle pets info..."); BattlePetMgr.Initialize();