From 544de86739a85792be7e6883968b2af8590d0711 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 31 Aug 2014 14:11:23 +0300 Subject: Add comments for outbound packet fields in debug log. --- src/net/eathena/messageout.cpp | 17 +++++++++-------- src/net/eathena/messageout.h | 11 ++++++++--- src/net/messageout.cpp | 16 ++++++++++------ src/net/messageout.h | 19 ++++++++++++++----- src/net/tmwa/messageout.cpp | 17 +++++++++-------- src/net/tmwa/messageout.h | 11 ++++++++--- 6 files changed, 58 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/net/eathena/messageout.cpp b/src/net/eathena/messageout.cpp index 386f5b046..7c5d328cb 100644 --- a/src/net/eathena/messageout.cpp +++ b/src/net/eathena/messageout.cpp @@ -46,7 +46,7 @@ MessageOut::MessageOut(const int16_t id) : mData = mNetwork->mOutBuffer + static_cast(mNetwork->mOutSize); // +++ can be issue. call to virtual member - writeInt16(id); + writeInt16(id, "packet id"); } void MessageOut::expand(const size_t bytes) @@ -55,9 +55,9 @@ void MessageOut::expand(const size_t bytes) PacketCounters::incOutBytes(static_cast(bytes)); } -void MessageOut::writeInt16(const int16_t value) +void MessageOut::writeInt16(const int16_t value, const char *const str) { - DEBUGLOG("writeInt16: " + toStringPrint(static_cast(value))); + DEBUGLOG2("writeInt16: " + toStringPrint(static_cast(value)), str); expand(2); #if SDL_BYTEORDER == SDL_BIG_ENDIAN int16_t swap = SDL_Swap16(value); @@ -69,9 +69,9 @@ void MessageOut::writeInt16(const int16_t value) PacketCounters::incOutBytes(2); } -void MessageOut::writeInt32(const int32_t value) +void MessageOut::writeInt32(const int32_t value, const char *const str) { - DEBUGLOG("writeInt32: " + toStringPrint(value)); + DEBUGLOG2("writeInt32: " + toStringPrint(value), str); expand(4); #if SDL_BYTEORDER == SDL_BIG_ENDIAN int32_t swap = SDL_Swap32(value); @@ -89,12 +89,13 @@ static_cast(w)) >> 8)) void MessageOut::writeCoordinates(const uint16_t x, const uint16_t y, - unsigned char direction) + unsigned char direction, + const char *const str) { - DEBUGLOG(strprintf("writeCoordinates: %u,%u %u", + DEBUGLOG2(strprintf("writeCoordinates: %u,%u %u", static_cast(x), static_cast(y), - static_cast(direction))); + static_cast(direction)), str); unsigned char *const data = reinterpret_cast(mData) + static_cast(mPos); mNetwork->mOutSize += 3; diff --git a/src/net/eathena/messageout.h b/src/net/eathena/messageout.h index 121d5a88f..8834d44fe 100644 --- a/src/net/eathena/messageout.h +++ b/src/net/eathena/messageout.h @@ -47,16 +47,21 @@ class MessageOut final : public Net::MessageOut A_DELETE_COPY(MessageOut) - void writeInt16(const int16_t value); /**< Writes a short. */ + /**< Writes a short. */ + void writeInt16(const int16_t value, + const char *const str = nullptr); - void writeInt32(const int32_t value); /**< Writes a long. */ + /**< Writes a long. */ + void writeInt32(const int32_t value, + const char *const str = nullptr); /** * Encodes coordinates and direction in 3 bytes. */ void writeCoordinates(const uint16_t x, const uint16_t y, - unsigned char direction); + unsigned char direction, + const char *const str = nullptr); void resetPos() { mPos = 0; } diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 16b205373..ff778d89a 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -45,16 +45,18 @@ MessageOut::MessageOut(const int16_t id A_UNUSED) : DEBUGLOG("MessageOut"); } -void MessageOut::writeInt8(const int8_t value) +void MessageOut::writeInt8(const int8_t value, const char *const str) { - DEBUGLOG("writeInt8: " + toStringPrint(static_cast(value))); + DEBUGLOG2("writeInt8: " + toStringPrint(static_cast(value)), str); expand(1); mData[mPos] = value; mPos += 1; PacketCounters::incOutBytes(1); } -void MessageOut::writeString(const std::string &string, int length) +void MessageOut::writeString(const std::string &string, + int length, + const char *const str) { int stringLength = static_cast(string.length()); if (length < 0) @@ -82,11 +84,13 @@ void MessageOut::writeString(const std::string &string, int length) } mPos += length; - DEBUGLOG("writeString: " + string); + DEBUGLOG2("writeString: " + string, str); PacketCounters::incOutBytes(length); } -void MessageOut::writeStringNoLog(const std::string &string, int length) +void MessageOut::writeStringNoLog(const std::string &string, + int length, + const char *const str) { int stringLength = static_cast(string.length()); if (length < 0) @@ -114,7 +118,7 @@ void MessageOut::writeStringNoLog(const std::string &string, int length) } mPos += length; - DEBUGLOG("writeString: ***"); + DEBUGLOG2("writeString: ***", str); PacketCounters::incOutBytes(length); } diff --git a/src/net/messageout.h b/src/net/messageout.h index 9d878db35..b2429ab33 100644 --- a/src/net/messageout.h +++ b/src/net/messageout.h @@ -40,24 +40,33 @@ class MessageOut notfinal public: A_DELETE_COPY(MessageOut) - virtual void writeInt8(const int8_t value); /**< Writes a byte. */ + /**< Writes a byte. */ + virtual void writeInt8(const int8_t value, + const char *const str = nullptr); - virtual void writeInt16(int16_t value) = 0; /**< Writes a short. */ + /**< Writes a short. */ + virtual void writeInt16(int16_t value, + const char *const str = nullptr) = 0; - virtual void writeInt32(int32_t value) = 0; /**< Writes a long. */ + /**< Writes a long. */ + virtual void writeInt32(int32_t value, + const char *const str = nullptr) = 0; /** * Writes a string. If a fixed length is not given (-1), it is stored * as a short at the start of the string. */ - virtual void writeString(const std::string &string, int length = -1); + virtual void writeString(const std::string &string, + int length = -1, + const char *const str = nullptr); /** * Writes a string. If a fixed length is not given (-1), it is stored * as a short at the start of the string. */ virtual void writeStringNoLog(const std::string &string, - int length = -1); + int length = -1, + const char *const str = nullptr); /** * Returns the content of the message. diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp index 31196a4a7..a740df563 100644 --- a/src/net/tmwa/messageout.cpp +++ b/src/net/tmwa/messageout.cpp @@ -46,7 +46,7 @@ MessageOut::MessageOut(const int16_t id) : mData = mNetwork->mOutBuffer + static_cast(mNetwork->mOutSize); // +++ can be issue. call to virtual member - writeInt16(id); + writeInt16(id, "packet id"); } void MessageOut::expand(const size_t bytes) @@ -55,9 +55,9 @@ void MessageOut::expand(const size_t bytes) PacketCounters::incOutBytes(static_cast(bytes)); } -void MessageOut::writeInt16(const int16_t value) +void MessageOut::writeInt16(const int16_t value, const char *const str) { - DEBUGLOG("writeInt16: " + toStringPrint(static_cast(value))); + DEBUGLOG2("writeInt16: " + toStringPrint(static_cast(value)), str); expand(2); #if SDL_BYTEORDER == SDL_BIG_ENDIAN int16_t swap = SDL_Swap16(value); @@ -69,9 +69,9 @@ void MessageOut::writeInt16(const int16_t value) PacketCounters::incOutBytes(2); } -void MessageOut::writeInt32(const int32_t value) +void MessageOut::writeInt32(const int32_t value, const char *const str) { - DEBUGLOG("writeInt32: " + toStringPrint(value)); + DEBUGLOG2("writeInt32: " + toStringPrint(value), str); expand(4); #if SDL_BYTEORDER == SDL_BIG_ENDIAN int32_t swap = SDL_Swap32(value); @@ -89,11 +89,12 @@ static_cast(w)) >> 8U)) void MessageOut::writeCoordinates(const uint16_t x, const uint16_t y, - unsigned char direction) + unsigned char direction, + const char *const str) { - DEBUGLOG(strprintf("writeCoordinates: %u,%u %u", + DEBUGLOG2(strprintf("writeCoordinates: %u,%u %u", static_cast(x), static_cast(y), - static_cast(direction))); + static_cast(direction)), str); unsigned char *const data = reinterpret_cast(mData) + static_cast(mPos); mNetwork->mOutSize += 3; diff --git a/src/net/tmwa/messageout.h b/src/net/tmwa/messageout.h index 57ba9e75b..7aba1677b 100644 --- a/src/net/tmwa/messageout.h +++ b/src/net/tmwa/messageout.h @@ -47,16 +47,21 @@ class MessageOut final : public Net::MessageOut A_DELETE_COPY(MessageOut) - void writeInt16(const int16_t value); /**< Writes a short. */ + /**< Writes a short. */ + void writeInt16(const int16_t value, + const char *const str = nullptr); - void writeInt32(const int32_t value); /**< Writes a long. */ + /**< Writes a long. */ + void writeInt32(const int32_t value, + const char *const str = nullptr); /** * Encodes coordinates and direction in 3 bytes. */ void writeCoordinates(const uint16_t x, const uint16_t y, - unsigned char direction); + unsigned char direction, + const char *const str = nullptr); void resetPos() { mPos = 0; } -- cgit v1.2.3-70-g09d2