Core/PacketIO: Fixed receiving and sending db2 hotfix packets

This commit is contained in:
Shauren
2020-06-08 00:08:37 +02:00
parent e5a6552abc
commit 5fce3604fc
7 changed files with 88 additions and 77 deletions

View File

@@ -1414,7 +1414,11 @@ void DB2Manager::LoadHotfixData()
}
_maxHotfixId = std::max(_maxHotfixId, id);
_hotfixData[id].emplace_back(tableHash, recordId);
HotfixRecord hotfixRecord;
hotfixRecord.TableHash = tableHash;
hotfixRecord.RecordID = recordId;
hotfixRecord.HotfixID = id;
_hotfixData.insert(hotfixRecord);
++_hotfixCount;
deletedRecords[std::make_pair(tableHash, recordId)] = deleted;
++count;
@@ -1463,7 +1467,7 @@ void DB2Manager::LoadHotfixBlob()
uint32 DB2Manager::GetHotfixCount() const
{
return _hotfixCount;
return _hotfixData.size();
}
DB2Manager::HotfixContainer const& DB2Manager::GetHotfixData() const
@@ -1485,8 +1489,11 @@ uint32 DB2Manager::GetEmptyAnimStateID() const
void DB2Manager::InsertNewHotfix(uint32 tableHash, uint32 recordId)
{
_hotfixData[++_maxHotfixId].emplace_back(tableHash, recordId);
++_hotfixCount;
HotfixRecord hotfixRecord;
hotfixRecord.TableHash = tableHash;
hotfixRecord.RecordID = recordId;
hotfixRecord.HotfixID = ++_maxHotfixId;
_hotfixData.insert(hotfixRecord);
}
std::vector<uint32> DB2Manager::GetAreasForGroup(uint32 areaGroupId) const

View File

@@ -227,11 +227,11 @@ struct TaxiPathBySourceAndDestination
uint32 price;
};
typedef std::map<uint32, TaxiPathBySourceAndDestination> TaxiPathSetForSource;
typedef std::map<uint32, TaxiPathSetForSource> TaxiPathSetBySource;
using TaxiPathSetForSource = std::map<uint32, TaxiPathBySourceAndDestination>;
using TaxiPathSetBySource = std::map<uint32, TaxiPathSetForSource>;
typedef std::vector<TaxiPathNodeEntry const*> TaxiPathNodeList;
typedef std::vector<TaxiPathNodeList> TaxiPathNodesByPath;
using TaxiPathNodeList = std::vector<TaxiPathNodeEntry const*>;
using TaxiPathNodesByPath = std::vector<TaxiPathNodeList>;
TC_GAME_API extern TaxiMask sTaxiNodesMask;
TC_GAME_API extern TaxiMask sOldContinentsNodesMask;
@@ -252,12 +252,24 @@ class TC_GAME_API DB2Manager
public:
DEFINE_DB2_SET_COMPARATOR(MountTypeXCapabilityEntry)
typedef std::map<int32 /*hotfixId*/, std::vector<std::pair<uint32 /*tableHash*/, int32 /*recordId*/>>> HotfixContainer;
struct HotfixRecord
{
uint32 TableHash = 0;
int32 RecordID = 0;
int32 HotfixID = 0;
typedef std::vector<ItemBonusEntry const*> ItemBonusList;
typedef std::unordered_map<uint32, std::unordered_map<uint32, MapDifficultyEntry const*>> MapDifficultyContainer;
typedef std::set<MountTypeXCapabilityEntry const*, MountTypeXCapabilityEntryComparator> MountTypeXCapabilitySet;
typedef std::vector<MountXDisplayEntry const*> MountXDisplayContainer;
friend bool operator<(HotfixRecord const& left, HotfixRecord const& right)
{
return std::tie(left.HotfixID, left.TableHash, left.RecordID) < std::tie(right.HotfixID, right.TableHash, right.RecordID);
}
};
using HotfixContainer = std::set<HotfixRecord>;
using ItemBonusList = std::vector<ItemBonusEntry const*>;
using MapDifficultyContainer = std::unordered_map<uint32, std::unordered_map<uint32, MapDifficultyEntry const*>>;
using MountTypeXCapabilitySet = std::set<MountTypeXCapabilityEntry const*, MountTypeXCapabilityEntryComparator>;
using MountXDisplayContainer = std::vector<MountXDisplayEntry const*>;
static DB2Manager& Instance();

View File

@@ -65,32 +65,27 @@ void WorldSession::HandleHotfixRequest(WorldPackets::Hotfix::HotfixRequest& hotf
DB2Manager::HotfixContainer const& hotfixes = sDB2Manager.GetHotfixData();
WorldPackets::Hotfix::HotfixResponse hotfixQueryResponse;
hotfixQueryResponse.Hotfixes.reserve(hotfixQuery.Hotfixes.size());
for (WorldPackets::Hotfix::HotfixRecord const& hotfixRecord : hotfixQuery.Hotfixes)
for (DB2Manager::HotfixRecord const& hotfixRecord : hotfixQuery.Hotfixes)
{
if (auto const* hotfixedRecords = Trinity::Containers::MapGetValuePtr(hotfixes, hotfixRecord.HotfixID))
if (hotfixes.find(hotfixRecord) != hotfixes.end())
{
for (auto const& tableRecord : *hotfixedRecords)
DB2StorageBase const* storage = sDB2Manager.GetStorage(hotfixRecord.TableHash);
WorldPackets::Hotfix::HotfixResponse::HotfixData hotfixData;
hotfixData.Record = hotfixRecord;
if (storage && storage->HasRecord(uint32(hotfixRecord.RecordID)))
{
uint32 hotfixTableHash = tableRecord.first;
int32 hotfixRecordId = tableRecord.second;;
DB2StorageBase const* storage = sDB2Manager.GetStorage(hotfixTableHash);
WorldPackets::Hotfix::HotfixResponse::HotfixData hotfixData;
hotfixData.Record = hotfixRecord;
if (storage && storage->HasRecord(hotfixRecordId))
{
std::size_t pos = hotfixQueryResponse.HotfixContent.size();
storage->WriteRecord(hotfixRecordId, GetSessionDbcLocale(), hotfixQueryResponse.HotfixContent);
hotfixData.Size = hotfixQueryResponse.HotfixContent.size() - pos;
}
else if (std::vector<uint8> const* blobData = sDB2Manager.GetHotfixBlobData(hotfixTableHash, hotfixRecordId))
{
hotfixData.Size = blobData->size();
hotfixQueryResponse.HotfixContent.append(blobData->data(), blobData->size());
}
hotfixQueryResponse.Hotfixes.emplace_back(std::move(hotfixData));
std::size_t pos = hotfixQueryResponse.HotfixContent.size();
storage->WriteRecord(uint32(hotfixRecord.RecordID), GetSessionDbcLocale(), hotfixQueryResponse.HotfixContent);
hotfixData.Size = hotfixQueryResponse.HotfixContent.size() - pos;
}
else if (std::vector<uint8> const* blobData = sDB2Manager.GetHotfixBlobData(hotfixRecord.TableHash, hotfixRecord.RecordID))
{
hotfixData.Size = blobData->size();
hotfixQueryResponse.HotfixContent.append(blobData->data(), blobData->size());
}
hotfixQueryResponse.Hotfixes.emplace_back(std::move(hotfixData));
}
}

View File

@@ -18,7 +18,27 @@
#include "HotfixPackets.h"
#include "PacketUtilities.h"
void WorldPackets::Hotfix::DBQueryBulk::Read()
namespace WorldPackets
{
namespace Hotfix
{
ByteBuffer& operator>>(ByteBuffer& data, DB2Manager::HotfixRecord& hotfixRecord)
{
data >> hotfixRecord.TableHash;
data >> hotfixRecord.RecordID;
data >> hotfixRecord.HotfixID;
return data;
}
ByteBuffer& operator<<(ByteBuffer& data, DB2Manager::HotfixRecord const& hotfixRecord)
{
data << uint32(hotfixRecord.TableHash);
data << int32(hotfixRecord.RecordID);
data << int32(hotfixRecord.HotfixID);
return data;
}
void DBQueryBulk::Read()
{
_worldPacket >> TableHash;
@@ -29,7 +49,7 @@ void WorldPackets::Hotfix::DBQueryBulk::Read()
_worldPacket >> Queries[i].RecordID;
}
WorldPacket const* WorldPackets::Hotfix::DBReply::Write()
WorldPacket const* DBReply::Write()
{
_worldPacket << uint32(TableHash);
_worldPacket << uint32(RecordID);
@@ -41,40 +61,17 @@ WorldPacket const* WorldPackets::Hotfix::DBReply::Write()
return &_worldPacket;
}
WorldPacket const* WorldPackets::Hotfix::AvailableHotfixes::Write()
WorldPacket const* AvailableHotfixes::Write()
{
_worldPacket << int32(HotfixCacheVersion);
_worldPacket << uint32(HotfixCount);
for (auto const& hotfixEntry : Hotfixes)
{
for (auto const& tableRecord : hotfixEntry.second)
{
_worldPacket << uint32(tableRecord.first);
_worldPacket << int32(tableRecord.second);
_worldPacket << int32(hotfixEntry.first);
}
}
for (DB2Manager::HotfixRecord const& hotfixRecord : Hotfixes)
_worldPacket << hotfixRecord;
return &_worldPacket;
}
ByteBuffer& operator>>(ByteBuffer& data, WorldPackets::Hotfix::HotfixRecord& hotfixRecord)
{
data >> hotfixRecord.TableHash;
data >> hotfixRecord.RecordID;
data >> hotfixRecord.HotfixID;
return data;
}
ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Hotfix::HotfixRecord const& hotfixRecord)
{
data << uint32(hotfixRecord.TableHash);
data << int32(hotfixRecord.RecordID);
data << int32(hotfixRecord.HotfixID);
return data;
}
void WorldPackets::Hotfix::HotfixRequest::Read()
void HotfixRequest::Read()
{
_worldPacket >> ClientBuild;
_worldPacket >> DataBuild;
@@ -84,11 +81,11 @@ void WorldPackets::Hotfix::HotfixRequest::Read()
throw PacketArrayMaxCapacityException(hotfixCount, sDB2Manager.GetHotfixCount());
Hotfixes.resize(hotfixCount);
for (HotfixRecord& hotfixRecord : Hotfixes)
for (DB2Manager::HotfixRecord& hotfixRecord : Hotfixes)
_worldPacket >> hotfixRecord;
}
ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Hotfix::HotfixResponse::HotfixData const& hotfixData)
ByteBuffer& operator<<(ByteBuffer& data, HotfixResponse::HotfixData const& hotfixData)
{
data << hotfixData.Record;
if (hotfixData.Size)
@@ -106,7 +103,7 @@ ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Hotfix::HotfixResponse::H
return data;
}
WorldPacket const* WorldPackets::Hotfix::HotfixResponse::Write()
WorldPacket const* HotfixResponse::Write()
{
_worldPacket << uint32(Hotfixes.size());
for (HotfixData const& hotfix : Hotfixes)
@@ -117,3 +114,5 @@ WorldPacket const* WorldPackets::Hotfix::HotfixResponse::Write()
return &_worldPacket;
}
}
}

View File

@@ -71,13 +71,6 @@ namespace WorldPackets
DB2Manager::HotfixContainer const& Hotfixes;
};
struct HotfixRecord
{
uint32 TableHash = 0;
int32 RecordID = 0;
int32 HotfixID = 0;
};
class HotfixRequest final : public ClientPacket
{
public:
@@ -87,7 +80,7 @@ namespace WorldPackets
uint32 ClientBuild = 0;
uint32 DataBuild = 0;
std::vector<HotfixRecord> Hotfixes;
std::vector<DB2Manager::HotfixRecord> Hotfixes;
};
class HotfixResponse final : public ServerPacket
@@ -95,7 +88,7 @@ namespace WorldPackets
public:
struct HotfixData
{
HotfixRecord Record;
DB2Manager::HotfixRecord Record;
Optional<uint32> Size;
};

View File

@@ -1391,6 +1391,11 @@ uint32 WorldSession::DosProtection::GetMaxPacketCounterAllowed(uint16 opcode) co
maxPacketCounterAllowed = PLAYER_SLOTS_COUNT;
break;
}
case CMSG_HOTFIX_REQUEST: // not profiled
{
maxPacketCounterAllowed = 1;
break;
}
default:
{
maxPacketCounterAllowed = 100;

View File

@@ -56,7 +56,7 @@ struct PacketHeader
uint32 Size;
uint8 Tag[12];
bool IsValidSize() { return Size < 0x10000; }
bool IsValidSize() { return Size < 0x40000; }
};
#pragma pack(pop)