diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp | 24 | ||||
-rw-r--r-- | src/server/shared/Packets/ByteBuffer.cpp | 18 | ||||
-rwxr-xr-x | src/server/shared/Packets/ByteBuffer.h | 53 |
3 files changed, 49 insertions, 46 deletions
diff --git a/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp b/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp index 2024771e31b..3e2c0197c5e 100755 --- a/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp @@ -842,22 +842,22 @@ void WorldSession::HandlePlayerLoginOpcode(WorldPacket & recv_data) sLog->outStaticDebug("WORLD: Recvd Player Logon Message"); - BitStream* mask = recv_data.ReadBitStream(8); + BitStream mask = recv_data.ReadBitStream(8); - ByteBuffer* bytes = new ByteBuffer(8, true); + ByteBuffer bytes(8, true); - if ((*mask)[6]) (*bytes)[5] = recv_data.ReadUInt8() ^ 1; - if ((*mask)[0]) (*bytes)[0] = recv_data.ReadUInt8() ^ 1; - if ((*mask)[4]) (*bytes)[3] = recv_data.ReadUInt8() ^ 1; - if ((*mask)[1]) (*bytes)[4] = recv_data.ReadUInt8() ^ 1; - if ((*mask)[2]) (*bytes)[7] = recv_data.ReadUInt8() ^ 1; - if ((*mask)[5]) (*bytes)[2] = recv_data.ReadUInt8() ^ 1; - if ((*mask)[7]) (*bytes)[6] = recv_data.ReadUInt8() ^ 1; - if ((*mask)[3]) (*bytes)[1] = recv_data.ReadUInt8() ^ 1; + if (mask[6]) bytes[5] = recv_data.ReadUInt8() ^ 1; + if (mask[0]) bytes[0] = recv_data.ReadUInt8() ^ 1; + if (mask[4]) bytes[3] = recv_data.ReadUInt8() ^ 1; + if (mask[1]) bytes[4] = recv_data.ReadUInt8() ^ 1; + if (mask[2]) bytes[7] = recv_data.ReadUInt8() ^ 1; + if (mask[5]) bytes[2] = recv_data.ReadUInt8() ^ 1; + if (mask[7]) bytes[6] = recv_data.ReadUInt8() ^ 1; + if (mask[3]) bytes[1] = recv_data.ReadUInt8() ^ 1; - playerGuid = BitConverter::ToUInt64((*bytes)); + playerGuid = BitConverter::ToUInt64(bytes); - sLog->outDebug(LOG_FILTER_NETWORKIO, "Character (Guid: %u) logging in", playerGuid); + sLog->outDebug(LOG_FILTER_NETWORKIO, "Character (Guid: %u) logging in", playerGuid); if (!CharCanLogin(GUID_LOPART(playerGuid))) { diff --git a/src/server/shared/Packets/ByteBuffer.cpp b/src/server/shared/Packets/ByteBuffer.cpp index cdb73987453..f495982ac14 100644 --- a/src/server/shared/Packets/ByteBuffer.cpp +++ b/src/server/shared/Packets/ByteBuffer.cpp @@ -48,7 +48,7 @@ template <typename T> void BitStream::WriteBits(T value, size_t bits) for (int32 i = bits-1; i >= 0; --i) WriteBit((value >> i) & 1); } - + bool BitStream::Emtpy () { return _data.empty(); @@ -68,22 +68,22 @@ void BitStream::Print() { if (!sLog->IsOutDebug()) return; - std::stringstream ss; - ss << "BitStream: "; + std::stringstream ss; + ss << "BitStream: "; for (uint32 i = 0; i < GetLenght(); ++i) - ss << uint32(GetBit(i)) << " "; + ss << uint32(GetBit(i)) << " "; - sLog->outDebug(LOG_FILTER_NETWORKIO, ss.str().c_str()); + sLog->outDebug(LOG_FILTER_NETWORKIO, ss.str().c_str()); } ByteBuffer::ByteBuffer(size_t res, bool init): _rpos(0), _wpos(0), _bitpos(8), _curbitval(0) { if (init) { + _storage.resize(res); for (size_t i = 0; i < res; ++i) - { *this << uint8(0); - } - } else + } + else _storage.reserve(res); -}
\ No newline at end of file +} diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h index c970f32380e..46c5b555093 100755 --- a/src/server/shared/Packets/ByteBuffer.h +++ b/src/server/shared/Packets/ByteBuffer.h @@ -57,26 +57,28 @@ class BitStream WriteBits(val, len); } + BitStream(BitStream const& bs) : _rpos(bs._rpos), _wpos(bs._wpos), _data(bs._data) {} + void Clear(); uint8 GetBit(uint32 bit); uint8 ReadBit(); void WriteBit(uint32 bit); template <typename T> void WriteBits(T value, size_t bits); - bool Emtpy (); + bool Emtpy(); void Reverse(); - void Print(); - + void Print(); + size_t GetLenght () { return _data.size();} uint32 GetReadPosition() { return _rpos; } uint32 GetWritePosition() { return _wpos; } - void SetReadPos (uint32 pos) { _rpos = pos; } + void SetReadPos(uint32 pos) { _rpos = pos; } - uint8 operator[](uint32 pos) const + uint8 const& operator[](uint32 const pos) const { - return _data[pos]; + return _data[pos]; } - uint8& operator[] (const uint32 pos) + uint8& operator[] (uint32 const pos) { return _data[pos]; } @@ -173,11 +175,11 @@ class ByteBuffer return value; } - BitStream* ReadBitStream(uint32 len) + BitStream ReadBitStream(uint32 len) { - BitStream* b = new BitStream(); + BitStream b; for (uint32 i = 0; i < len; ++i) - b->WriteBit(readBit()); + b.WriteBit(readBit()); return b; } @@ -343,13 +345,15 @@ class ByteBuffer return *this; } - uint8 operator[](size_t pos) const + uint8& operator[](size_t const pos) { - return read<uint8>(pos); + if (pos >= size()) + throw ByteBufferException(false, pos, 1, size()); + return _storage[pos]; } - uint8& operator[] (const size_t pos) - { + uint8 const& operator[](size_t const pos) const + { if (pos >= size()) throw ByteBufferException(false, pos, 1, size()); return _storage[pos]; @@ -447,7 +451,7 @@ class ByteBuffer (*this) >> u; return u; } - + uint32 ReadUInt32() { uint32 u = 0; @@ -475,7 +479,7 @@ class ByteBuffer (*this) >> u; return u; } - + int32 ReadInt32() { uint32 u = 0; @@ -503,7 +507,7 @@ class ByteBuffer (*this) >> b; return b > 0 ? true : false; } - + float ReadSingle() { float f = 0; @@ -791,38 +795,37 @@ inline void ByteBuffer::read_skip<std::string>() class BitConverter { public: - - static uint8 ToUInt8(ByteBuffer buff, size_t start = 0) + static uint8 ToUInt8(ByteBuffer const& buff, size_t start = 0) { return buff.read<uint8>(start); } - static uint16 ToUInt16(ByteBuffer buff, size_t start = 0) + static uint16 ToUInt16(ByteBuffer const& buff, size_t start = 0) { return buff.read<uint16>(start); } - static uint32 ToUInt32(ByteBuffer buff, size_t start = 0) + static uint32 ToUInt32(ByteBuffer const& buff, size_t start = 0) { return buff.read<uint32>(start); } - static uint64 ToUInt64(ByteBuffer buff, size_t start = 0) + static uint64 ToUInt64(ByteBuffer const& buff, size_t start = 0) { return buff.read<uint64>(start); } - static int16 ToInt16(ByteBuffer buff, size_t start = 0) + static int16 ToInt16(ByteBuffer const& buff, size_t start = 0) { return buff.read<int16>(start); } - static int32 ToInt32(ByteBuffer buff, size_t start = 0) + static int32 ToInt32(ByteBuffer const& buff, size_t start = 0) { return buff.read<int32>(start); } - static int64 ToInt64(ByteBuffer buff, size_t start = 0) + static int64 ToInt64(ByteBuffer const& buff, size_t start = 0) { return buff.read<int64>(start); } |