diff options
Diffstat (limited to 'src/server/shared/Packets/ByteBuffer.h')
-rw-r--r-- | src/server/shared/Packets/ByteBuffer.h | 142 |
1 files changed, 32 insertions, 110 deletions
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; |