Core/PacketIO: Fixed receiving and sending db2 hotfix packets

Port From (https://github.com/TrinityCore/TrinityCore/commit/5fce3604fc9613299f8780d30abbbe69c0c7e531)
This commit is contained in:
hondacrx
2020-06-18 13:10:45 -04:00
parent 802cda4c01
commit 2d5a910f67
5 changed files with 312 additions and 313 deletions
File diff suppressed because it is too large Load Diff
+29 -3
View File
@@ -18,6 +18,7 @@
using Framework.Constants;
using Framework.Database;
using Framework.GameMath;
using Game.Network;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -657,7 +658,11 @@ namespace Game.DataStorage
continue;
}
_hotfixData.Add(id, Tuple.Create(tableHash, recordId));
HotfixRecord hotfixRecord = new HotfixRecord();
hotfixRecord.TableHash = tableHash;
hotfixRecord.RecordID = recordId;
hotfixRecord.HotfixID = id;
_hotfixData.Add(hotfixRecord);
++_hotfixCount;
deletedRecords[Tuple.Create(tableHash, recordId)] = deleted;
@@ -707,7 +712,7 @@ namespace Game.DataStorage
}
public uint GetHotfixCount() { return _hotfixCount; }
public MultiMap<int, Tuple<uint, int>> GetHotfixData() { return _hotfixData; }
public List<HotfixRecord> GetHotfixData() { return _hotfixData; }
public byte[] GetHotfixBlobData(uint tableHash, int recordId)
{
@@ -2050,7 +2055,7 @@ namespace Game.DataStorage
Dictionary<uint, IDB2Storage> _storage = new Dictionary<uint, IDB2Storage>();
uint _hotfixCount = 0;
MultiMap<int, Tuple<uint, int>> _hotfixData = new MultiMap<int, Tuple<uint, int>>();
List<HotfixRecord> _hotfixData = new List<HotfixRecord>();
Dictionary<Tuple<uint, int>, byte[]> _hotfixBlob = new Dictionary<Tuple<uint, int>, byte[]>();
MultiMap<uint, uint> _areaGroupMembers = new MultiMap<uint, uint>();
@@ -2282,6 +2287,27 @@ namespace Game.DataStorage
}
}
public struct HotfixRecord
{
public uint TableHash;
public int RecordID;
public int HotfixID;
public void Write(WorldPacket data)
{
data.WriteUInt32(TableHash);
data.WriteInt32(RecordID);
data.WriteInt32(HotfixID);
}
public void Read(WorldPacket data)
{
TableHash = data.ReadUInt32();
RecordID = data.ReadInt32();
HotfixID = data.ReadInt32();
}
}
class ChrClassesXPowerTypesRecordComparer : IComparer<ChrClassesXPowerTypesRecord>
{
public int Compare(ChrClassesXPowerTypesRecord left, ChrClassesXPowerTypesRecord right)
+20 -24
View File
@@ -70,33 +70,29 @@ namespace Game
HotfixResponse hotfixQueryResponse = new HotfixResponse();
foreach (HotfixRecord hotfixRecord in hotfixQuery.Hotfixes)
{
var hotfixedRecords = hotfixes.LookupByKey(hotfixRecord.HotfixID);
if (!hotfixedRecords.Empty())
if (hotfixes.Contains(hotfixRecord))
{
foreach (var tableRecord in hotfixedRecords)
var storage = Global.DB2Mgr.GetStorage(hotfixRecord.TableHash);
HotfixResponse.HotfixData hotfixData = new HotfixResponse.HotfixData();
hotfixData.Record = hotfixRecord;
if (storage != null && storage.HasRecord((uint)hotfixRecord.RecordID))
{
var storage = Global.DB2Mgr.GetStorage(hotfixRecord.TableHash);
HotfixResponse.HotfixData hotfixData = new HotfixResponse.HotfixData();
hotfixData.Record = hotfixRecord;
if (storage != null && storage.HasRecord((uint)hotfixData.Record.RecordID))
{
uint pos = hotfixQueryResponse.HotfixContent.GetSize();
storage.WriteRecord((uint)hotfixData.Record.RecordID, GetSessionDbcLocale(), hotfixQueryResponse.HotfixContent);
hotfixData.Size.Set(hotfixQueryResponse.HotfixContent.GetSize() - pos);
}
else
{
byte[] blobData = Global.DB2Mgr.GetHotfixBlobData(hotfixData.Record.TableHash, hotfixData.Record.RecordID);
if (blobData != null)
{
hotfixData.Size.Set((uint)blobData.Length);
hotfixQueryResponse.HotfixContent.WriteBytes(blobData);
}
}
hotfixQueryResponse.Hotfixes.Add(hotfixData);
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);
if (blobData != null)
{
hotfixData.Size.Set((uint)blobData.Length);
hotfixQueryResponse.HotfixContent.WriteBytes(blobData);
}
}
hotfixQueryResponse.Hotfixes.Add(hotfixData);
}
}
+1 -1
View File
@@ -240,6 +240,6 @@ namespace Game.Network
byteBuffer.WriteBytes(Tag, 12);
}
public bool IsValidSize() { return Size < 0x10000; }
public bool IsValidSize() { return Size < 0x40000; }
}
}
+10 -33
View File
@@ -21,6 +21,7 @@ using Framework.IO;
using Game.Entities;
using System.Collections.Generic;
using System;
using Game.DataStorage;
namespace Game.Network.Packets
{
@@ -77,7 +78,7 @@ namespace Game.Network.Packets
class AvailableHotfixes : ServerPacket
{
public AvailableHotfixes(int hotfixCacheVersion, uint hotfixCount, MultiMap<int, Tuple<uint, int>> hotfixes) : base(ServerOpcodes.AvailableHotfixes)
public AvailableHotfixes(int hotfixCacheVersion, uint hotfixCount, List<HotfixRecord> hotfixes) : base(ServerOpcodes.AvailableHotfixes)
{
HotfixCacheVersion = hotfixCacheVersion;
HotfixCount = hotfixCount;
@@ -89,20 +90,13 @@ namespace Game.Network.Packets
_worldPacket.WriteInt32(HotfixCacheVersion);
_worldPacket.WriteUInt32(HotfixCount);
foreach (var key in Hotfixes.Keys)
{
foreach (var tableRecord in Hotfixes[key])
{
_worldPacket.WriteUInt32(tableRecord.Item1);
_worldPacket.WriteInt32(tableRecord.Item2);
_worldPacket.WriteInt32(key);
}
}
foreach (HotfixRecord hotfixRecord in Hotfixes)
hotfixRecord.Write(_worldPacket);
}
public int HotfixCacheVersion;
public uint HotfixCount;
public MultiMap<int, Tuple<uint, int>> Hotfixes;
public List<HotfixRecord> Hotfixes;
}
class HotfixRequest : ClientPacket
@@ -116,7 +110,11 @@ namespace Game.Network.Packets
uint hotfixCount = _worldPacket.ReadUInt32();
for (var i = 0; i < hotfixCount; ++i)
Hotfixes.Add(new HotfixRecord(_worldPacket));
{
HotfixRecord hotfixRecord = new HotfixRecord();
hotfixRecord.Read(_worldPacket);
Hotfixes.Add(hotfixRecord);
}
}
public uint ClientBuild;
@@ -163,25 +161,4 @@ namespace Game.Network.Packets
public Optional<uint> Size;
}
}
public struct HotfixRecord
{
public HotfixRecord(WorldPacket data)
{
TableHash = data.ReadUInt32();
RecordID = data.ReadInt32();
HotfixID = data.ReadInt32();
}
public void Write(WorldPacket data)
{
data.WriteUInt32(TableHash);
data.WriteInt32(RecordID);
data.WriteInt32(HotfixID);
}
public uint TableHash;
public int RecordID;
public int HotfixID;
}
}