net: Add network log file.
I've had some reports from multiplayer users about stalls where the game just freezes up; having decent logging of network events seems like an essential step for diagnosing such bugs. It seems like a prudent feature to just have anyway; the network engine is already littered with commented-out printf statements used in the past for similar purposes.
This commit is contained in:
parent
af80499016
commit
f7f8ce6c63
4 changed files with 82 additions and 1 deletions
|
|
@ -1136,6 +1136,7 @@ void NET_CL_Init(void)
|
|||
|
||||
void NET_Init(void)
|
||||
{
|
||||
NET_OpenLog();
|
||||
NET_CL_Init();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,12 +16,14 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "doomtype.h"
|
||||
#include "d_mode.h"
|
||||
#include "i_system.h"
|
||||
#include "i_timer.h"
|
||||
#include "m_argv.h"
|
||||
|
||||
#include "net_common.h"
|
||||
#include "net_io.h"
|
||||
|
|
@ -46,6 +48,8 @@ struct net_reliable_packet_s
|
|||
net_reliable_packet_t *next;
|
||||
};
|
||||
|
||||
static FILE *net_debug = NULL;
|
||||
|
||||
// Why did the server reject us?
|
||||
char *net_client_reject_reason = NULL;
|
||||
|
||||
|
|
@ -478,3 +482,74 @@ boolean NET_ValidGameSettings(GameMode_t mode, GameMission_t mission,
|
|||
return true;
|
||||
}
|
||||
|
||||
static void CloseLog(void)
|
||||
{
|
||||
if (net_debug != NULL)
|
||||
{
|
||||
fclose(net_debug);
|
||||
net_debug = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void NET_OpenLog(void)
|
||||
{
|
||||
int p;
|
||||
|
||||
p = M_CheckParmWithArgs("-netlog", 1);
|
||||
if (p > 0)
|
||||
{
|
||||
net_debug = fopen(myargv[p + 1], "w");
|
||||
if (net_debug == NULL)
|
||||
{
|
||||
I_Error("Failed to open %s to write debug log.", myargv[p + 1]);
|
||||
}
|
||||
I_AtExit(CloseLog, true);
|
||||
}
|
||||
}
|
||||
|
||||
void NET_Log(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
if (net_debug == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(net_debug, "%8d: ", I_GetTimeMS());
|
||||
va_start(args, fmt);
|
||||
vfprintf(net_debug, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(net_debug, "\n");
|
||||
}
|
||||
|
||||
void NET_LogPacket(net_packet_t *packet)
|
||||
{
|
||||
int i, bytes;
|
||||
|
||||
if (net_debug == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bytes = packet->len - packet->pos;
|
||||
if (bytes == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
fprintf(net_debug, "\t%02x", packet->data[packet->pos]);
|
||||
for (i = 1; i < bytes; ++i)
|
||||
{
|
||||
if ((i % 16) == 0)
|
||||
{
|
||||
fprintf(net_debug, "\n\t");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(net_debug, " ");
|
||||
}
|
||||
fprintf(net_debug, "%02x", packet->data[packet->pos + i]);
|
||||
}
|
||||
fprintf(net_debug, "\n");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -98,5 +98,9 @@ unsigned int NET_ExpandTicNum(unsigned int relative, unsigned int b);
|
|||
boolean NET_ValidGameSettings(GameMode_t mode, GameMission_t mission,
|
||||
net_gamesettings_t *settings);
|
||||
|
||||
void NET_OpenLog(void);
|
||||
void NET_Log(const char *fmt, ...);
|
||||
void NET_LogPacket(net_packet_t *packet);
|
||||
|
||||
#endif /* #ifndef NET_COMMON_H */
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include "m_argv.h"
|
||||
|
||||
#include "net_defs.h"
|
||||
#include "net_common.h"
|
||||
#include "net_sdl.h"
|
||||
#include "net_server.h"
|
||||
|
||||
|
|
@ -65,6 +65,7 @@ void NET_DedicatedServer(void)
|
|||
{
|
||||
CheckForClientOptions();
|
||||
|
||||
NET_OpenLog();
|
||||
NET_SV_Init();
|
||||
NET_SV_AddModule(&net_sdl_module);
|
||||
NET_SV_RegisterWithMaster();
|
||||
|
|
|
|||
Loading…
Reference in a new issue