1
0

Comm logging is available in both Debug and Release modes.

This commit is contained in:
madmaxoft 2014-01-25 15:28:16 +01:00
parent 5aa3fc4c56
commit ff066453b8
3 changed files with 16 additions and 16 deletions

View File

@ -53,10 +53,8 @@ Implements the 1.7.x protocol classes:
#ifdef _DEBUG
// fwd: main.cpp:
extern bool g_ShouldLogComm;
#endif
@ -76,14 +74,12 @@ cProtocol172::cProtocol172(cClientHandle * a_Client, const AString & a_ServerAdd
m_IsEncrypted(false)
{
// Create the comm log file, if so requested:
#ifdef _DEBUG
if (g_ShouldLogComm)
{
cFile::CreateFolder("CommLogs");
AString FileName = Printf("CommLogs/%x__%s.log", (unsigned)time(NULL), a_Client->GetIPString().c_str());
m_CommLogFile.Open(FileName, cFile::fmWrite);
}
#endif // _DEBUG
}
@ -1087,7 +1083,6 @@ void cProtocol172::SendWindowProperty(const cWindow & a_Window, short a_Property
void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
{
// Write the incoming data into the comm log file:
#ifdef _DEBUG
if (g_ShouldLogComm)
{
if (m_ReceivedData.GetReadableSpace() > 0)
@ -1109,7 +1104,6 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
a_Size, a_Size, Hex.c_str()
);
}
#endif
if (!m_ReceivedData.Write(a_Data, a_Size))
{
@ -1147,7 +1141,6 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
}
// Log the packet info into the comm log file:
#ifdef _DEBUG
if (g_ShouldLogComm)
{
AString PacketData;
@ -1162,7 +1155,6 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
PacketType, PacketType, PacketLen, PacketLen, m_State, PacketDataHex.c_str()
);
}
#endif // _DEBUG
if (!HandlePacket(bb, PacketType))
{
@ -1180,6 +1172,12 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
LOGD("Packet contents:\n%s", Out.c_str());
#endif // _DEBUG
// Put a message in the comm log:
if (g_ShouldLogComm)
{
m_CommLogFile.Printf("^^^^^^ Unhandled packet ^^^^^^\n\n\n");
}
return;
}
@ -1189,6 +1187,16 @@ void cProtocol172::AddReceivedData(const char * a_Data, int a_Size)
LOGWARNING("Protocol 1.7: Wrong number of bytes read for packet 0x%x, state %d. Read %u bytes, packet contained %u bytes",
PacketType, m_State, bb.GetUsedSpace() - bb.GetReadableSpace(), PacketLen
);
// Put a message in the comm log:
if (g_ShouldLogComm)
{
m_CommLogFile.Printf("^^^^^^ Wrong number of bytes read for this packet (exp %d left, got %d left) ^^^^^^\n\n\n",
1, bb.GetReadableSpace()
);
m_CommLogFile.Flush();
}
ASSERT(!"Read wrong number of bytes!");
m_Client->PacketError(PacketType);
}
@ -1873,7 +1881,6 @@ cProtocol172::cPacketizer::~cPacketizer()
m_Out.CommitRead();
// Log the comm into logfile:
#ifdef _DEBUG
if (g_ShouldLogComm)
{
AString Hex;
@ -1883,7 +1890,6 @@ cProtocol172::cPacketizer::~cPacketizer()
DataToSend[0], DataToSend[0], PacketLen, PacketLen, m_Protocol.m_State, Hex.c_str()
);
}
#endif // _DEBUG
}

View File

@ -223,10 +223,8 @@ protected:
CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption m_Decryptor;
CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption m_Encryptor;
#ifdef _DEBUG
/** The logfile where the comm is logged, when g_ShouldLogComm is true */
cFile m_CommLogFile;
#endif
/// Adds the received (unencrypted) data to m_ReceivedData, parses complete packets

View File

@ -19,10 +19,8 @@ bool g_SERVER_TERMINATED = false; // Set to true when the server terminates, so
#ifdef _DEBUG
/** If set to true, the protocols will log each player's communication to a separate logfile */
bool g_ShouldLogComm;
#endif
@ -232,7 +230,6 @@ int main( int argc, char **argv )
// *((int *)0) = 0;
// Check if comm logging is to be enabled:
#ifdef _DEBUG
for (int i = 0; i < argc; i++)
{
if (
@ -243,7 +240,6 @@ int main( int argc, char **argv )
g_ShouldLogComm = true;
}
}
#endif // _DEBUG
#if !defined(ANDROID_NDK)
try