Skip to content

Commit d7bdc01

Browse files
joschiwaldShauren
authored andcommitted
Core/Packets: updated AccountData packets
(cherry picked from commit d55c0cb)
1 parent 735a155 commit d7bdc01

5 files changed

Lines changed: 135 additions & 62 deletions

File tree

src/server/game/Handlers/MiscHandler.cpp

Lines changed: 37 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "CharacterPackets.h"
2222
#include "Chat.h"
2323
#include "CinematicMgr.h"
24+
#include "ClientConfigPackets.h"
2425
#include "Common.h"
2526
#include "Corpse.h"
2627
#include "Creature.h"
@@ -763,97 +764,78 @@ void WorldSession::HandleAreaTriggerOpcode(WorldPacket& recvData)
763764
player->TeleportTo(at->target_mapId, at->target_X, at->target_Y, at->target_Z, at->target_Orientation, TELE_TO_NOT_LEAVE_TRANSPORT);
764765
}
765766

766-
void WorldSession::HandleUpdateAccountData(WorldPacket& recvData)
767+
void WorldSession::HandleUpdateAccountData(WorldPackets::ClientConfig::UserClientUpdateAccountData& packet)
767768
{
768-
TC_LOG_DEBUG("network", "WORLD: Received CMSG_UPDATE_ACCOUNT_DATA");
769+
TC_LOG_DEBUG("network", "WORLD: Received CMSG_UPDATE_ACCOUNT_DATA: type {}, time {}, decompressedSize {}",
770+
packet.DataType, packet.Time, packet.Size);
769771

770-
uint32 type, timestamp, decompressedSize;
771-
recvData >> type >> timestamp >> decompressedSize;
772-
773-
TC_LOG_DEBUG("network", "UAD: type {}, time {}, decompressedSize {}", type, timestamp, decompressedSize);
774-
775-
if (type >= NUM_ACCOUNT_DATA_TYPES)
772+
if (packet.DataType >= NUM_ACCOUNT_DATA_TYPES)
776773
return;
777774

778-
if (decompressedSize == 0) // erase
775+
if (packet.Size == 0) // erase
779776
{
780-
SetAccountData(AccountDataType(type), 0, "");
777+
SetAccountData(AccountDataType(packet.DataType), 0, "");
781778

782-
WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE, 4+4);
783-
data << uint32(type);
784-
data << uint32(0);
785-
SendPacket(&data);
779+
WorldPackets::ClientConfig::UpdateAccountDataComplete updateAccountDataComplete;
780+
updateAccountDataComplete.DataType = packet.DataType;
781+
updateAccountDataComplete.Result = 0;
782+
SendPacket(updateAccountDataComplete.Write());
786783

787784
return;
788785
}
789786

790-
if (decompressedSize > 0xFFFF)
787+
if (packet.Size > 0xFFFF)
791788
{
792-
recvData.rfinish(); // unnneded warning spam in this case
793-
TC_LOG_ERROR("network", "UAD: Account data packet too big, size {}", decompressedSize);
789+
TC_LOG_ERROR("network", "UAD: Account data packet too big, size {}", packet.Size);
794790
return;
795791
}
796792

797-
ByteBuffer dest;
798-
dest.resize(decompressedSize);
793+
std::string dest;
794+
dest.resize(packet.Size);
799795

800-
uLongf realSize = decompressedSize;
801-
if (uncompress(dest.contents(), &realSize, recvData.contents() + recvData.rpos(), recvData.size() - recvData.rpos()) != Z_OK)
796+
uLongf realSize = packet.Size;
797+
if (uncompress(reinterpret_cast<Bytef*>(dest.data()), &realSize, packet.CompressedData.data(), packet.CompressedData.size()) != Z_OK)
802798
{
803-
recvData.rfinish(); // unnneded warning spam in this case
804799
TC_LOG_ERROR("network", "UAD: Failed to decompress account data");
805800
return;
806801
}
807802

808-
recvData.rfinish(); // uncompress read (recvData.size() - recvData.rpos())
809-
810-
std::string adata;
811-
dest >> adata;
812-
813-
SetAccountData(AccountDataType(type), timestamp, adata);
803+
SetAccountData(AccountDataType(packet.DataType), packet.Time, dest);
814804

815-
WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE, 4+4);
816-
data << uint32(type);
817-
data << uint32(0);
818-
SendPacket(&data);
805+
WorldPackets::ClientConfig::UpdateAccountDataComplete updateAccountDataComplete;
806+
updateAccountDataComplete.DataType = packet.DataType;
807+
updateAccountDataComplete.Result = 0;
808+
SendPacket(updateAccountDataComplete.Write());
819809
}
820810

821-
void WorldSession::HandleRequestAccountData(WorldPacket& recvData)
811+
void WorldSession::HandleRequestAccountData(WorldPackets::ClientConfig::RequestAccountData& request)
822812
{
823-
TC_LOG_DEBUG("network", "WORLD: Received CMSG_REQUEST_ACCOUNT_DATA");
824-
825-
uint32 type;
826-
recvData >> type;
813+
TC_LOG_DEBUG("network", "WORLD: Received CMSG_REQUEST_ACCOUNT_DATA: type {}", request.DataType);
827814

828-
TC_LOG_DEBUG("network", "RAD: type {}", type);
829-
830-
if (type >= NUM_ACCOUNT_DATA_TYPES)
815+
if (request.DataType >= NUM_ACCOUNT_DATA_TYPES)
831816
return;
832817

833-
AccountData* adata = GetAccountData(AccountDataType(type));
818+
AccountData const* adata = GetAccountData(AccountDataType(request.DataType));
834819

835-
uint32 size = adata->Data.size();
820+
WorldPackets::ClientConfig::UpdateAccountData data;
821+
data.Player = _player ? _player->GetGUID() : ObjectGuid::Empty;
822+
data.Time = adata->Time;
823+
data.Size = adata->Data.size();
824+
data.DataType = request.DataType;
836825

837-
uLongf destSize = compressBound(size);
826+
uLongf destSize = compressBound(data.Size);
838827

839-
ByteBuffer dest;
840-
dest.resize(destSize);
828+
data.CompressedData.resize(destSize);
841829

842-
if (size && compress(dest.contents(), &destSize, (uint8 const*)adata->Data.c_str(), size) != Z_OK)
830+
if (data.Size && compress(data.CompressedData.data(), &destSize, (uint8 const*)adata->Data.c_str(), data.Size) != Z_OK)
843831
{
844-
TC_LOG_DEBUG("network", "RAD: Failed to compress account data");
832+
TC_LOG_ERROR("network", "RAD: Failed to compress account data");
845833
return;
846834
}
847835

848-
dest.resize(destSize);
836+
data.CompressedData.resize(destSize);
849837

850-
WorldPacket data(SMSG_UPDATE_ACCOUNT_DATA, 8+4+4+4+destSize);
851-
data << (_player ? _player->GetGUID() : ObjectGuid::Empty);
852-
data << uint32(type); // type (0-7)
853-
data << uint32(adata->Time); // unix time
854-
data << uint32(size); // decompressed length
855-
data.append(dest); // compressed data
856-
SendPacket(&data);
838+
SendPacket(data.Write());
857839
}
858840

859841
void WorldSession::HandleSetActionButtonOpcode(WorldPacket& recvData)

src/server/game/Server/Packets/ClientConfigPackets.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,42 @@ WorldPacket const* ClientCacheVersion::Write()
8484

8585
return &_worldPacket;
8686
}
87+
88+
void RequestAccountData::Read()
89+
{
90+
_worldPacket >> DataType;
91+
}
92+
93+
WorldPacket const* UpdateAccountData::Write()
94+
{
95+
_worldPacket << Player;
96+
_worldPacket << int32(DataType);
97+
_worldPacket << uint32(Time);
98+
_worldPacket << uint32(Size);
99+
if (!CompressedData.empty())
100+
_worldPacket.append(CompressedData.data(), CompressedData.size());
101+
102+
return &_worldPacket;
103+
}
104+
105+
void UserClientUpdateAccountData::Read()
106+
{
107+
_worldPacket >> DataType;
108+
_worldPacket >> Time;
109+
_worldPacket >> Size;
110+
111+
std::size_t pos = _worldPacket.rpos();
112+
std::size_t remainingSize = _worldPacket.size() - pos;
113+
114+
CompressedData = { _worldPacket.contents() + pos, remainingSize };
115+
_worldPacket.rpos(pos + remainingSize);
116+
}
117+
118+
WorldPacket const* UpdateAccountDataComplete::Write()
119+
{
120+
_worldPacket << int32(DataType);
121+
_worldPacket << int32(Result);
122+
123+
return &_worldPacket;
124+
}
87125
}

src/server/game/Server/Packets/ClientConfigPackets.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef TRINITYCORE_CLIENT_CONFIG_PACKETS_H
1919
#define TRINITYCORE_CLIENT_CONFIG_PACKETS_H
2020

21+
#include "ObjectGuid.h"
2122
#include "Packet.h"
2223
#include <span>
2324

@@ -50,6 +51,54 @@ namespace WorldPackets
5051

5152
uint32 CacheVersion = 0;
5253
};
54+
55+
class RequestAccountData final : public ClientPacket
56+
{
57+
public:
58+
explicit RequestAccountData(WorldPacket&& packet) : ClientPacket(CMSG_REQUEST_ACCOUNT_DATA, std::move(packet)) { }
59+
60+
void Read() override;
61+
62+
int32 DataType = 0; ///< @see enum AccountDataType
63+
};
64+
65+
class UpdateAccountData final : public ServerPacket
66+
{
67+
public:
68+
explicit UpdateAccountData() : ServerPacket(SMSG_UPDATE_ACCOUNT_DATA) { }
69+
70+
WorldPacket const* Write() override;
71+
72+
ObjectGuid Player;
73+
uint32 Time = 0; ///< UnixTime
74+
uint32 Size = 0; ///< decompressed size
75+
int32 DataType = 0; ///< @see enum AccountDataType
76+
std::vector<uint8> CompressedData;
77+
};
78+
79+
class UserClientUpdateAccountData final : public ClientPacket
80+
{
81+
public:
82+
explicit UserClientUpdateAccountData(WorldPacket&& packet) : ClientPacket(CMSG_UPDATE_ACCOUNT_DATA, std::move(packet)) { }
83+
84+
void Read() override;
85+
86+
uint32 Time = 0; ///< UnixTime
87+
uint32 Size = 0; ///< decompressed size
88+
int32 DataType = 0; ///< @see enum AccountDataType
89+
std::span<uint8 const> CompressedData;
90+
};
91+
92+
class UpdateAccountDataComplete final : public ServerPacket
93+
{
94+
public:
95+
explicit UpdateAccountDataComplete() : ServerPacket(SMSG_UPDATE_ACCOUNT_DATA_COMPLETE, 4 + 4) { }
96+
97+
WorldPacket const* Write() override;
98+
99+
int32 DataType = 0; ///< @see enum AccountDataType
100+
int32 Result = 0;
101+
};
53102
}
54103
}
55104

src/server/game/Server/WorldSession.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ namespace WorldPackets
144144
class PlayedTimeClient;
145145
}
146146

147+
namespace ClientConfig
148+
{
149+
class RequestAccountData;
150+
class UserClientUpdateAccountData;
151+
}
152+
147153
namespace Chat
148154
{
149155
class EmoteClient;
@@ -323,9 +329,7 @@ uint32 constexpr MAX_CHARACTERS_PER_REALM = 10; // max supported by client in ch
323329

324330
struct AccountData
325331
{
326-
AccountData() : Time(0), Data("") { }
327-
328-
time_t Time;
332+
time_t Time = 0;
329333
std::string Data;
330334
};
331335

@@ -559,7 +563,7 @@ class TC_GAME_API WorldSession
559563
bool CheckStableMaster(ObjectGuid guid);
560564

561565
// Account Data
562-
AccountData* GetAccountData(AccountDataType type) { return &m_accountData[type]; }
566+
AccountData const* GetAccountData(AccountDataType type) const { return &m_accountData[type]; }
563567
void SetAccountData(AccountDataType type, time_t tm, std::string const& data);
564568
void SendAccountDataTimes(uint32 mask);
565569
void LoadAccountData(PreparedQueryResult result, uint32 mask);
@@ -762,8 +766,8 @@ class TC_GAME_API WorldSession
762766
void HandleSetWatchedFactionOpcode(WorldPacket& recvData);
763767
void HandleSetFactionInactiveOpcode(WorldPacket& recvData);
764768

765-
void HandleUpdateAccountData(WorldPacket& recvPacket);
766-
void HandleRequestAccountData(WorldPacket& recvPacket);
769+
void HandleUpdateAccountData(WorldPackets::ClientConfig::UserClientUpdateAccountData& packet);
770+
void HandleRequestAccountData(WorldPackets::ClientConfig::RequestAccountData& request);
767771
void HandleSetActionButtonOpcode(WorldPacket& recvPacket);
768772

769773
void HandleGameObjectUseOpcode(WorldPacket& recPacket);

src/server/shared/Packets/ByteBuffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ class TC_SHARED_API ByteBuffer
354354

355355
void read(uint8 *dest, size_t len)
356356
{
357-
if (_rpos + len > size())
357+
if (_rpos + len > size())
358358
throw ByteBufferPositionException(false, _rpos, len, size());
359359
std::memcpy(dest, &_storage[_rpos], len);
360360
_rpos += len;

0 commit comments

Comments
 (0)