Core/DataStores: Support all new hotfix status values

Port From (https://github.com/TrinityCore/TrinityCore/commit/c86cffe5ef95d87929d954abe36d96fe9edb68e3)
This commit is contained in:
hondacrx
2021-03-04 14:10:23 -05:00
parent ac2c1c5191
commit 7b5f4e610c
3 changed files with 42 additions and 38 deletions
+14 -5
View File
@@ -703,7 +703,7 @@ namespace Game.DataStorage
{ {
uint oldMSTime = Time.GetMSTime(); 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()) if (result.IsEmpty())
{ {
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 hotfix info entries."); Log.outInfo(LogFilter.ServerLoading, "Loaded 0 hotfix info entries.");
@@ -718,8 +718,8 @@ namespace Game.DataStorage
int id = result.Read<int>(0); int id = result.Read<int>(0);
uint tableHash = result.Read<uint>(1); uint tableHash = result.Read<uint>(1);
int recordId = result.Read<int>(2); int recordId = result.Read<int>(2);
bool deleted = result.Read<bool>(3); HotfixRecord.Status status = (HotfixRecord.Status)result.Read<byte>(3);
if (!deleted && !_storage.ContainsKey(tableHash)) if (status == HotfixRecord.Status.Valid && !_storage.ContainsKey(tableHash))
{ {
if (!_hotfixBlob.Any(p => p.ContainsKey((tableHash, recordId)))) if (!_hotfixBlob.Any(p => p.ContainsKey((tableHash, recordId))))
{ {
@@ -733,8 +733,9 @@ namespace Game.DataStorage
hotfixRecord.TableHash = tableHash; hotfixRecord.TableHash = tableHash;
hotfixRecord.RecordID = recordId; hotfixRecord.RecordID = recordId;
hotfixRecord.HotfixID = id; hotfixRecord.HotfixID = id;
hotfixRecord.HotfixStatus = status;
_hotfixData.Add(hotfixRecord); _hotfixData.Add(hotfixRecord);
deletedRecords[(tableHash, recordId)] = deleted; deletedRecords[(tableHash, recordId)] = status == HotfixRecord.Status.RecordRemoved;
++count; ++count;
} while (result.NextRow()); } while (result.NextRow());
@@ -2512,11 +2513,12 @@ namespace Game.DataStorage
} }
} }
public struct HotfixRecord public class HotfixRecord
{ {
public uint TableHash; public uint TableHash;
public int RecordID; public int RecordID;
public int HotfixID; public int HotfixID;
public Status HotfixStatus = Status.Invalid;
public void Write(WorldPacket data) public void Write(WorldPacket data)
{ {
@@ -2531,6 +2533,13 @@ namespace Game.DataStorage
RecordID = data.ReadInt32(); RecordID = data.ReadInt32();
HotfixID = data.ReadInt32(); HotfixID = data.ReadInt32();
} }
public enum Status
{
Valid = 1,
RecordRemoved = 2,
Invalid = 3
}
} }
public class HotfixOptionalData public class HotfixOptionalData
+24 -21
View File
@@ -72,33 +72,36 @@ namespace Game
HotfixConnect hotfixQueryResponse = new HotfixConnect(); HotfixConnect hotfixQueryResponse = new HotfixConnect();
foreach (HotfixRecord hotfixRecord in hotfixQuery.Hotfixes) 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(); HotfixConnect.HotfixData hotfixData = new HotfixConnect.HotfixData();
hotfixData.Record = hotfixRecord; hotfixData.Record = hotfixes[serverHotfixIndex];
if (storage != null && storage.HasRecord((uint)hotfixRecord.RecordID)) if (hotfixData.Record.HotfixStatus == HotfixRecord.Status.Valid)
{ {
uint pos = hotfixQueryResponse.HotfixContent.GetSize(); var storage = Global.DB2Mgr.GetStorage(hotfixRecord.TableHash);
storage.WriteRecord((uint)hotfixRecord.RecordID, GetSessionDbcLocale(), hotfixQueryResponse.HotfixContent); if (storage != null && storage.HasRecord((uint)hotfixRecord.RecordID))
var optionalDataEntries = Global.DB2Mgr.GetHotfixOptionalData(hotfixRecord.TableHash, (uint)hotfixRecord.RecordID, GetSessionDbcLocale());
foreach (HotfixOptionalData optionalData in optionalDataEntries)
{ {
hotfixQueryResponse.HotfixContent.WriteUInt32(optionalData.Key); uint pos = hotfixQueryResponse.HotfixContent.GetSize();
hotfixQueryResponse.HotfixContent.WriteBytes(optionalData.Data); storage.WriteRecord((uint)hotfixRecord.RecordID, GetSessionDbcLocale(), hotfixQueryResponse.HotfixContent);
}
hotfixData.Size.Set(hotfixQueryResponse.HotfixContent.GetSize() - pos); var optionalDataEntries = Global.DB2Mgr.GetHotfixOptionalData(hotfixRecord.TableHash, (uint)hotfixRecord.RecordID, GetSessionDbcLocale());
} foreach (HotfixOptionalData optionalData in optionalDataEntries)
else {
{ hotfixQueryResponse.HotfixContent.WriteUInt32(optionalData.Key);
byte[] blobData = Global.DB2Mgr.GetHotfixBlobData(hotfixRecord.TableHash, hotfixRecord.RecordID, GetSessionDbcLocale()); hotfixQueryResponse.HotfixContent.WriteBytes(optionalData.Data);
if (blobData != null) }
hotfixData.Size = hotfixQueryResponse.HotfixContent.GetSize() - pos;
}
else
{ {
hotfixData.Size.Set((uint)blobData.Length); byte[] blobData = Global.DB2Mgr.GetHotfixBlobData(hotfixRecord.TableHash, hotfixRecord.RecordID, GetSessionDbcLocale());
hotfixQueryResponse.HotfixContent.WriteBytes(blobData); if (blobData != null)
{
hotfixData.Size = (uint)blobData.Length;
hotfixQueryResponse.HotfixContent.WriteBytes(blobData);
}
} }
} }
@@ -144,21 +144,13 @@ namespace Game.Networking.Packets
public void Write(WorldPacket data) public void Write(WorldPacket data)
{ {
Record.Write(data); Record.Write(data);
if (Size.HasValue) data.WriteUInt32(Size);
{ data.WriteBits((byte)Record.HotfixStatus, 2);
data.WriteUInt32(Size.Value);
data.WriteBits(1, 2);
}
else
{
data.WriteUInt32(0);
data.WriteBits(3, 2);
}
data.FlushBits(); data.FlushBits();
} }
public HotfixRecord Record; public HotfixRecord Record = new HotfixRecord();
public Optional<uint> Size; public uint Size;
} }
} }
} }