From fc439dbed08cc850db80d7f1dab18c37d860f87b Mon Sep 17 00:00:00 2001 From: hondacrx Date: Thu, 1 Feb 2024 20:59:03 -0500 Subject: [PATCH] Core/DataStores: Don't send hotfix ids in SMSG_AVAILABLE_HOTFIXES that don't have a hotfix blob for client locale Port From (https://github.com/TrinityCore/TrinityCore/commit/973b5f404f5b7115239a81030ad2f8dff8e165ea) --- Source/Game/DataStorage/DB2Manager.cs | 33 ++++++++++++++++--- Source/Game/Handlers/HotfixHandler.cs | 20 +++++++++-- .../Game/Networking/Packets/HotfixPackets.cs | 14 +++----- Source/Game/World/WorldManager.cs | 2 +- 4 files changed, 52 insertions(+), 17 deletions(-) diff --git a/Source/Game/DataStorage/DB2Manager.cs b/Source/Game/DataStorage/DB2Manager.cs index e00e7a727..e2563e924 100644 --- a/Source/Game/DataStorage/DB2Manager.cs +++ b/Source/Game/DataStorage/DB2Manager.cs @@ -637,7 +637,7 @@ namespace Game.DataStorage return _storage.LookupByKey(type); } - public void LoadHotfixData() + public void LoadHotfixData(BitSet availableDb2Locales) { uint oldMSTime = Time.GetMSTime(); @@ -660,7 +660,17 @@ namespace Game.DataStorage HotfixRecord.Status status = (HotfixRecord.Status)result.Read(4); if (status == HotfixRecord.Status.Valid && !_storage.ContainsKey(tableHash)) { - if (!_hotfixBlob.Any(p => p.ContainsKey((tableHash, recordId)))) + var key = (tableHash, recordId); + for (int locale = 0; locale < (int)Locale.Total; ++locale) + { + if (!availableDb2Locales[locale]) + continue; + + if (!_hotfixBlob[locale].ContainsKey(key)) + availableDb2Locales[locale] = false; + } + + if (!availableDb2Locales.Any()) { Log.outError(LogFilter.Sql, $"Table `hotfix_data` references unknown DB2 store by hash 0x{tableHash:X} and has no reference to `hotfix_blob` in hotfix id {id} with RecordID: {recordId}"); continue; @@ -673,7 +683,13 @@ namespace Game.DataStorage hotfixRecord.ID.PushID = id; hotfixRecord.ID.UniqueID = uniqueId; hotfixRecord.HotfixStatus = status; - _hotfixData.Add(id, hotfixRecord); + hotfixRecord.AvailableLocalesMask = availableDb2Locales.ToBlockRange()[0];//Ulgy i know + + HotfixPush push = _hotfixData[id]; + push.Records.Add(hotfixRecord); + push.AvailableLocalesMask |= hotfixRecord.AvailableLocalesMask; + + _hotfixData.Add(id, push); deletedRecords[(tableHash, recordId)] = status == HotfixRecord.Status.RecordRemoved; ++count; @@ -812,7 +828,7 @@ namespace Game.DataStorage public uint GetHotfixCount() { return (uint)_hotfixData.Count; } - public MultiMap GetHotfixData() { return _hotfixData; } + public Dictionary GetHotfixData() { return _hotfixData; } public byte[] GetHotfixBlobData(uint tableHash, int recordId, Locale locale) { @@ -2219,7 +2235,7 @@ namespace Game.DataStorage delegate bool AllowedHotfixOptionalData(byte[] data); Dictionary _storage = new(); - MultiMap _hotfixData = new(); + Dictionary _hotfixData = new(); Dictionary<(uint tableHash, int recordId), byte[]>[] _hotfixBlob = new Dictionary<(uint tableHash, int recordId), byte[]>[(int)Locale.Total]; MultiMap> _allowedHotfixOptionalData = new(); MultiMap<(uint tableHash, int recordId), HotfixOptionalData>[] _hotfixOptionalData = new MultiMap<(uint tableHash, int recordId), HotfixOptionalData>[(int)Locale.Total]; @@ -2467,6 +2483,7 @@ namespace Game.DataStorage public int RecordID; public HotfixId ID; public Status HotfixStatus = Status.Invalid; + public uint AvailableLocalesMask; public void Write(WorldPacket data) { @@ -2516,6 +2533,12 @@ namespace Game.DataStorage public byte[] Data; } + public class HotfixPush + { + public List Records = new(); + public uint AvailableLocalesMask; + } + class ChrClassesXPowerTypesRecordComparer : IComparer { public int Compare(ChrClassesXPowerTypesRecord left, ChrClassesXPowerTypesRecord right) diff --git a/Source/Game/Handlers/HotfixHandler.cs b/Source/Game/Handlers/HotfixHandler.cs index 1c187e129..9dd37788b 100644 --- a/Source/Game/Handlers/HotfixHandler.cs +++ b/Source/Game/Handlers/HotfixHandler.cs @@ -5,6 +5,8 @@ using Framework.Constants; using Game.DataStorage; using Game.Networking; using Game.Networking.Packets; +using System.Linq; +using System.Collections.Generic; namespace Game { @@ -46,7 +48,18 @@ namespace Game void SendAvailableHotfixes() { - SendPacket(new AvailableHotfixes(Global.WorldMgr.GetRealmId().GetAddress(), Global.DB2Mgr.GetHotfixData())); + AvailableHotfixes availableHotfixes = new(); + availableHotfixes.VirtualRealmAddress = Global.WorldMgr.GetRealmId().GetAddress(); + + foreach (var (_, push) in Global.DB2Mgr.GetHotfixData()) + { + if ((push.AvailableLocalesMask & (1 << (int)GetSessionDbcLocale())) == 0) + continue; + + availableHotfixes.Hotfixes.Add(push.Records.First().ID); + } + + SendPacket(availableHotfixes); } [WorldPacketHandler(ClientOpcodes.HotfixRequest, Status = SessionStatus.Authed)] @@ -60,8 +73,11 @@ namespace Game var hotfixRecords = hotfixes.LookupByKey(hotfixId); if (hotfixRecords != null) { - foreach (var hotfixRecord in hotfixRecords) + foreach (var hotfixRecord in hotfixRecords.Records) { + if ((hotfixRecord.AvailableLocalesMask & (1 << (int)GetSessionDbcLocale())) == 0) + continue; + HotfixConnect.HotfixData hotfixData = new(); hotfixData.Record = hotfixRecord; if (hotfixRecord.HotfixStatus == HotfixRecord.Status.Valid) diff --git a/Source/Game/Networking/Packets/HotfixPackets.cs b/Source/Game/Networking/Packets/HotfixPackets.cs index b7cdff82d..2e7754d2d 100644 --- a/Source/Game/Networking/Packets/HotfixPackets.cs +++ b/Source/Game/Networking/Packets/HotfixPackets.cs @@ -61,23 +61,19 @@ namespace Game.Networking.Packets class AvailableHotfixes : ServerPacket { - public AvailableHotfixes(uint virtualRealmAddress, MultiMap hotfixes) : base(ServerOpcodes.AvailableHotfixes) - { - VirtualRealmAddress = virtualRealmAddress; - Hotfixes = hotfixes; - } + public AvailableHotfixes() : base(ServerOpcodes.AvailableHotfixes) { } public override void Write() { _worldPacket.WriteUInt32(VirtualRealmAddress); - _worldPacket.WriteInt32(Hotfixes.Keys.Count); + _worldPacket.WriteInt32(Hotfixes.Count); - foreach (var key in Hotfixes.Keys) - Hotfixes[key][0].ID.Write(_worldPacket); + foreach (var hotfixId in Hotfixes) + hotfixId.Write(_worldPacket); } public uint VirtualRealmAddress; - public MultiMap Hotfixes; + public List Hotfixes = new(); } class HotfixRequest : ClientPacket diff --git a/Source/Game/World/WorldManager.cs b/Source/Game/World/WorldManager.cs index a9d2bad1c..e04ddfb00 100644 --- a/Source/Game/World/WorldManager.cs +++ b/Source/Game/World/WorldManager.cs @@ -437,7 +437,7 @@ namespace Game Global.DB2Mgr.LoadHotfixBlob(m_availableDbcLocaleMask); Log.outInfo(LogFilter.ServerLoading, "Loading hotfix info..."); - Global.DB2Mgr.LoadHotfixData(); + Global.DB2Mgr.LoadHotfixData(m_availableDbcLocaleMask); Log.outInfo(LogFilter.ServerLoading, "Loading hotfix optional data..."); Global.DB2Mgr.LoadHotfixOptionalData(m_availableDbcLocaleMask);