summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-09-01 12:38:59 +0300
committerAndrei Karas <akaras@inbox.ru>2014-09-06 01:18:54 +0300
commit11d80e856811ceddec805ce68b0a17b13f5cf25e (patch)
tree31e4c919f5acd2e20b5f805bbe8524b1d0f9f754 /src
parenta15146e08d00f9986edfde7a15a70790b64cc1ce (diff)
downloadmanaverse-11d80e856811ceddec805ce68b0a17b13f5cf25e.tar.gz
manaverse-11d80e856811ceddec805ce68b0a17b13f5cf25e.tar.bz2
manaverse-11d80e856811ceddec805ce68b0a17b13f5cf25e.tar.xz
manaverse-11d80e856811ceddec805ce68b0a17b13f5cf25e.zip
In debug packets logging also display offset.
Diffstat (limited to 'src')
-rw-r--r--src/logger.cpp36
-rw-r--r--src/logger.h8
-rw-r--r--src/net/eathena/messagein.cpp5
-rw-r--r--src/net/eathena/messageout.cpp7
-rw-r--r--src/net/messagein.cpp26
-rw-r--r--src/net/messageout.cpp7
-rw-r--r--src/net/tmwa/messagein.cpp5
-rw-r--r--src/net/tmwa/messageout.cpp7
8 files changed, 68 insertions, 33 deletions
diff --git a/src/logger.cpp b/src/logger.cpp
index 024de4660..2b80602e8 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -120,7 +120,9 @@ void Logger::dlog(const std::string &str)
std::cout << timeStr.str() << str << std::endl;
}
-void Logger::dlog2(const std::string &str, const char* const comment)
+void Logger::dlog2(const std::string &str,
+ const int pos,
+ const char* const comment)
{
if (!mDebugLog)
return;
@@ -137,17 +139,41 @@ void Logger::dlog2(const std::string &str, const char* const comment)
if (mLogFile.is_open())
{
if (comment)
- mLogFile << timeStr.str() << str << ": " << comment << std::endl;
+ {
+ mLogFile << timeStr.str();
+ mLogFile.fill('0');
+ mLogFile.width(4);
+ mLogFile << pos << " ";
+ mLogFile << str << ": " << comment << std::endl;
+ }
else
- mLogFile << timeStr.str() << str << std::endl;
+ {
+ mLogFile << timeStr.str();
+ mLogFile.fill('0');
+ mLogFile.width(4);
+ mLogFile << pos << " ";
+ mLogFile << str << std::endl;
+ }
}
if (mLogToStandardOut)
{
if (comment)
- std::cout << timeStr.str() << str << ": " << comment << std::endl;
+ {
+ std::cout << timeStr.str();
+ std::cout.fill('0');
+ std::cout.width(4);
+ std::cout << pos << " ";
+ std::cout << str << ": " << comment << std::endl;
+ }
else
- std::cout << timeStr.str() << str << std::endl;
+ {
+ std::cout << timeStr.str();
+ std::cout.fill('0');
+ std::cout.width(4);
+ std::cout << pos << " ";
+ std::cout << str << std::endl;
+ }
}
}
#endif
diff --git a/src/logger.h b/src/logger.h
index 8eafc70af..ba1aa3f29 100644
--- a/src/logger.h
+++ b/src/logger.h
@@ -39,9 +39,9 @@
#endif
#ifdef ENABLEDEBUGLOG
-#define DEBUGLOG2(msg, comment) \
+#define DEBUGLOG2(msg, pos, comment) \
if (logger) \
- logger->dlog2(msg, comment)
+ logger->dlog2(msg, pos, comment)
#else
#define DEBUGLOG2(msg, comment) {}
#endif
@@ -119,7 +119,9 @@ class Logger final
*/
void dlog(const std::string &str);
- void dlog2(const std::string &str, const char* const comment);
+ void dlog2(const std::string &str,
+ const int pos,
+ const char* const comment);
#endif
void setDebugLog(const bool n)
diff --git a/src/net/eathena/messagein.cpp b/src/net/eathena/messagein.cpp
index e3918dd3a..60d89980d 100644
--- a/src/net/eathena/messagein.cpp
+++ b/src/net/eathena/messagein.cpp
@@ -59,9 +59,10 @@ int16_t MessageIn::readInt16(const char *const str)
memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t));
#endif
}
+ DEBUGLOG2("readInt16: " + toStringPrint(static_cast<int>(value)),
+ mPos, str);
mPos += 2;
PacketCounters::incInBytes(2);
- DEBUGLOG2("readInt16: " + toStringPrint(static_cast<int>(value)), str);
return value;
}
@@ -78,9 +79,9 @@ int32_t MessageIn::readInt32(const char *const str)
memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int32_t));
#endif
}
+ DEBUGLOG2("readInt32: " + toStringPrint(value), mPos, str);
mPos += 4;
PacketCounters::incInBytes(4);
- DEBUGLOG2("readInt32: " + toStringPrint(value), str);
return value;
}
diff --git a/src/net/eathena/messageout.cpp b/src/net/eathena/messageout.cpp
index 7c5d328cb..1b0dae6f1 100644
--- a/src/net/eathena/messageout.cpp
+++ b/src/net/eathena/messageout.cpp
@@ -57,7 +57,6 @@ void MessageOut::expand(const size_t bytes)
void MessageOut::writeInt16(const int16_t value, const char *const str)
{
- DEBUGLOG2("writeInt16: " + toStringPrint(static_cast<int>(value)), str);
expand(2);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap = SDL_Swap16(value);
@@ -65,13 +64,15 @@ void MessageOut::writeInt16(const int16_t value, const char *const str)
#else
memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int16_t));
#endif
+ DEBUGLOG2("writeInt16: " + toStringPrint(static_cast<int>(value)),
+ mPos, str);
mPos += 2;
PacketCounters::incOutBytes(2);
}
void MessageOut::writeInt32(const int32_t value, const char *const str)
{
- DEBUGLOG2("writeInt32: " + toStringPrint(value), str);
+ DEBUGLOG2("writeInt32: " + toStringPrint(value), mPos, str);
expand(4);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int32_t swap = SDL_Swap32(value);
@@ -95,7 +96,7 @@ void MessageOut::writeCoordinates(const uint16_t x,
DEBUGLOG2(strprintf("writeCoordinates: %u,%u %u",
static_cast<unsigned>(x),
static_cast<unsigned>(y),
- static_cast<unsigned>(direction)), str);
+ static_cast<unsigned>(direction)), mPos, str);
unsigned char *const data = reinterpret_cast<unsigned char*>(mData)
+ static_cast<size_t>(mPos);
mNetwork->mOutSize += 3;
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index b131e85e0..92447cde2 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -53,9 +53,10 @@ unsigned char MessageIn::readUInt8(const char *const str)
if (mPos < mLength)
value = static_cast<unsigned char>(mData[mPos]);
+ DEBUGLOG2("readUInt8: " + toStringPrint(static_cast<int>(value)),
+ mPos, str);
mPos += 1;
PacketCounters::incInBytes(1);
- DEBUGLOG2("readUInt8: " + toStringPrint(static_cast<int>(value)), str);
return value;
}
@@ -65,9 +66,10 @@ signed char MessageIn::readInt8(const char *const str)
if (mPos < mLength)
value = static_cast<signed char>(mData[mPos]);
+ DEBUGLOG2("readInt8: " + toStringPrint(static_cast<int>(value)),
+ mPos, str);
mPos += 1;
PacketCounters::incInBytes(1);
- DEBUGLOG2("readInt8: " + toStringPrint(static_cast<int>(value)), str);
return value;
}
@@ -120,7 +122,7 @@ void MessageIn::readCoordinates(uint16_t &restrict x,
DEBUGLOG2(std::string("readCoordinates: ").append(toString(
static_cast<int>(x))).append(",").append(toString(
static_cast<int>(y))).append(",").append(toString(
- static_cast<int>(serverDir))), str);
+ static_cast<int>(serverDir))), mPos, str);
}
else
{
@@ -157,7 +159,7 @@ void MessageIn::readCoordinatePair(uint16_t &restrict srcX,
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))), str);
+ static_cast<int>(dstY))), mPos, str);
}
else
{
@@ -173,9 +175,9 @@ void MessageIn::readCoordinatePair(uint16_t &restrict srcX,
void MessageIn::skip(const unsigned int length, const char *const str)
{
+ DEBUGLOG2("skip: " + toString(static_cast<int>(length)), mPos, str);
mPos += length;
PacketCounters::incInBytes(length);
- DEBUGLOG2("skip: " + toString(static_cast<int>(length)), str);
}
std::string MessageIn::readString(int length, const char *const dstr)
@@ -187,8 +189,8 @@ std::string MessageIn::readString(int length, const char *const dstr)
// Make sure the string isn't erroneous
if (length < 0 || mPos + length > mLength)
{
+ DEBUGLOG2("readString error", mPos, dstr);
mPos = mLength + 1;
- DEBUGLOG2("readString error", dstr);
return "";
}
@@ -199,9 +201,9 @@ std::string MessageIn::readString(int length, const char *const dstr)
const std::string str(stringBeg, stringEnd
? stringEnd - stringBeg : static_cast<size_t>(length));
+ DEBUGLOG2("readString: " + str, mPos, dstr);
mPos += length;
PacketCounters::incInBytes(length);
- DEBUGLOG2("readString: " + str, dstr);
return str;
}
@@ -225,9 +227,7 @@ std::string MessageIn::readRawString(int length, const char *const dstr)
std::string str(stringBeg, stringEnd
? stringEnd - stringBeg : static_cast<size_t>(length));
- mPos += length;
- PacketCounters::incInBytes(length);
- DEBUGLOG2("readString: " + str, dstr);
+ DEBUGLOG2("readString: " + str, mPos, dstr);
if (stringEnd)
{
@@ -240,10 +240,12 @@ std::string MessageIn::readRawString(int length, const char *const dstr)
stringEnd2 ? stringEnd2 - stringBeg2 : len2);
if (hiddenPart.length() > 0)
{
- DEBUGLOG2("readString2: " + hiddenPart, dstr);
+ DEBUGLOG2("readString2: " + hiddenPart, mPos, dstr);
return str.append("|").append(hiddenPart);
}
}
+ mPos += length;
+ PacketCounters::incInBytes(length);
return str;
}
@@ -257,8 +259,8 @@ unsigned char *MessageIn::readBytes(int length, const char *const dstr)
// Make sure the string isn't erroneous
if (length < 0 || mPos + length > mLength)
{
+ DEBUGLOG2("readBytesString error", mPos, dstr);
mPos = mLength + 1;
- DEBUGLOG2("readBytesString error", dstr);
return nullptr;
}
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp
index ff778d89a..0026538b5 100644
--- a/src/net/messageout.cpp
+++ b/src/net/messageout.cpp
@@ -47,9 +47,10 @@ MessageOut::MessageOut(const int16_t id A_UNUSED) :
void MessageOut::writeInt8(const int8_t value, const char *const str)
{
- DEBUGLOG2("writeInt8: " + toStringPrint(static_cast<int>(value)), str);
expand(1);
mData[mPos] = value;
+ DEBUGLOG2("writeInt8: " + toStringPrint(static_cast<int>(value)),
+ mPos, str);
mPos += 1;
PacketCounters::incOutBytes(1);
}
@@ -83,8 +84,8 @@ void MessageOut::writeString(const std::string &string,
length - stringLength);
}
+ DEBUGLOG2("writeString: " + string, mPos, str);
mPos += length;
- DEBUGLOG2("writeString: " + string, str);
PacketCounters::incOutBytes(length);
}
@@ -117,8 +118,8 @@ void MessageOut::writeStringNoLog(const std::string &string,
length - stringLength);
}
+ DEBUGLOG2("writeString: ***", mPos, str);
mPos += length;
- DEBUGLOG2("writeString: ***", str);
PacketCounters::incOutBytes(length);
}
diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp
index 18686f347..d467048d7 100644
--- a/src/net/tmwa/messagein.cpp
+++ b/src/net/tmwa/messagein.cpp
@@ -59,9 +59,10 @@ int16_t MessageIn::readInt16(const char *const str)
memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t));
#endif
}
+ DEBUGLOG2("readInt16: " + toStringPrint(static_cast<int>(value)),
+ mPos, str);
mPos += 2;
PacketCounters::incInBytes(2);
- DEBUGLOG2("readInt16: " + toStringPrint(static_cast<int>(value)), str);
return value;
}
@@ -78,9 +79,9 @@ int32_t MessageIn::readInt32(const char *const str)
memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int32_t));
#endif
}
+ DEBUGLOG2("readInt32: " + toStringPrint(value), mPos, str);
mPos += 4;
PacketCounters::incInBytes(4);
- DEBUGLOG2("readInt32: " + toStringPrint(value), str);
return value;
}
diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp
index a740df563..a66c1c2b1 100644
--- a/src/net/tmwa/messageout.cpp
+++ b/src/net/tmwa/messageout.cpp
@@ -57,7 +57,8 @@ void MessageOut::expand(const size_t bytes)
void MessageOut::writeInt16(const int16_t value, const char *const str)
{
- DEBUGLOG2("writeInt16: " + toStringPrint(static_cast<int>(value)), str);
+ DEBUGLOG2("writeInt16: " + toStringPrint(static_cast<int>(value)),
+ mPos, str);
expand(2);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int16_t swap = SDL_Swap16(value);
@@ -71,7 +72,7 @@ void MessageOut::writeInt16(const int16_t value, const char *const str)
void MessageOut::writeInt32(const int32_t value, const char *const str)
{
- DEBUGLOG2("writeInt32: " + toStringPrint(value), str);
+ DEBUGLOG2("writeInt32: " + toStringPrint(value), mPos, str);
expand(4);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int32_t swap = SDL_Swap32(value);
@@ -94,7 +95,7 @@ void MessageOut::writeCoordinates(const uint16_t x,
{
DEBUGLOG2(strprintf("writeCoordinates: %u,%u %u",
static_cast<unsigned>(x), static_cast<unsigned>(y),
- static_cast<unsigned>(direction)), str);
+ static_cast<unsigned>(direction)), mPos, str);
unsigned char *const data = reinterpret_cast<unsigned char*>(mData)
+ static_cast<size_t>(mPos);
mNetwork->mOutSize += 3;