diff options
| author | Shocker <shocker@freakz.ro> | 2011-11-26 22:23:35 +0200 |
|---|---|---|
| committer | Shocker <shocker@freakz.ro> | 2011-11-26 22:23:35 +0200 |
| commit | 4b0464056283bd651622ee7870263c462a790d9c (patch) | |
| tree | 40cba9d0f1bd987cb8390b4a74af0ef75655a33c /src | |
| parent | 784a2fa29ab025ce4cf36b3ff57b2892d525375d (diff) | |
| parent | ccb89b0347e6317c655ab32230d07326f2e9b242 (diff) | |
Merge branch '4.x' of github.com:TrinityCore/TrinityCore into 4.x
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/game/DataStores/DB2Structure.h | 2 | ||||
| -rwxr-xr-x | src/server/game/Entities/Player/Player.cpp | 2 | ||||
| -rwxr-xr-x | src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp | 17 | ||||
| -rwxr-xr-x | src/server/game/Server/WorldSession.cpp | 2 | ||||
| -rw-r--r-- | src/server/shared/Packets/ByteBuffer.cpp | 89 | ||||
| -rwxr-xr-x | src/server/shared/Packets/ByteBuffer.h | 179 |
6 files changed, 283 insertions, 8 deletions
diff --git a/src/server/game/DataStores/DB2Structure.h b/src/server/game/DataStores/DB2Structure.h index 23bf8339c0d..ae070924b5b 100644 --- a/src/server/game/DataStores/DB2Structure.h +++ b/src/server/game/DataStores/DB2Structure.h @@ -45,7 +45,7 @@ struct ItemEntry struct ItemCurrencyCostEntry { - uint32 Id; + //uint32 Id; uint32 ItemId; }; diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index bc3a1be7ff9..ff2daa14589 100755 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -16520,7 +16520,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) SetInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, fields[48].GetUInt32()); // set which actionbars the client has active - DO NOT REMOVE EVER AGAIN (can be changed though, if it does change fieldwise) - SetByteValue(PLAYER_FIELD_BYTES, 2, fields[62].GetUInt8()); + SetByteValue(PLAYER_FIELD_BYTES, 2, fields[60].GetUInt8()); InitDisplayIds(); diff --git a/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp b/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp index 507fe47ef15..2024771e31b 100755 --- a/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp @@ -842,7 +842,22 @@ void WorldSession::HandlePlayerLoginOpcode(WorldPacket & recv_data) sLog->outStaticDebug("WORLD: Recvd Player Logon Message"); - recv_data >> playerGuid; + BitStream* mask = recv_data.ReadBitStream(8); + + ByteBuffer* bytes = new ByteBuffer(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; + + playerGuid = BitConverter::ToUInt64((*bytes)); + + sLog->outDebug(LOG_FILTER_NETWORKIO, "Character (Guid: %u) logging in", playerGuid); if (!CharCanLogin(GUID_LOPART(playerGuid))) { diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 75d8ed0f7a0..976ef4bd70b 100755 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -159,7 +159,7 @@ void WorldSession::SendPacket(WorldPacket const* packet) if (!m_Socket) return; - if (packet->GetOpcode() == UNKNOWN_OPCODE) + if (packet->GetOpcode() == NULL || packet->GetOpcode() == UNKNOWN_OPCODE) { sLog->outError("Sending unknown opcode - prevented. Trace:"); ACE_Stack_Trace trace; diff --git a/src/server/shared/Packets/ByteBuffer.cpp b/src/server/shared/Packets/ByteBuffer.cpp new file mode 100644 index 00000000000..cdb73987453 --- /dev/null +++ b/src/server/shared/Packets/ByteBuffer.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2008-2011 TrinityCore <http://www.trinitycore.org/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "ByteBuffer.h" + +void BitStream::Clear() +{ + _data.clear(); + _rpos = _wpos = 0; +} + +uint8 BitStream::GetBit(uint32 bit) +{ + ASSERT(_data.size() > bit); + return _data[bit]; +} + +uint8 BitStream::ReadBit() +{ + ASSERT(_data.size() < _rpos); + uint8 b = _data[_rpos]; + ++_rpos; + return b; +} + +void BitStream::WriteBit(uint32 bit) +{ + _data.push_back(bit ? uint8(1) : uint8(0)); + ++_wpos; +} + +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(); +} + +void BitStream::Reverse() +{ + uint32 len = GetLenght(); + std::vector<uint8> b = _data; + Clear(); + + for(uint32 i = len; i > 0; --i) + WriteBit(b[i-1]); +} + +void BitStream::Print() +{ + if (!sLog->IsOutDebug()) + return; + std::stringstream ss; + ss << "BitStream: "; + for (uint32 i = 0; i < GetLenght(); ++i) + ss << uint32(GetBit(i)) << " "; + + 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) + { + for (size_t i = 0; i < res; ++i) + { + *this << uint8(0); + } + } 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 a4a996b299a..c970f32380e 100755 --- a/src/server/shared/Packets/ByteBuffer.h +++ b/src/server/shared/Packets/ByteBuffer.h @@ -24,6 +24,8 @@ #include "Logging/Log.h" #include "Utilities/ByteConverter.h" + + class ByteBufferException { public: @@ -45,6 +47,45 @@ class ByteBufferException size_t size; }; +class BitStream +{ + public: + BitStream(): _rpos(0), _wpos(0) {} + + BitStream(uint32 val, size_t len): _rpos(0), _wpos(0) + { + WriteBits(val, len); + } + + void Clear(); + uint8 GetBit(uint32 bit); + uint8 ReadBit(); + void WriteBit(uint32 bit); + template <typename T> void WriteBits(T value, size_t bits); + bool Emtpy (); + void Reverse(); + void Print(); + + size_t GetLenght () { return _data.size();} + uint32 GetReadPosition() { return _rpos; } + uint32 GetWritePosition() { return _wpos; } + void SetReadPos (uint32 pos) { _rpos = pos; } + + uint8 operator[](uint32 pos) const + { + return _data[pos]; + } + + uint8& operator[] (const uint32 pos) + { + return _data[pos]; + } + + private: + std::vector<uint8> _data; + uint32 _rpos, _wpos; +}; + class ByteBuffer { public: @@ -57,10 +98,7 @@ class ByteBuffer } // constructor - ByteBuffer(size_t res): _rpos(0), _wpos(0), _bitpos(8), _curbitval(0) - { - _storage.reserve(res); - } + ByteBuffer(size_t res, bool init = false); // copy constructor ByteBuffer(const ByteBuffer &buf): _rpos(buf._rpos), _wpos(buf._wpos), _storage(buf._storage), _bitpos(buf._bitpos), _curbitval(buf._curbitval) { } @@ -135,6 +173,14 @@ class ByteBuffer return value; } + BitStream* ReadBitStream(uint32 len) + { + BitStream* b = new BitStream(); + for (uint32 i = 0; i < len; ++i) + b->WriteBit(readBit()); + return b; + } + template <typename T> void put(size_t pos, T value) { EndianConvert(value); @@ -302,6 +348,13 @@ class ByteBuffer return read<uint8>(pos); } + uint8& operator[] (const size_t pos) + { + if (pos >= size()) + throw ByteBufferException(false, pos, 1, size()); + return _storage[pos]; + } + size_t rpos() const { return _rpos; } size_t rpos(size_t rpos_) @@ -381,6 +434,83 @@ class ByteBuffer } } + uint8 ReadUInt8() + { + uint8 u = 0; + (*this) >> u; + return u; + } + + uint16 ReadUInt16() + { + uint16 u = 0; + (*this) >> u; + return u; + } + + uint32 ReadUInt32() + { + uint32 u = 0; + (*this) >> u; + return u; + } + + uint64 ReadUInt64() + { + uint64 u = 0; + (*this) >> u; + return u; + } + + int8 ReadInt8() + { + int8 u = 0; + (*this) >> u; + return u; + } + + int16 ReadInt16() + { + int16 u = 0; + (*this) >> u; + return u; + } + + int32 ReadInt32() + { + uint32 u = 0; + (*this) >> u; + return u; + } + + int64 ReadInt64() + { + int64 u = 0; + (*this) >> u; + return u; + } + + std::string ReadString() + { + std::string s = 0; + (*this) >> s; + return s; + } + + bool ReadBoolean() + { + uint8 b = 0; + (*this) >> b; + return b > 0 ? true : false; + } + + float ReadSingle() + { + float f = 0; + (*this) >> f; + return f; + } + const uint8 *contents() const { return &_storage[0]; } size_t size() const { return _storage.size(); } @@ -657,5 +787,46 @@ inline void ByteBuffer::read_skip<std::string>() { read_skip<char*>(); } + +class BitConverter +{ + public: + + static uint8 ToUInt8(ByteBuffer buff, size_t start = 0) + { + return buff.read<uint8>(start); + } + + static uint16 ToUInt16(ByteBuffer buff, size_t start = 0) + { + return buff.read<uint16>(start); + } + + static uint32 ToUInt32(ByteBuffer buff, size_t start = 0) + { + return buff.read<uint32>(start); + } + + static uint64 ToUInt64(ByteBuffer buff, size_t start = 0) + { + return buff.read<uint64>(start); + } + + static int16 ToInt16(ByteBuffer buff, size_t start = 0) + { + return buff.read<int16>(start); + } + + static int32 ToInt32(ByteBuffer buff, size_t start = 0) + { + return buff.read<int32>(start); + } + + static int64 ToInt64(ByteBuffer buff, size_t start = 0) + { + return buff.read<int64>(start); + } +}; + #endif |
