TrinityCore
Loading...
Searching...
No Matches
HotfixHandler.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "WorldSession.h"
19#include "GameTime.h"
20#include "HotfixPackets.h"
21#include "Log.h"
22#include "MapUtils.h"
23#include "World.h"
24
26{
27 DB2StorageBase const* store = sDB2Manager.GetStorage(dbQuery.TableHash);
29 {
31 dbReply.TableHash = dbQuery.TableHash;
32 dbReply.RecordID = record.RecordID;
33
34 if (store && store->HasRecord(record.RecordID))
35 {
38 store->WriteRecord(record.RecordID, GetSessionDbcLocale(), dbReply.Data);
39
40 if (std::vector<DB2Manager::HotfixOptionalData> const* optionalDataEntries = sDB2Manager.GetHotfixOptionalData(dbQuery.TableHash, record.RecordID, GetSessionDbcLocale()))
41 {
42 for (DB2Manager::HotfixOptionalData const& optionalData : *optionalDataEntries)
43 {
44 dbReply.Data << uint32(optionalData.Key);
45 dbReply.Data.append(optionalData.Data.data(), optionalData.Data.size());
46 }
47 }
48 }
49 else
50 {
51 TC_LOG_TRACE("network", "CMSG_DB_QUERY_BULK: {} requested non-existing entry {} in datastore: {}", GetPlayerInfo(), record.RecordID, dbQuery.TableHash);
53 }
54
55 SendPacket(dbReply.Write());
56 }
57}
58
60{
62 availableHotfixes.VirtualRealmAddress = GetVirtualRealmAddress();
63
64 for (auto const& [pushId, push] : sDB2Manager.GetHotfixData())
65 {
66 if (!(push.AvailableLocalesMask & (1 << GetSessionDbcLocale())))
67 continue;
68
69 availableHotfixes.Hotfixes.insert(push.Records.front().ID);
70 }
71
72 SendPacket(availableHotfixes.Write());
73}
74
76{
77 DB2Manager::HotfixContainer const& hotfixes = sDB2Manager.GetHotfixData();
78 WorldPackets::Hotfix::HotfixConnect hotfixQueryResponse;
79 hotfixQueryResponse.Hotfixes.reserve(hotfixQuery.Hotfixes.size());
80 for (int32 hotfixId : hotfixQuery.Hotfixes)
81 {
82 if (DB2Manager::HotfixPush const* hotfixRecords = Trinity::Containers::MapGetValuePtr(hotfixes, hotfixId))
83 {
84 for (DB2Manager::HotfixRecord const& hotfixRecord : hotfixRecords->Records)
85 {
86 if (!(hotfixRecord.AvailableLocalesMask & (1 << GetSessionDbcLocale())))
87 continue;
88
89 WorldPackets::Hotfix::HotfixConnect::HotfixData& hotfixData = hotfixQueryResponse.Hotfixes.emplace_back();
90 hotfixData.Record = hotfixRecord;
91 if (hotfixRecord.HotfixStatus == DB2Manager::HotfixRecord::Status::Valid)
92 {
93 DB2StorageBase const* storage = sDB2Manager.GetStorage(hotfixRecord.TableHash);
94 if (storage && storage->HasRecord(uint32(hotfixRecord.RecordID)))
95 {
96 std::size_t pos = hotfixQueryResponse.HotfixContent.size();
97 storage->WriteRecord(uint32(hotfixRecord.RecordID), GetSessionDbcLocale(), hotfixQueryResponse.HotfixContent);
98
99 if (std::vector<DB2Manager::HotfixOptionalData> const* optionalDataEntries = sDB2Manager.GetHotfixOptionalData(hotfixRecord.TableHash, hotfixRecord.RecordID, GetSessionDbcLocale()))
100 {
101 for (DB2Manager::HotfixOptionalData const& optionalData : *optionalDataEntries)
102 {
103 hotfixQueryResponse.HotfixContent << uint32(optionalData.Key);
104 hotfixQueryResponse.HotfixContent.append(optionalData.Data.data(), optionalData.Data.size());
105 }
106 }
107
108 hotfixData.Size = hotfixQueryResponse.HotfixContent.size() - pos;
109 }
110 else if (std::vector<uint8> const* blobData = sDB2Manager.GetHotfixBlobData(hotfixRecord.TableHash, hotfixRecord.RecordID, GetSessionDbcLocale()))
111 {
112 hotfixData.Size = blobData->size();
113 hotfixQueryResponse.HotfixContent.append(blobData->data(), blobData->size());
114 }
115 else
116 // Do not send Status::Valid when we don't have a hotfix blob for current locale
118 }
119 }
120 }
121 }
122
123 SendPacket(hotfixQueryResponse.Write());
124}
#define sDB2Manager
Definition DB2Stores.h:569
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
#define TC_LOG_TRACE(filterType__, message__,...)
Definition Log.h:178
void append(T value)
Definition ByteBuffer.h:130
size_t size() const
Definition ByteBuffer.h:568
std::map< int32, HotfixPush > HotfixContainer
Definition DB2Stores.h:437
Interface class for common access.
Definition DB2Store.h:31
void WriteRecord(uint32 id, LocaleConstant locale, ByteBuffer &buffer) const
Definition DB2Store.cpp:41
bool HasRecord(uint32 id) const
Definition DB2Store.h:43
std::set< DB2Manager::HotfixId > Hotfixes
WorldPacket const * Write() override
std::vector< DBQueryRecord > Queries
DB2Manager::HotfixRecord::Status Status
WorldPacket const * Write() override
WorldPacket const * Write() override
std::vector< HotfixData > Hotfixes
void HandleDBQueryBulk(WorldPackets::Hotfix::DBQueryBulk &dbQuery)
LocaleConstant GetSessionDbcLocale() const
std::string GetPlayerInfo() const
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
void HandleHotfixRequest(WorldPackets::Hotfix::HotfixRequest &hotfixQuery)
void SendAvailableHotfixes()
uint32 GetVirtualRealmAddress()
Definition World.cpp:3526
time_t GetGameTime()
Definition GameTime.cpp:52
auto MapGetValuePtr(M &map, typename M::key_type const &key)
Definition MapUtils.h:37