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

@@ -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));
}
}