Files
ForeverCore/src/server/game/Handlers/HotfixHandler.cpp
T

93 lines
3.5 KiB
C++
Raw Normal View History

/*
2018-01-01 00:40:17 +01:00
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "WorldSession.h"
#include "Containers.h"
#include "DB2Stores.h"
#include "HotfixPackets.h"
#include "Log.h"
2017-06-18 00:19:57 +02:00
#include "ObjectDefines.h"
2017-05-18 23:52:58 +02:00
#include "World.h"
void WorldSession::HandleDBQueryBulk(WorldPackets::Hotfix::DBQueryBulk& dbQuery)
{
DB2StorageBase const* store = sDB2Manager.GetStorage(dbQuery.TableHash);
if (!store)
{
TC_LOG_ERROR("network", "CMSG_DB_QUERY_BULK: %s requested unsupported unknown hotfix type: %u", GetPlayerInfo().c_str(), dbQuery.TableHash);
return;
}
for (WorldPackets::Hotfix::DBQueryBulk::DBQueryRecord const& record : dbQuery.Queries)
{
WorldPackets::Hotfix::DBReply dbReply;
dbReply.TableHash = dbQuery.TableHash;
dbReply.RecordID = record.RecordID;
if (store->HasRecord(record.RecordID))
{
dbReply.Allow = true;
dbReply.Timestamp = sWorld->GetGameTime();
store->WriteRecord(record.RecordID, GetSessionDbcLocale(), dbReply.Data);
}
else
{
TC_LOG_TRACE("network", "CMSG_DB_QUERY_BULK: %s requested non-existing entry %u in datastore: %u", GetPlayerInfo().c_str(), record.RecordID, dbQuery.TableHash);
dbReply.Timestamp = time(NULL);
}
SendPacket(dbReply.Write());
}
}
2017-11-11 17:11:00 +01:00
void WorldSession::SendAvailableHotfixes(int32 version)
{
2017-11-11 17:11:00 +01:00
SendPacket(WorldPackets::Hotfix::AvailableHotfixes(version, sDB2Manager.GetHotfixData()).Write());
}
2017-11-11 17:11:00 +01:00
void WorldSession::HandleHotfixRequest(WorldPackets::Hotfix::HotfixRequest& hotfixQuery)
{
2017-06-15 15:23:08 +02:00
std::map<uint64, int32> const& hotfixes = sDB2Manager.GetHotfixData();
2017-11-11 17:11:00 +01:00
WorldPackets::Hotfix::HotfixResponse hotfixQueryResponse;
hotfixQueryResponse.Hotfixes.reserve(hotfixQuery.Hotfixes.size());
2017-06-15 15:23:08 +02:00
for (uint64 hotfixId : hotfixQuery.Hotfixes)
{
2017-06-15 15:23:08 +02:00
if (int32 const* hotfix = Trinity::Containers::MapGetValuePtr(hotfixes, hotfixId))
{
2017-06-15 15:23:08 +02:00
DB2StorageBase const* storage = sDB2Manager.GetStorage(PAIR64_HIPART(hotfixId));
2017-11-11 17:11:00 +01:00
WorldPackets::Hotfix::HotfixResponse::HotfixData hotfixData;
2017-06-15 15:23:08 +02:00
hotfixData.ID = hotfixId;
hotfixData.RecordID = *hotfix;
if (storage && storage->HasRecord(hotfixData.RecordID))
{
2017-06-15 15:23:08 +02:00
hotfixData.Data = boost::in_place();
storage->WriteRecord(hotfixData.RecordID, GetSessionDbcLocale(), *hotfixData.Data);
}
else if (std::vector<uint8> const* blobData = sDB2Manager.GetHotfixBlobData(PAIR64_HIPART(hotfixId), *hotfix))
{
hotfixData.Data = boost::in_place();
hotfixData.Data->append(blobData->data(), blobData->size());
}
hotfixQueryResponse.Hotfixes.emplace_back(std::move(hotfixData));
}
}
SendPacket(hotfixQueryResponse.Write());
}