Core/PacketIO: Rename ByteBuffer::contents to ByteBuffer::data

This commit is contained in:
Shauren
2025-05-15 19:18:41 +02:00
parent 150c9cce5d
commit c6050a319c
12 changed files with 19 additions and 30 deletions

View File

@@ -3288,7 +3288,7 @@ bool ConditionMgr::IsPlayerMeetingCondition(Player const* player, PlayerConditio
ByteBuffer HexToBytes(const std::string& hex)
{
ByteBuffer buffer(hex.length() / 2, ByteBuffer::Resize{});
Trinity::Impl::HexStrToByteArray(hex, buffer.contents(), buffer.size());
Trinity::Impl::HexStrToByteArray(hex, buffer.data(), buffer.size());
return buffer;
}

View File

@@ -48,7 +48,7 @@ void WorldSession::SendBattlenetResponse(uint32 serviceHash, uint32 methodId, ui
if (response->ByteSize())
{
bnetResponse.Data.resize(response->ByteSize());
response->SerializePartialToArray(bnetResponse.Data.contents(), response->ByteSize());
response->SerializePartialToArray(bnetResponse.Data.data(), response->ByteSize());
}
SendPacket(bnetResponse.Write());
@@ -81,7 +81,7 @@ void WorldSession::SendBattlenetRequest(uint32 serviceHash, uint32 methodId, pb:
if (request->ByteSize())
{
notification.Data.resize(request->ByteSize());
request->SerializePartialToArray(notification.Data.contents(), request->ByteSize());
request->SerializePartialToArray(notification.Data.data(), request->ByteSize());
}
SendPacket(notification.Write());

View File

@@ -711,7 +711,7 @@ void WorldSession::HandleUpdateAccountData(WorldPackets::ClientConfig::UserClien
dest.resize(packet.Size);
uLongf realSize = packet.Size;
if (uncompress(reinterpret_cast<Bytef*>(dest.data()), &realSize, packet.CompressedData.contents(), packet.CompressedData.size()) != Z_OK)
if (uncompress(reinterpret_cast<Bytef*>(dest.data()), &realSize, packet.CompressedData.data(), packet.CompressedData.size()) != Z_OK)
{
TC_LOG_ERROR("network", "UAD: Failed to decompress account data");
return;
@@ -739,7 +739,7 @@ void WorldSession::HandleRequestAccountData(WorldPackets::ClientConfig::RequestA
data.CompressedData.resize(destSize);
if (data.Size && compress(data.CompressedData.contents(), &destSize, (uint8 const*)adata->Data.c_str(), data.Size) != Z_OK)
if (data.Size && compress(data.CompressedData.data(), &destSize, (uint8 const*)adata->Data.c_str(), data.Size) != Z_OK)
{
TC_LOG_ERROR("network", "RAD: Failed to compress account data");
return;

View File

@@ -304,7 +304,7 @@ WorldPacket const* WorldPackets::Auth::ConnectTo::Write()
Trinity::Crypto::RsaSignature rsa(*ConnectToRSA);
Trinity::Crypto::RsaSignature::SHA256 digestGenerator;
std::vector<uint8> signature;
rsa.Sign(signBuffer.contents(), signBuffer.size(), digestGenerator, signature);
rsa.Sign(signBuffer.data(), signBuffer.size(), digestGenerator, signature);
_worldPacket.append(signature.data(), signature.size());
_worldPacket.append(whereBuffer);

View File

@@ -66,7 +66,7 @@ void WorldPackets::ClientConfig::UserClientUpdateAccountData::Read()
if (compressedSize)
{
CompressedData.resize(compressedSize);
_worldPacket.read(CompressedData.contents(), compressedSize);
_worldPacket.read(CompressedData.data(), compressedSize);
}
}

View File

@@ -24,6 +24,6 @@ void WorldPackets::Warden::WardenData::Read()
if (size)
{
Data.resize(size);
_worldPacket.read(Data.contents(), size);
_worldPacket.read(Data.data(), size);
}
}

View File

@@ -145,7 +145,7 @@ void PacketLog::LogPacket(WorldPacket const& packet, Direction direction, boost:
fwrite(&header, sizeof(header), 1, _file);
if (size)
{
uint8 const* data = packet.contents();
uint8 const* data = packet.data();
if (direction == CLIENT_TO_SERVER)
data += 4;
fwrite(data, 1, size, _file);

View File

@@ -553,7 +553,7 @@ void WorldSocket::WritePacketToBuffer(EncryptablePacket const& packet, MessageBu
{
CompressedWorldPacket cmp;
cmp.UncompressedSize = packetSize + sizeof(opcode);
cmp.UncompressedAdler = adler32(adler32(0x9827D8F1, (Bytef*)&opcode, sizeof(opcode)), packet.contents(), packetSize);
cmp.UncompressedAdler = adler32(adler32(0x9827D8F1, (Bytef*)&opcode, sizeof(opcode)), packet.data(), packetSize);
// Reserve space for compression info - uncompressed size and checksums
uint8* compressionInfo = buffer.GetWritePointer();
@@ -570,7 +570,7 @@ void WorldSocket::WritePacketToBuffer(EncryptablePacket const& packet, MessageBu
opcode = SMSG_COMPRESSED_PACKET;
}
else if (!packet.empty())
buffer.Write(packet.contents(), packet.size());
buffer.Write(packet.data(), packet.size());
memcpy(dataPos, &opcode, sizeof(opcode));
packetSize += sizeof(opcode);
@@ -599,7 +599,7 @@ uint32 WorldSocket::CompressPacket(uint8* buffer, WorldPacket const& packet)
return 0;
}
_compressionStream->next_in = (Bytef*)packet.contents();
_compressionStream->next_in = (Bytef*)packet.data();
_compressionStream->avail_in = packet.size();
z_res = deflate(_compressionStream, Z_SYNC_FLUSH);

View File

@@ -208,7 +208,7 @@ char const* Warden::ApplyPenalty(WardenCheck const* check)
void Warden::HandleData(ByteBuffer& buff)
{
DecryptData(buff.contents(), buff.size());
DecryptData(buff.data(), buff.size());
uint8 opcode;
buff >> opcode;
TC_LOG_DEBUG("warden", "Got packet, opcode {:02X}, size {}", opcode, uint32(buff.size() - 1));

View File

@@ -182,7 +182,7 @@ void WardenMac::RequestChecks()
buff.hexlike();
// Encrypt with warden RC4 key.
EncryptData(buff.contents(), buff.size());
EncryptData(buff.data(), buff.size());
WorldPacket pkt(SMSG_WARDEN3_DATA, buff.size());
pkt.append(buff);

View File

@@ -366,7 +366,7 @@ void WardenWin::RequestChecks()
}
// Encrypt with warden RC4 key
EncryptData(buff.contents(), buff.size());
EncryptData(buff.data(), buff.size());
WorldPacket pkt(SMSG_WARDEN3_DATA, buff.size());
pkt.append(buff);
@@ -395,7 +395,7 @@ void WardenWin::HandleCheckResult(ByteBuffer &buff)
return;
}
if (!IsValidCheckSum(Checksum, buff.contents() + buff.rpos(), Length))
if (!IsValidCheckSum(Checksum, buff.data() + buff.rpos(), Length))
{
buff.rfinish();
char const* penalty = ApplyPenalty(nullptr);

View File

@@ -571,19 +571,8 @@ class TC_SHARED_API ByteBuffer
std::string_view ReadString(uint32 length, bool requireValidUtf8 = true);
uint8* contents()
{
if (_storage.empty())
throw ByteBufferException();
return _storage.data();
}
uint8 const* contents() const
{
if (_storage.empty())
throw ByteBufferException();
return _storage.data();
}
uint8* data() { return _storage.data(); }
uint8 const* data() const { return _storage.data(); }
size_t size() const { return _storage.size(); }
bool empty() const { return _storage.empty(); }
@@ -622,7 +611,7 @@ class TC_SHARED_API ByteBuffer
void append(ByteBuffer const& buffer)
{
if (!buffer.empty())
append(buffer.contents(), buffer.size());
append(buffer.data(), buffer.size());
}
template <size_t Size>