diff options
| author | Spp <spp@jorge.gr> | 2013-03-25 14:34:22 +0100 |
|---|---|---|
| committer | Spp <spp@jorge.gr> | 2013-03-25 14:34:22 +0100 |
| commit | c97c381ea0b63963b3756f531b8c64636cb5d66b (patch) | |
| tree | c5a99580d20b16b3eb957faab142b7761fefd507 /src/server/shared/Packets | |
| parent | 132cc295ca7f1eeb29aaa1ff821faa47ef3478f9 (diff) | |
| parent | 1a6a23ec96c7646d2753198f93eaba62d2732a83 (diff) | |
Merge branch 'master' into 4.3.4
Conflicts:
src/server/game/Entities/Object/Object.cpp
src/server/game/Entities/Object/Object.h
src/server/game/Entities/Pet/Pet.cpp
src/server/game/Entities/Player/Player.cpp
src/server/game/Entities/Player/Player.h
src/server/game/Events/GameEventMgr.cpp
src/server/game/Loot/LootMgr.cpp
src/server/shared/Packets/ByteBuffer.h
Diffstat (limited to 'src/server/shared/Packets')
| -rw-r--r-- | src/server/shared/Packets/ByteBuffer.cpp | 95 | ||||
| -rw-r--r-- | src/server/shared/Packets/ByteBuffer.h | 142 |
2 files changed, 127 insertions, 110 deletions
diff --git a/src/server/shared/Packets/ByteBuffer.cpp b/src/server/shared/Packets/ByteBuffer.cpp new file mode 100644 index 00000000000..a14cf3477af --- /dev/null +++ b/src/server/shared/Packets/ByteBuffer.cpp @@ -0,0 +1,95 @@ +#include "ByteBuffer.h" +#include "Log.h" + +#include <ace/Stack_Trace.h> +#include <sstream> + +ByteBufferPositionException::ByteBufferPositionException(bool add, size_t pos, + size_t size, size_t valueSize) +{ + std::ostringstream ss; + ACE_Stack_Trace trace; + + ss << "Attempted to " << (add ? "put" : "get") << " value with size: " + << valueSize << " in ByteBuffer (pos: " << pos << " size: " << size + << ")\n\n" << trace.c_str(); + + message().assign(ss.str()); +} + +ByteBufferSourceException::ByteBufferSourceException(size_t pos, size_t size, + size_t valueSize) +{ + std::ostringstream ss; + ACE_Stack_Trace trace; + + ss << "Attempted to put a " + << (valueSize > 0 ? "NULL-pointer" : "zero-sized value") + << " in ByteBuffer (pos: " << pos << " size: " << size << ")\n\n" + << trace.c_str(); + + message().assign(ss.str()); +} + +void ByteBuffer::print_storage() const +{ + if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled trace output + return; + + std::ostringstream o; + o << "STORAGE_SIZE: " << size(); + for (uint32 i = 0; i < size(); ++i) + o << read<uint8>(i) << " - "; + o << " "; + + sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str()); +} + +void ByteBuffer::textlike() const +{ + if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled trace output + return; + + std::ostringstream o; + o << "STORAGE_SIZE: " << size(); + for (uint32 i = 0; i < size(); ++i) + { + char buf[1]; + snprintf(buf, 1, "%c", read<uint8>(i)); + o << buf; + } + o << " "; + sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str()); +} + +void ByteBuffer::hexlike() const +{ + if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled trace output + return; + + uint32 j = 1, k = 1; + + std::ostringstream o; + o << "STORAGE_SIZE: " << size(); + + for (uint32 i = 0; i < size(); ++i) + { + char buf[3]; + snprintf(buf, 1, "%2X ", read<uint8>(i)); + if ((i == (j * 8)) && ((i != (k * 16)))) + { + o << "| "; + ++j; + } + else if (i == (k * 16)) + { + o << "\n"; + ++k; + ++j; + } + + o << buf; + } + o << " "; + sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str()); +} diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h index 6504a645e2b..0f4221b53ff 100644 --- a/src/server/shared/Packets/ByteBuffer.h +++ b/src/server/shared/Packets/ByteBuffer.h @@ -19,66 +19,47 @@ #ifndef _BYTEBUFFER_H #define _BYTEBUFFER_H -#include "Common.h" +#include "Define.h" #include "Debugging/Errors.h" -#include "Log.h" #include "Utilities/ByteConverter.h" +#include <exception> +#include <list> +#include <map> +#include <string> +#include <vector> +#include <cstring> -class ByteBufferException +// Root of ByteBuffer exception hierarchy +class ByteBufferException : public std::exception { - public: - ByteBufferException(size_t pos, size_t size, size_t valueSize) - : Pos(pos), Size(size), ValueSize(valueSize) - { - } +public: + ~ByteBufferException() throw() { } - protected: - size_t Pos; - size_t Size; - size_t ValueSize; + char const * what() const throw() { return msg_.c_str(); } + +protected: + std::string & message() throw() { return msg_; } + +private: + std::string msg_; }; class ByteBufferPositionException : public ByteBufferException { - public: - ByteBufferPositionException(bool add, size_t pos, size_t size, size_t valueSize) - : ByteBufferException(pos, size, valueSize), _add(add) - { - PrintError(); - } - - protected: - void PrintError() const - { - ACE_Stack_Trace trace; +public: + ByteBufferPositionException(bool add, size_t pos, size_t size, size_t valueSize); - sLog->outError(LOG_FILTER_NETWORKIO, "Attempted to %s value with size: " SIZEFMTD " in ByteBuffer (pos: " SIZEFMTD " size: "SIZEFMTD")\n[Stack trace: %s]", - (_add ? "put" : "get"), ValueSize, Pos, Size, trace.c_str()); - } - - private: - bool _add; + ~ByteBufferPositionException() throw() { } }; class ByteBufferSourceException : public ByteBufferException { - public: - ByteBufferSourceException(size_t pos, size_t size, size_t valueSize) - : ByteBufferException(pos, size, valueSize) - { - PrintError(); - } +public: + ByteBufferSourceException(size_t pos, size_t size, size_t valueSize); - protected: - void PrintError() const - { - ACE_Stack_Trace trace; - - sLog->outError(LOG_FILTER_NETWORKIO, "Attempted to put a %s in ByteBuffer (pos: " SIZEFMTD " size: "SIZEFMTD ")\n[Stack trace: %s]", - (ValueSize > 0 ? "NULL-pointer" : "zero-sized value"), Pos, Size, trace.c_str()); - } + ~ByteBufferSourceException() throw() { } }; class ByteBuffer @@ -453,7 +434,7 @@ class ByteBuffer { if (_rpos + len > size()) throw ByteBufferPositionException(false, _rpos, len, size()); - memcpy(dest, &_storage[_rpos], len); + std::memcpy(dest, &_storage[_rpos], len); _rpos += len; } @@ -485,8 +466,7 @@ class ByteBuffer { if (!length) return std::string(); - char* buffer = new char[length + 1]; - memset(buffer, 0, length + 1); + char* buffer = new char[length + 1](); read((uint8*)buffer, length); std::string retval = buffer; delete[] buffer; @@ -504,8 +484,7 @@ class ByteBuffer uint32 ReadPackedTime() { uint32 packedDate = read<uint32>(); - tm lt; - memset(<, 0, sizeof(lt)); + tm lt = tm(); lt.tm_min = packedDate & 0x3F; lt.tm_hour = (packedDate >> 6) & 0x1F; @@ -565,7 +544,7 @@ class ByteBuffer if (_storage.size() < _wpos + cnt) _storage.resize(_wpos + cnt); - memcpy(&_storage[_wpos], src, cnt); + std::memcpy(&_storage[_wpos], src, cnt); _wpos += cnt; } @@ -618,71 +597,14 @@ class ByteBuffer if (!src) throw ByteBufferSourceException(_wpos, size(), cnt); - memcpy(&_storage[pos], src, cnt); + std::memcpy(&_storage[pos], src, cnt); } - void print_storage() const - { - if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled debug output - return; + void print_storage() const; - std::ostringstream o; - o << "STORAGE_SIZE: " << size(); - for (uint32 i = 0; i < size(); ++i) - o << read<uint8>(i) << " - "; - o << " "; + void textlike() const; - sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str()); - } - - void textlike() const - { - if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled debug output - return; - - std::ostringstream o; - o << "STORAGE_SIZE: " << size(); - for (uint32 i = 0; i < size(); ++i) - { - char buf[1]; - snprintf(buf, 1, "%c", read<uint8>(i)); - o << buf; - } - o << " "; - sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str()); - } - - void hexlike() const - { - if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled debug output - return; - - uint32 j = 1, k = 1; - - std::ostringstream o; - o << "STORAGE_SIZE: " << size(); - - for (uint32 i = 0; i < size(); ++i) - { - char buf[3]; - snprintf(buf, 1, "%2X ", read<uint8>(i)); - if ((i == (j * 8)) && ((i != (k * 16)))) - { - o << "| "; - ++j; - } - else if (i == (k * 16)) - { - o << "\n"; - ++k; - ++j; - } - - o << buf; - } - o << " "; - sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str()); - } + void hexlike() const; protected: size_t _rpos, _wpos, _bitpos; |
