From 7b5f4e610c46b67e170117242c4927225e394f5b Mon Sep 17 00:00:00 2001 From: hondacrx Date: Thu, 4 Mar 2021 14:10:23 -0500 Subject: [PATCH] Core/DataStores: Support all new hotfix status values Port From (https://github.com/TrinityCore/TrinityCore/commit/c86cffe5ef95d87929d954abe36d96fe9edb68e3) --- Source/Game/DataStorage/DB2Manager.cs | 19 +++++--- Source/Game/Handlers/HotfixHandler.cs | 45 ++++++++++--------- .../Game/Networking/Packets/HotfixPackets.cs | 16 ++----- 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/Source/Game/DataStorage/DB2Manager.cs b/Source/Game/DataStorage/DB2Manager.cs index 32cdb4482..4e58c9f22 100644 --- a/Source/Game/DataStorage/DB2Manager.cs +++ b/Source/Game/DataStorage/DB2Manager.cs @@ -703,7 +703,7 @@ namespace Game.DataStorage { uint oldMSTime = Time.GetMSTime(); - SQLResult result = DB.Hotfix.Query("SELECT Id, TableHash, RecordId, Deleted FROM hotfix_data ORDER BY Id"); + SQLResult result = DB.Hotfix.Query("SELECT Id, TableHash, RecordId, Status FROM hotfix_data ORDER BY Id"); if (result.IsEmpty()) { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 hotfix info entries."); @@ -718,8 +718,8 @@ namespace Game.DataStorage int id = result.Read(0); uint tableHash = result.Read(1); int recordId = result.Read(2); - bool deleted = result.Read(3); - if (!deleted && !_storage.ContainsKey(tableHash)) + HotfixRecord.Status status = (HotfixRecord.Status)result.Read(3); + if (status == HotfixRecord.Status.Valid && !_storage.ContainsKey(tableHash)) { if (!_hotfixBlob.Any(p => p.ContainsKey((tableHash, recordId)))) { @@ -733,8 +733,9 @@ namespace Game.DataStorage hotfixRecord.TableHash = tableHash; hotfixRecord.RecordID = recordId; hotfixRecord.HotfixID = id; + hotfixRecord.HotfixStatus = status; _hotfixData.Add(hotfixRecord); - deletedRecords[(tableHash, recordId)] = deleted; + deletedRecords[(tableHash, recordId)] = status == HotfixRecord.Status.RecordRemoved; ++count; } while (result.NextRow()); @@ -2512,11 +2513,12 @@ namespace Game.DataStorage } } - public struct HotfixRecord + public class HotfixRecord { public uint TableHash; public int RecordID; public int HotfixID; + public Status HotfixStatus = Status.Invalid; public void Write(WorldPacket data) { @@ -2531,6 +2533,13 @@ namespace Game.DataStorage RecordID = data.ReadInt32(); HotfixID = data.ReadInt32(); } + + public enum Status + { + Valid = 1, + RecordRemoved = 2, + Invalid = 3 + } } public class HotfixOptionalData diff --git a/Source/Game/Handlers/HotfixHandler.cs b/Source/Game/Handlers/HotfixHandler.cs index ce3a89a6d..506efe30f 100644 --- a/Source/Game/Handlers/HotfixHandler.cs +++ b/Source/Game/Handlers/HotfixHandler.cs @@ -72,33 +72,36 @@ namespace Game HotfixConnect hotfixQueryResponse = new HotfixConnect(); foreach (HotfixRecord hotfixRecord in hotfixQuery.Hotfixes) { - if (hotfixes.Contains(hotfixRecord)) + var serverHotfixIndex = hotfixes.IndexOf(hotfixRecord); + if (serverHotfixIndex != -1) { - var storage = Global.DB2Mgr.GetStorage(hotfixRecord.TableHash); - HotfixConnect.HotfixData hotfixData = new HotfixConnect.HotfixData(); - hotfixData.Record = hotfixRecord; - if (storage != null && storage.HasRecord((uint)hotfixRecord.RecordID)) + hotfixData.Record = hotfixes[serverHotfixIndex]; + if (hotfixData.Record.HotfixStatus == HotfixRecord.Status.Valid) { - uint pos = hotfixQueryResponse.HotfixContent.GetSize(); - storage.WriteRecord((uint)hotfixRecord.RecordID, GetSessionDbcLocale(), hotfixQueryResponse.HotfixContent); - - var optionalDataEntries = Global.DB2Mgr.GetHotfixOptionalData(hotfixRecord.TableHash, (uint)hotfixRecord.RecordID, GetSessionDbcLocale()); - foreach (HotfixOptionalData optionalData in optionalDataEntries) + var storage = Global.DB2Mgr.GetStorage(hotfixRecord.TableHash); + if (storage != null && storage.HasRecord((uint)hotfixRecord.RecordID)) { - hotfixQueryResponse.HotfixContent.WriteUInt32(optionalData.Key); - hotfixQueryResponse.HotfixContent.WriteBytes(optionalData.Data); - } + uint pos = hotfixQueryResponse.HotfixContent.GetSize(); + storage.WriteRecord((uint)hotfixRecord.RecordID, GetSessionDbcLocale(), hotfixQueryResponse.HotfixContent); - hotfixData.Size.Set(hotfixQueryResponse.HotfixContent.GetSize() - pos); - } - else - { - byte[] blobData = Global.DB2Mgr.GetHotfixBlobData(hotfixRecord.TableHash, hotfixRecord.RecordID, GetSessionDbcLocale()); - if (blobData != null) + var optionalDataEntries = Global.DB2Mgr.GetHotfixOptionalData(hotfixRecord.TableHash, (uint)hotfixRecord.RecordID, GetSessionDbcLocale()); + foreach (HotfixOptionalData optionalData in optionalDataEntries) + { + hotfixQueryResponse.HotfixContent.WriteUInt32(optionalData.Key); + hotfixQueryResponse.HotfixContent.WriteBytes(optionalData.Data); + } + + hotfixData.Size = hotfixQueryResponse.HotfixContent.GetSize() - pos; + } + else { - hotfixData.Size.Set((uint)blobData.Length); - hotfixQueryResponse.HotfixContent.WriteBytes(blobData); + byte[] blobData = Global.DB2Mgr.GetHotfixBlobData(hotfixRecord.TableHash, hotfixRecord.RecordID, GetSessionDbcLocale()); + if (blobData != null) + { + hotfixData.Size = (uint)blobData.Length; + hotfixQueryResponse.HotfixContent.WriteBytes(blobData); + } } } diff --git a/Source/Game/Networking/Packets/HotfixPackets.cs b/Source/Game/Networking/Packets/HotfixPackets.cs index 1613325f0..8e891e9a4 100644 --- a/Source/Game/Networking/Packets/HotfixPackets.cs +++ b/Source/Game/Networking/Packets/HotfixPackets.cs @@ -144,21 +144,13 @@ namespace Game.Networking.Packets public void Write(WorldPacket data) { Record.Write(data); - if (Size.HasValue) - { - data.WriteUInt32(Size.Value); - data.WriteBits(1, 2); - } - else - { - data.WriteUInt32(0); - data.WriteBits(3, 2); - } + data.WriteUInt32(Size); + data.WriteBits((byte)Record.HotfixStatus, 2); data.FlushBits(); } - public HotfixRecord Record; - public Optional Size; + public HotfixRecord Record = new HotfixRecord(); + public uint Size; } } }