Modified packet logging to include server name and save both in and out to the same file

This commit is contained in:
purpleyouko committed 2025-12-26 14:28:59 -06:00
1 parent 4a149c8621
commit a320bbe470
6 files changed
+42 -3

No files matched your search

+42 -3
View File
@@ -91,10 +91,29 @@ bool CClientSocket::ReceiveData( )
CPacket* pak = (CPacket*)&Buffer;
//comment to prevent packet logging
/// FK: Prepare Logging.
string ThisServer;
switch (LOG_THISSERVER)
{
case LOG_LOGIN_SERVER:
ThisServer = "LOGIN Server";
break;
case LOG_CHARACTER_SERVER:
ThisServer = "CHAR Server";
break;
case LOG_WORLD_SERVER:
ThisServer = "WORLD Server";
break;
case LOG_SAME_FILE:
ThisServer = "DEFAULT";
break;
}
FILE *fh = NULL;
fopen_s (&fh, "log/inoutpackets.log", "a+");
if ( fh != NULL ) {
fprintf( fh, "(SID:%08u) IN %04x: ", sock, pak->Command );
fprintf( fh, "%s: (SID:%08u) IN %04x: ", ThisServer.c_str(), sock, pak->Command );
for ( int i=0; i<pak->Size-6; ++i ) fprintf( fh, "%02x ", (unsigned char)pak->Buffer[i] );
fprintf( fh, "\n" );
fclose( fh );
@@ -120,12 +139,32 @@ void CClientSocket::SendPacket( CPacket *P )
{
//first log it so we don't have to worry about encryption. Comment to prevent logging
bool LogFile = true;
/// FK: Prepare Logging.
string ThisServer;
switch (LOG_THISSERVER)
{
case LOG_LOGIN_SERVER:
ThisServer = "LOGIN Server";
break;
case LOG_CHARACTER_SERVER:
ThisServer = "CHAR Server";
break;
case LOG_WORLD_SERVER:
ThisServer = "WORLD Server";
break;
case LOG_SAME_FILE:
ThisServer = "DEFAULT";
break;
}
FILE *fh = NULL;
fopen_s (&fh, "log/receivedpackets.log", "a+");
//fopen_s (&fh, "log/receivedpackets.log", "a+");
fopen_s (&fh, "log/inoutpackets.log", "a+"); //send in and out to same log
if ( fh != NULL && LogFile)
{
fprintf( fh, "(SID:%08u) OUT %04x: ", sock, P->Command );
fprintf( fh, "%s: (SID:%08u) OUT %04x: ", ThisServer.c_str(), sock, P->Command );
for ( int i=0; i<P->Size-6; ++i ) fprintf( fh, "%02x ", (unsigned char)P->Buffer[i] );
fprintf( fh, "\n" );
fclose( fh );