2017-04-19 19:10:49 +02:00
|
|
|
/*
|
2020-01-02 06:44:10 +01:00
|
|
|
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
|
2017-04-19 19:10:49 +02:00
|
|
|
*
|
|
|
|
|
* 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"
|
2017-03-02 02:19:25 +01:00
|
|
|
#include "GameTime.h"
|
2017-04-19 19:10:49 +02:00
|
|
|
#include "HotfixPackets.h"
|
|
|
|
|
#include "Log.h"
|
2017-06-18 00:19:57 +02:00
|
|
|
#include "ObjectDefines.h"
|
2020-08-13 14:15:26 +02:00
|
|
|
#include "Realm.h"
|
2017-05-18 23:52:58 +02:00
|
|
|
#include "World.h"
|
2017-04-19 19:10:49 +02:00
|
|
|
|
|
|
|
|
void WorldSession::HandleDBQueryBulk(WorldPackets::Hotfix::DBQueryBulk& dbQuery)
|
|
|
|
|
{
|
|
|
|
|
DB2StorageBase const* store = sDB2Manager.GetStorage(dbQuery.TableHash);
|
|
|
|
|
for (WorldPackets::Hotfix::DBQueryBulk::DBQueryRecord const& record : dbQuery.Queries)
|
|
|
|
|
{
|
|
|
|
|
WorldPackets::Hotfix::DBReply dbReply;
|
|
|
|
|
dbReply.TableHash = dbQuery.TableHash;
|
|
|
|
|
dbReply.RecordID = record.RecordID;
|
|
|
|
|
|
2020-12-20 22:49:53 +01:00
|
|
|
if (store && store->HasRecord(record.RecordID))
|
2017-04-19 19:10:49 +02:00
|
|
|
{
|
2021-02-28 20:58:03 +01:00
|
|
|
dbReply.Status = DB2Manager::HotfixRecord::Status::Valid;
|
2017-03-02 02:19:25 +01:00
|
|
|
dbReply.Timestamp = GameTime::GetGameTime();
|
2017-04-19 19:10:49 +02:00
|
|
|
store->WriteRecord(record.RecordID, GetSessionDbcLocale(), dbReply.Data);
|
2020-12-20 22:49:53 +01:00
|
|
|
|
|
|
|
|
if (std::vector<DB2Manager::HotfixOptionalData> const* optionalDataEntries = sDB2Manager.GetHotfixOptionalData(dbQuery.TableHash, record.RecordID, GetSessionDbcLocale()))
|
|
|
|
|
{
|
|
|
|
|
for (DB2Manager::HotfixOptionalData const& optionalData : *optionalDataEntries)
|
|
|
|
|
{
|
|
|
|
|
dbReply.Data << uint32(optionalData.Key);
|
|
|
|
|
dbReply.Data.append(optionalData.Data.data(), optionalData.Data.size());
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-19 19:10:49 +02:00
|
|
|
}
|
|
|
|
|
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);
|
2017-12-10 12:39:37 +01:00
|
|
|
dbReply.Timestamp = GameTime::GetGameTime();
|
2017-04-19 19:10:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendPacket(dbReply.Write());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 14:15:26 +02:00
|
|
|
void WorldSession::SendAvailableHotfixes()
|
2017-04-19 19:10:49 +02:00
|
|
|
{
|
2021-04-09 20:57:47 +02:00
|
|
|
SendPacket(WorldPackets::Hotfix::AvailableHotfixes(realm.Id.GetAddress(), sDB2Manager.GetHotfixData()).Write());
|
2017-04-19 19:10:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-11 17:11:00 +01:00
|
|
|
void WorldSession::HandleHotfixRequest(WorldPackets::Hotfix::HotfixRequest& hotfixQuery)
|
2017-04-19 19:10:49 +02:00
|
|
|
{
|
2019-05-18 22:21:17 +02:00
|
|
|
DB2Manager::HotfixContainer const& hotfixes = sDB2Manager.GetHotfixData();
|
2020-09-19 12:44:42 +02:00
|
|
|
WorldPackets::Hotfix::HotfixConnect hotfixQueryResponse;
|
2017-04-19 19:10:49 +02:00
|
|
|
hotfixQueryResponse.Hotfixes.reserve(hotfixQuery.Hotfixes.size());
|
2021-04-09 20:57:47 +02:00
|
|
|
for (int32 hotfixId : hotfixQuery.Hotfixes)
|
2017-04-19 19:10:49 +02:00
|
|
|
{
|
2021-04-09 20:57:47 +02:00
|
|
|
if (std::vector<DB2Manager::HotfixRecord> const* hotfixRecords = Trinity::Containers::MapGetValuePtr(hotfixes, hotfixId))
|
2017-04-19 19:10:49 +02:00
|
|
|
{
|
2021-04-09 20:57:47 +02:00
|
|
|
for (DB2Manager::HotfixRecord const& hotfixRecord : *hotfixRecords)
|
2020-06-08 00:08:37 +02:00
|
|
|
{
|
2021-04-09 20:57:47 +02:00
|
|
|
hotfixQueryResponse.Hotfixes.emplace_back();
|
2021-02-28 01:14:33 +01:00
|
|
|
|
2021-04-09 20:57:47 +02:00
|
|
|
WorldPackets::Hotfix::HotfixConnect::HotfixData& hotfixData = hotfixQueryResponse.Hotfixes.back();
|
|
|
|
|
hotfixData.Record = hotfixRecord;
|
|
|
|
|
if (hotfixRecord.HotfixStatus == DB2Manager::HotfixRecord::Status::Valid)
|
|
|
|
|
{
|
|
|
|
|
DB2StorageBase const* storage = sDB2Manager.GetStorage(hotfixRecord.TableHash);
|
|
|
|
|
if (storage && storage->HasRecord(uint32(hotfixRecord.RecordID)))
|
2020-12-20 22:49:53 +01:00
|
|
|
{
|
2021-04-09 20:57:47 +02:00
|
|
|
std::size_t pos = hotfixQueryResponse.HotfixContent.size();
|
|
|
|
|
storage->WriteRecord(uint32(hotfixRecord.RecordID), GetSessionDbcLocale(), hotfixQueryResponse.HotfixContent);
|
|
|
|
|
|
|
|
|
|
if (std::vector<DB2Manager::HotfixOptionalData> const* optionalDataEntries = sDB2Manager.GetHotfixOptionalData(hotfixRecord.TableHash, hotfixRecord.RecordID, GetSessionDbcLocale()))
|
2021-02-28 01:14:33 +01:00
|
|
|
{
|
2021-04-09 20:57:47 +02:00
|
|
|
for (DB2Manager::HotfixOptionalData const& optionalData : *optionalDataEntries)
|
|
|
|
|
{
|
|
|
|
|
hotfixQueryResponse.HotfixContent << uint32(optionalData.Key);
|
|
|
|
|
hotfixQueryResponse.HotfixContent.append(optionalData.Data.data(), optionalData.Data.size());
|
|
|
|
|
}
|
2021-02-28 01:14:33 +01:00
|
|
|
}
|
2020-12-20 22:49:53 +01:00
|
|
|
|
2021-04-09 20:57:47 +02:00
|
|
|
hotfixData.Size = hotfixQueryResponse.HotfixContent.size() - pos;
|
|
|
|
|
}
|
|
|
|
|
else if (std::vector<uint8> const* blobData = sDB2Manager.GetHotfixBlobData(hotfixRecord.TableHash, hotfixRecord.RecordID, GetSessionDbcLocale()))
|
|
|
|
|
{
|
|
|
|
|
hotfixData.Size = blobData->size();
|
|
|
|
|
hotfixQueryResponse.HotfixContent.append(blobData->data(), blobData->size());
|
|
|
|
|
}
|
2021-08-17 20:02:43 +02:00
|
|
|
else
|
|
|
|
|
// Do not send Status::Valid when we don't have a hotfix blob for current locale
|
|
|
|
|
hotfixData.Record.HotfixStatus = storage ? DB2Manager::HotfixRecord::Status::RecordRemoved : DB2Manager::HotfixRecord::Status::Invalid;
|
2021-02-28 01:14:33 +01:00
|
|
|
}
|
2020-06-08 00:08:37 +02:00
|
|
|
}
|
2017-04-19 19:10:49 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendPacket(hotfixQueryResponse.Write());
|
|
|
|
|
}
|