summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-08-31 13:53:06 +0300
committerAndrei Karas <akaras@inbox.ru>2014-08-31 13:53:06 +0300
commita63248380554067d4291c653b4ba82db36fbc821 (patch)
treec4ad257d15fc44179ccafe9c3e887bfce710967c /src/net
parent1d5aa3c38c3a545ad0056613f561ac01d945b2ed (diff)
downloadmanaverse-a63248380554067d4291c653b4ba82db36fbc821.tar.gz
manaverse-a63248380554067d4291c653b4ba82db36fbc821.tar.bz2
manaverse-a63248380554067d4291c653b4ba82db36fbc821.tar.xz
manaverse-a63248380554067d4291c653b4ba82db36fbc821.zip
Add comments for inbound packet fields in debug log.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/eathena/messagein.cpp8
-rw-r--r--src/net/eathena/messagein.h6
-rw-r--r--src/net/messagein.cpp47
-rw-r--r--src/net/messagein.h30
-rw-r--r--src/net/tmwa/messagein.cpp10
-rw-r--r--src/net/tmwa/messagein.h6
6 files changed, 63 insertions, 44 deletions
diff --git a/src/net/eathena/messagein.cpp b/src/net/eathena/messagein.cpp
index 6e542b698..f9d17bfd5 100644
--- a/src/net/eathena/messagein.cpp
+++ b/src/net/eathena/messagein.cpp
@@ -46,7 +46,7 @@ void MessageIn::postInit()
mId = readInt16();
}
-int16_t MessageIn::readInt16()
+int16_t MessageIn::readInt16(const char *const str)
{
int16_t value = -1;
if (mPos + 2 <= mLength)
@@ -61,11 +61,11 @@ int16_t MessageIn::readInt16()
}
mPos += 2;
PacketCounters::incInBytes(2);
- DEBUGLOG("readInt16: " + toStringPrint(static_cast<int>(value)));
+ DEBUGLOG2("readInt16: " + toStringPrint(static_cast<int>(value)), str);
return value;
}
-int32_t MessageIn::readInt32()
+int32_t MessageIn::readInt32(const char *const str)
{
int32_t value = -1;
if (mPos + 4 <= mLength)
@@ -80,7 +80,7 @@ int32_t MessageIn::readInt32()
}
mPos += 4;
PacketCounters::incInBytes(4);
- DEBUGLOG("readInt32: " + toStringPrint(value));
+ DEBUGLOG2("readInt32: " + toStringPrint(value), str);
return value;
}
diff --git a/src/net/eathena/messagein.h b/src/net/eathena/messagein.h
index ad7fd7663..3c267a888 100644
--- a/src/net/eathena/messagein.h
+++ b/src/net/eathena/messagein.h
@@ -47,8 +47,10 @@ class MessageIn final : public Net::MessageIn
void postInit();
- int16_t readInt16(); /**< Reads a short. */
- int32_t readInt32(); /**< Reads a long. */
+ /**< Reads a short. */
+ int16_t readInt16(const char *const str = nullptr);
+ /**< Reads a long. */
+ int32_t readInt32(const char *const str = nullptr);
};
} // namespace EAthena
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index ccc80a838..b131e85e0 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -47,7 +47,7 @@ MessageIn::MessageIn(const char *const data, const unsigned int length) :
DEBUGLOG("MessageIn");
}
-unsigned char MessageIn::readUInt8()
+unsigned char MessageIn::readUInt8(const char *const str)
{
unsigned char value = static_cast<unsigned char>(-1);
if (mPos < mLength)
@@ -55,11 +55,11 @@ unsigned char MessageIn::readUInt8()
mPos += 1;
PacketCounters::incInBytes(1);
- DEBUGLOG("readUInt8: " + toStringPrint(static_cast<int>(value)));
+ DEBUGLOG2("readUInt8: " + toStringPrint(static_cast<int>(value)), str);
return value;
}
-signed char MessageIn::readInt8()
+signed char MessageIn::readInt8(const char *const str)
{
signed char value = static_cast<signed char>(-1);
if (mPos < mLength)
@@ -67,7 +67,7 @@ signed char MessageIn::readInt8()
mPos += 1;
PacketCounters::incInBytes(1);
- DEBUGLOG("readInt8: " + toStringPrint(static_cast<int>(value)));
+ DEBUGLOG2("readInt8: " + toStringPrint(static_cast<int>(value)), str);
return value;
}
@@ -101,8 +101,10 @@ uint8_t MessageIn::fromServerDirection(const uint8_t serverDir)
}
}
-void MessageIn::readCoordinates(uint16_t &restrict x, uint16_t &restrict y,
- uint8_t &restrict direction)
+void MessageIn::readCoordinates(uint16_t &restrict x,
+ uint16_t &restrict y,
+ uint8_t &restrict direction,
+ const char *const str)
{
if (mPos + 3 <= mLength)
{
@@ -115,10 +117,10 @@ void MessageIn::readCoordinates(uint16_t &restrict x, uint16_t &restrict y,
const uint8_t serverDir = static_cast<uint8_t>(data[2] & 0x000f);
direction = fromServerDirection(serverDir);
- DEBUGLOG(std::string("readCoordinates: ").append(toString(
+ DEBUGLOG2(std::string("readCoordinates: ").append(toString(
static_cast<int>(x))).append(",").append(toString(
static_cast<int>(y))).append(",").append(toString(
- static_cast<int>(serverDir))));
+ static_cast<int>(serverDir))), str);
}
else
{
@@ -134,7 +136,8 @@ void MessageIn::readCoordinates(uint16_t &restrict x, uint16_t &restrict y,
void MessageIn::readCoordinatePair(uint16_t &restrict srcX,
uint16_t &restrict srcY,
uint16_t &restrict dstX,
- uint16_t &restrict dstY)
+ uint16_t &restrict dstY,
+ const char *const str)
{
if (mPos + 5 <= mLength)
{
@@ -150,11 +153,11 @@ void MessageIn::readCoordinatePair(uint16_t &restrict srcX,
temp = MAKEWORD(data[2], data[1] & 0x003f);
srcY = static_cast<uint16_t>(temp >> 4);
- DEBUGLOG(std::string("readCoordinatePair: ").append(toString(
+ DEBUGLOG2(std::string("readCoordinatePair: ").append(toString(
static_cast<int>(srcX))).append(",").append(toString(
static_cast<int>(srcY))).append(" ").append(toString(
static_cast<int>(dstX))).append(",").append(toString(
- static_cast<int>(dstY))));
+ static_cast<int>(dstY))), str);
}
else
{
@@ -168,14 +171,14 @@ void MessageIn::readCoordinatePair(uint16_t &restrict srcX,
PacketCounters::incInBytes(5);
}
-void MessageIn::skip(const unsigned int length)
+void MessageIn::skip(const unsigned int length, const char *const str)
{
mPos += length;
PacketCounters::incInBytes(length);
- DEBUGLOG("skip: " + toString(static_cast<int>(length)));
+ DEBUGLOG2("skip: " + toString(static_cast<int>(length)), str);
}
-std::string MessageIn::readString(int length)
+std::string MessageIn::readString(int length, const char *const dstr)
{
// Get string length
if (length < 0)
@@ -185,7 +188,7 @@ std::string MessageIn::readString(int length)
if (length < 0 || mPos + length > mLength)
{
mPos = mLength + 1;
- DEBUGLOG("readString error");
+ DEBUGLOG2("readString error", dstr);
return "";
}
@@ -198,11 +201,11 @@ std::string MessageIn::readString(int length)
? stringEnd - stringBeg : static_cast<size_t>(length));
mPos += length;
PacketCounters::incInBytes(length);
- DEBUGLOG("readString: " + str);
+ DEBUGLOG2("readString: " + str, dstr);
return str;
}
-std::string MessageIn::readRawString(int length)
+std::string MessageIn::readRawString(int length, const char *const dstr)
{
// Get string length
if (length < 0)
@@ -224,7 +227,7 @@ std::string MessageIn::readRawString(int length)
mPos += length;
PacketCounters::incInBytes(length);
- DEBUGLOG("readString: " + str);
+ DEBUGLOG2("readString: " + str, dstr);
if (stringEnd)
{
@@ -237,7 +240,7 @@ std::string MessageIn::readRawString(int length)
stringEnd2 ? stringEnd2 - stringBeg2 : len2);
if (hiddenPart.length() > 0)
{
- DEBUGLOG("readString2: " + hiddenPart);
+ DEBUGLOG2("readString2: " + hiddenPart, dstr);
return str.append("|").append(hiddenPart);
}
}
@@ -245,7 +248,7 @@ std::string MessageIn::readRawString(int length)
return str;
}
-unsigned char *MessageIn::readBytes(int length)
+unsigned char *MessageIn::readBytes(int length, const char *const dstr)
{
// Get string length
if (length < 0)
@@ -255,7 +258,7 @@ unsigned char *MessageIn::readBytes(int length)
if (length < 0 || mPos + length > mLength)
{
mPos = mLength + 1;
- DEBUGLOG("readBytesString error");
+ DEBUGLOG2("readBytesString error", dstr);
return nullptr;
}
@@ -279,6 +282,8 @@ unsigned char *MessageIn::readBytes(int length)
else
str.append("_");
}
+ if (dstr)
+ logger->dlog(dstr);
logger->dlog("ReadBytes: " + str);
#endif
diff --git a/src/net/messagein.h b/src/net/messagein.h
index 932764b8c..708041c2c 100644
--- a/src/net/messagein.h
+++ b/src/net/messagein.h
@@ -58,13 +58,17 @@ class MessageIn notfinal
unsigned int getUnreadLength() const A_WARN_UNUSED
{ return mLength > mPos ? mLength - mPos : 0; }
- virtual unsigned char readUInt8(); /**< Reads a byte. */
+ /**< Reads a byte. */
+ virtual unsigned char readUInt8(const char *const str = nullptr);
- virtual signed char readInt8(); /**< Reads a byte. */
+ /**< Reads a byte. */
+ virtual signed char readInt8(const char *const str = nullptr);
- virtual int16_t readInt16() = 0; /**< Reads a short. */
+ /**< Reads a short. */
+ virtual int16_t readInt16(const char *const str = nullptr) = 0;
- virtual int readInt32() = 0; /**< Reads a long. */
+ /**< Reads a long. */
+ virtual int readInt32(const char *const str = nullptr) = 0;
/**
* Reads a special 3 byte block used by eAthena, containing x and y
@@ -72,7 +76,8 @@ class MessageIn notfinal
*/
virtual void readCoordinates(uint16_t &restrict x,
uint16_t &restrict y,
- uint8_t &restrict direction);
+ uint8_t &restrict direction,
+ const char *const str = nullptr);
/**
* Reads a special 5 byte block used by eAthena, containing a source
@@ -81,23 +86,28 @@ class MessageIn notfinal
virtual void readCoordinatePair(uint16_t &restrict srcX,
uint16_t &restrict srcY,
uint16_t &restrict dstX,
- uint16_t &restrict dstY);
+ uint16_t &restrict dstY,
+ const char *const str = nullptr);
/**
* Skips a given number of bytes.
*/
- virtual void skip(const unsigned int length);
+ virtual void skip(const unsigned int length,
+ const char *const str = nullptr);
/**
* Reads a string. If a length is not given (-1), it is assumed
* that the length of the string is stored in a short at the
* start of the string.
*/
- virtual std::string readString(int length = -1);
+ virtual std::string readString(int length = -1,
+ const char *const dstr = nullptr);
- virtual std::string readRawString(int length);
+ virtual std::string readRawString(int length,
+ const char *const dstr = nullptr);
- unsigned char *readBytes(int length);
+ unsigned char *readBytes(int length,
+ const char *const dstr = nullptr);
virtual ~MessageIn()
{ }
diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp
index 0e855ef56..18686f347 100644
--- a/src/net/tmwa/messagein.cpp
+++ b/src/net/tmwa/messagein.cpp
@@ -43,10 +43,10 @@ MessageIn::MessageIn(const char *const data, const unsigned int length) :
void MessageIn::postInit()
{
// Read the message ID
- mId = readInt16();
+ mId = readInt16("packet id");
}
-int16_t MessageIn::readInt16()
+int16_t MessageIn::readInt16(const char *const str)
{
int16_t value = -1;
if (mPos + 2 <= mLength)
@@ -61,11 +61,11 @@ int16_t MessageIn::readInt16()
}
mPos += 2;
PacketCounters::incInBytes(2);
- DEBUGLOG("readInt16: " + toStringPrint(static_cast<int>(value)));
+ DEBUGLOG2("readInt16: " + toStringPrint(static_cast<int>(value)), str);
return value;
}
-int32_t MessageIn::readInt32()
+int32_t MessageIn::readInt32(const char *const str)
{
int32_t value = -1;
if (mPos + 4 <= mLength)
@@ -80,7 +80,7 @@ int32_t MessageIn::readInt32()
}
mPos += 4;
PacketCounters::incInBytes(4);
- DEBUGLOG("readInt32: " + toStringPrint(value));
+ DEBUGLOG2("readInt32: " + toStringPrint(value), str);
return value;
}
diff --git a/src/net/tmwa/messagein.h b/src/net/tmwa/messagein.h
index 8dd95a478..26ce4612c 100644
--- a/src/net/tmwa/messagein.h
+++ b/src/net/tmwa/messagein.h
@@ -47,8 +47,10 @@ class MessageIn final : public Net::MessageIn
void postInit();
- int16_t readInt16(); /**< Reads a short. */
- int32_t readInt32(); /**< Reads a long. */
+ /**< Reads a short. */
+ int16_t readInt16(const char *const str = nullptr);
+ /**< Reads a long. */
+ int32_t readInt32(const char *const str = nullptr);
};
} // namespace TmwAthena