diff options
author | Shauren <shauren.trinity@gmail.com> | 2025-05-23 14:41:39 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2025-05-23 14:41:39 +0200 |
commit | 85e621f01adf84ee66e20f8b75c93be7b4940cb2 (patch) | |
tree | ebd324f4d5e4132c7cb241ae988e17dc40aef9fa /src/server | |
parent | 5bebf0520968665af288d1d3619f1c42a7322ccb (diff) |
Core/PacketIO: Remove ByteBuffer constructor from MessageBuffer
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/game/Conditions/ConditionMgr.cpp | 9 | ||||
-rw-r--r-- | src/server/game/Server/WorldPacket.h | 23 | ||||
-rw-r--r-- | src/server/game/Server/WorldSocket.cpp | 4 | ||||
-rw-r--r-- | src/server/shared/Packets/ByteBuffer.cpp | 6 | ||||
-rw-r--r-- | src/server/shared/Packets/ByteBuffer.h | 42 |
5 files changed, 27 insertions, 57 deletions
diff --git a/src/server/game/Conditions/ConditionMgr.cpp b/src/server/game/Conditions/ConditionMgr.cpp index a31ab98c268..d954214506f 100644 --- a/src/server/game/Conditions/ConditionMgr.cpp +++ b/src/server/game/Conditions/ConditionMgr.cpp @@ -3285,13 +3285,6 @@ bool ConditionMgr::IsPlayerMeetingCondition(Player const* player, PlayerConditio return true; } -static ByteBuffer HexToBytes(std::string_view const& hex) -{ - ByteBuffer buffer(hex.length() / 2, ByteBuffer::Resize{}); - Trinity::Impl::HexStrToByteArray(hex, buffer.data(), buffer.size()); - return buffer; -} - static constexpr int32(* const WorldStateExpressionFunctions[WSE_FUNCTION_MAX])(Map const*, uint32, uint32) = { // WSE_FUNCTION_NONE @@ -3636,7 +3629,7 @@ bool EvalRelOp(ByteBuffer& buffer, Map const* map) bool ConditionMgr::IsMeetingWorldStateExpression(Map const* map, WorldStateExpressionEntry const* expression) try { - ByteBuffer buffer = HexToBytes(expression->Expression); + ByteBuffer buffer(HexStrToByteVector(expression->Expression)); if (buffer.empty()) return false; diff --git a/src/server/game/Server/WorldPacket.h b/src/server/game/Server/WorldPacket.h index 240db0ea91c..70462b5a533 100644 --- a/src/server/game/Server/WorldPacket.h +++ b/src/server/game/Server/WorldPacket.h @@ -26,27 +26,28 @@ class WorldPacket : public ByteBuffer { public: // just container for later use - WorldPacket() : ByteBuffer(0, Reserve{}), m_opcode(UNKNOWN_OPCODE), _connection(CONNECTION_TYPE_DEFAULT) - { - } + explicit WorldPacket() : ByteBuffer(0, Reserve{}), + m_opcode(UNKNOWN_OPCODE), _connection(CONNECTION_TYPE_DEFAULT) { } - WorldPacket(uint32 opcode, ConnectionType connection = CONNECTION_TYPE_DEFAULT) : ByteBuffer(0, Reserve{}), + explicit WorldPacket(uint32 opcode, ConnectionType connection = CONNECTION_TYPE_DEFAULT) : ByteBuffer(0, Reserve{}), m_opcode(opcode), _connection(connection) { } - WorldPacket(uint32 opcode, size_t res, Reserve, ConnectionType connection = CONNECTION_TYPE_DEFAULT) : ByteBuffer(res, Reserve{}), + explicit WorldPacket(uint32 opcode, size_t res, Reserve, ConnectionType connection = CONNECTION_TYPE_DEFAULT) : ByteBuffer(res, Reserve{}), m_opcode(opcode), _connection(connection) { } - WorldPacket(uint32 opcode, size_t res, Resize, ConnectionType connection = CONNECTION_TYPE_DEFAULT) : ByteBuffer(res, Resize{}), + explicit WorldPacket(uint32 opcode, size_t res, Resize, ConnectionType connection = CONNECTION_TYPE_DEFAULT) : ByteBuffer(res, Resize{}), m_opcode(opcode), _connection(connection) { } - WorldPacket(uint32 opcode, size_t res, ConnectionType connection = CONNECTION_TYPE_DEFAULT) : WorldPacket(opcode, res, Reserve{}, connection) { } + explicit WorldPacket(uint32 opcode, size_t res, ConnectionType connection = CONNECTION_TYPE_DEFAULT) : WorldPacket(opcode, res, Reserve{}, connection) { } - WorldPacket(WorldPacket&& packet) noexcept : ByteBuffer(std::move(packet)), m_opcode(packet.m_opcode), _connection(packet._connection), m_receivedTime(packet.m_receivedTime) - { - } + WorldPacket(WorldPacket&& packet) noexcept : ByteBuffer(std::move(packet)), + m_opcode(packet.m_opcode), _connection(packet._connection), m_receivedTime(packet.m_receivedTime) { } WorldPacket(WorldPacket const& right) = default; + explicit WorldPacket(std::vector<uint8>&& buffer, ConnectionType connection) : ByteBuffer(std::move(buffer)), + m_opcode(UNKNOWN_OPCODE), _connection(connection) { } + WorldPacket& operator=(WorldPacket const& right) { if (this != &right) @@ -71,8 +72,6 @@ class WorldPacket : public ByteBuffer return *this; } - WorldPacket(MessageBuffer&& buffer, ConnectionType connection) : ByteBuffer(std::move(buffer)), m_opcode(UNKNOWN_OPCODE), _connection(connection) { } - void Initialize(uint32 opcode, size_t newres = 200, ConnectionType connection = CONNECTION_TYPE_DEFAULT) { clear(); diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index 10a5446bc23..210b2098833 100644 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -157,7 +157,7 @@ void WorldSocketProtocolInitializer::HandleDataReady() { try { - ByteBuffer buffer(std::move(_packetBuffer)); + ByteBuffer buffer(std::move(_packetBuffer).Release()); if (buffer.ReadString(ClientConnectionInitialize.length()) != ClientConnectionInitialize) { _socket->CloseSocket(); @@ -365,7 +365,7 @@ WorldSocket::ReadDataHandlerResult WorldSocket::ReadDataHandler() return ReadDataHandlerResult::Error; } - WorldPacket packet(std::move(_packetBuffer), GetConnectionType()); + WorldPacket packet(std::move(_packetBuffer).Release(), GetConnectionType()); OpcodeClient opcode = packet.read<OpcodeClient>(); if (!opcodeTable.IsValid(opcode)) { diff --git a/src/server/shared/Packets/ByteBuffer.cpp b/src/server/shared/Packets/ByteBuffer.cpp index f49c36a1cc0..c8980a93fe4 100644 --- a/src/server/shared/Packets/ByteBuffer.cpp +++ b/src/server/shared/Packets/ByteBuffer.cpp @@ -18,8 +18,6 @@ #include "ByteBuffer.h" #include "Errors.h" #include "Log.h" -#include "MessageBuffer.h" -#include "Util.h" #include <utf8.h> #include <algorithm> #include <sstream> @@ -35,10 +33,6 @@ ByteBufferInvalidValueException::ByteBufferInvalidValueException(char const* typ { } -ByteBuffer::ByteBuffer(MessageBuffer&& buffer) : _rpos(0), _wpos(0), _bitpos(InitialBitPos), _curbitval(0), _storage(buffer.Move()) -{ -} - ByteBuffer& ByteBuffer::operator>>(float& value) { read(&value, 1); diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h index f61a72f3664..94c22206aa0 100644 --- a/src/server/shared/Packets/ByteBuffer.h +++ b/src/server/shared/Packets/ByteBuffer.h @@ -25,8 +25,6 @@ #include <vector> #include <cstring> -class MessageBuffer; - // Root of ByteBuffer exception hierarchy class TC_SHARED_API ByteBufferException : public std::exception { @@ -58,34 +56,32 @@ class TC_SHARED_API ByteBuffer constexpr static size_t DEFAULT_SIZE = 0x1000; constexpr static uint8 InitialBitPos = 8; - // constructor - ByteBuffer() : _rpos(0), _wpos(0), _bitpos(InitialBitPos), _curbitval(0) - { - _storage.reserve(DEFAULT_SIZE); - } - // reserve/resize tag struct Reserve { }; struct Resize { }; - ByteBuffer(size_t size, Reserve) : _rpos(0), _wpos(0), _bitpos(InitialBitPos), _curbitval(0) + // constructor + explicit ByteBuffer() : ByteBuffer(DEFAULT_SIZE, Reserve{}) { } + + explicit ByteBuffer(size_t size, Reserve) : _rpos(0), _wpos(0), _bitpos(InitialBitPos), _curbitval(0) { _storage.reserve(size); } - ByteBuffer(size_t size, Resize) : _rpos(0), _wpos(size), _bitpos(InitialBitPos), _curbitval(0) + explicit ByteBuffer(size_t size, Resize) : _rpos(0), _wpos(size), _bitpos(InitialBitPos), _curbitval(0) { _storage.resize(size); } - ByteBuffer(ByteBuffer&& buf) noexcept : _rpos(buf._rpos), _wpos(buf._wpos), - _bitpos(buf._bitpos), _curbitval(buf._curbitval), _storage(buf.Move()) { } - ByteBuffer(ByteBuffer const& right) = default; - ByteBuffer(MessageBuffer&& buffer); + ByteBuffer(ByteBuffer&& buf) noexcept : _rpos(buf._rpos), _wpos(buf._wpos), + _bitpos(buf._bitpos), _curbitval(buf._curbitval), _storage(std::move(buf).Release()) { } + + explicit ByteBuffer(std::vector<uint8>&& buffer) noexcept : _rpos(0), _wpos(buffer.size()), + _bitpos(InitialBitPos), _curbitval(0), _storage(std::move(buffer)) { } - std::vector<uint8>&& Move() noexcept + std::vector<uint8>&& Release() && noexcept { _rpos = 0; _wpos = 0; @@ -94,19 +90,7 @@ class TC_SHARED_API ByteBuffer return std::move(_storage); } - ByteBuffer& operator=(ByteBuffer const& right) - { - if (this != &right) - { - _rpos = right._rpos; - _wpos = right._wpos; - _bitpos = right._bitpos; - _curbitval = right._curbitval; - _storage = right._storage; - } - - return *this; - } + ByteBuffer& operator=(ByteBuffer const& right) = default; ByteBuffer& operator=(ByteBuffer&& right) noexcept { @@ -116,7 +100,7 @@ class TC_SHARED_API ByteBuffer _wpos = right._wpos; _bitpos = right._bitpos; _curbitval = right._curbitval; - _storage = right.Move(); + _storage = std::move(right).Release(); } return *this; |