engine: common: add cvars net_send_debug and net_recv_debug to print server/client messages to console

This commit is contained in:
Alibek Omarov 2024-10-15 06:11:57 +03:00
parent 1bd59096fd
commit ece204c30f
3 changed files with 39 additions and 31 deletions

View file

@ -17,8 +17,6 @@ GNU General Public License for more details.
#include "protocol.h" #include "protocol.h"
#include "net_buffer.h" #include "net_buffer.h"
#include "xash3d_mathlib.h" #include "xash3d_mathlib.h"
//#define DEBUG_NET_MESSAGES_SEND
//#define DEBUG_NET_MESSAGES_READ
// precalculated bit masks for WriteUBitLong. // precalculated bit masks for WriteUBitLong.
// Using these tables instead of doing the calculations // Using these tables instead of doing the calculations
@ -323,28 +321,30 @@ void MSG_WriteVec3Angles( sizebuf_t *sb, const float *fa )
void MSG_WriteCmdExt( sizebuf_t *sb, int cmd, netsrc_t type, const char *name ) void MSG_WriteCmdExt( sizebuf_t *sb, int cmd, netsrc_t type, const char *name )
{ {
#ifdef DEBUG_NET_MESSAGES_SEND if( unlikely( net_send_debug.value ))
if( name != NULL )
{ {
// get custom name if( name != NULL )
Con_Printf( "^1sv^7 write: %s\n", name );
}
else if( type == NS_SERVER )
{
if( cmd >= 0 && cmd <= svc_lastmsg )
{ {
// get engine message name // get custom name
Con_Printf( "^1sv^7 write: %s\n", svc_strings[cmd] ); Con_Printf( "^1sv^7 (%d) write: %s\n", sb->iCurBit, name );
}
else if( type == NS_SERVER )
{
if( cmd >= 0 && cmd <= svc_lastmsg )
{
// get engine message name
Con_Printf( "^1sv^7 (%d) write: %s\n", sb->iCurBit, svc_strings[cmd] );
}
}
else if( type == NS_CLIENT )
{
if( cmd >= 0 && cmd <= clc_lastmsg )
{
Con_Printf( "^1cl^7 (%d) write: %s\n", sb->iCurBit, clc_strings[cmd] );
}
} }
} }
else if( type == NS_CLIENT )
{
if( cmd >= 0 && cmd <= clc_lastmsg )
{
Con_Printf( "^1cl^7 write: %s\n", clc_strings[cmd] );
}
}
#endif
MSG_WriteUBitLong( sb, cmd, sizeof( uint8_t ) << 3 ); MSG_WriteUBitLong( sb, cmd, sizeof( uint8_t ) << 3 );
} }
@ -570,16 +570,18 @@ int MSG_ReadCmd( sizebuf_t *sb, netsrc_t type )
{ {
int cmd = MSG_ReadUBitLong( sb, sizeof( uint8_t ) << 3 ); int cmd = MSG_ReadUBitLong( sb, sizeof( uint8_t ) << 3 );
#ifdef DEBUG_NET_MESSAGES_READ if( unlikely( net_recv_debug.value ))
if( type == NS_SERVER )
{ {
Con_Printf( "^1cl^7 read: %s\n", CL_MsgInfo( cmd )); if( type == NS_SERVER )
{
Con_Printf( "^1cl^7 read: %s\n", CL_MsgInfo( cmd ));
}
else if( cmd >= 0 && cmd <= clc_lastmsg )
{
Con_Printf( "^1sv^7 read: %s\n", clc_strings[cmd] );
}
} }
else if( cmd >= 0 && cmd <= clc_lastmsg )
{
Con_Printf( "^1sv^7 read: %s\n", clc_strings[cmd] );
}
#endif
return cmd; return cmd;
} }

View file

@ -87,10 +87,12 @@ such as during the connection stage while waiting for the client to load,
then a packet only needs to be delivered if there is something in the then a packet only needs to be delivered if there is something in the
unacknowledged reliable unacknowledged reliable
*/ */
CVAR_DEFINE_AUTO( net_showpackets, "0", 0, "show network packets" ); CVAR_DEFINE_AUTO( net_showpackets, "0", FCVAR_PRIVILEGED, "show network packets" );
static CVAR_DEFINE_AUTO( net_chokeloop, "0", 0, "apply bandwidth choke to loopback packets" ); static CVAR_DEFINE_AUTO( net_chokeloop, "0", 0, "apply bandwidth choke to loopback packets" );
static CVAR_DEFINE_AUTO( net_showdrop, "0", 0, "show packets that are dropped" ); static CVAR_DEFINE_AUTO( net_showdrop, "0", 0, "show packets that are dropped" );
static CVAR_DEFINE_AUTO( net_qport, "0", FCVAR_READ_ONLY, "current quake netport" ); static CVAR_DEFINE_AUTO( net_qport, "0", FCVAR_READ_ONLY, "current quake netport" );
CVAR_DEFINE_AUTO( net_send_debug, "0", FCVAR_PRIVILEGED, "enable debugging output for outgoing messages" );
CVAR_DEFINE_AUTO( net_recv_debug, "0", FCVAR_PRIVILEGED, "enable debugging output for incoming messages" );
int net_drop; int net_drop;
netadr_t net_from; netadr_t net_from;
@ -265,6 +267,8 @@ void Netchan_Init( void )
Cvar_RegisterVariable( &net_chokeloop ); Cvar_RegisterVariable( &net_chokeloop );
Cvar_RegisterVariable( &net_showdrop ); Cvar_RegisterVariable( &net_showdrop );
Cvar_RegisterVariable( &net_qport ); Cvar_RegisterVariable( &net_qport );
Cvar_RegisterVariable( &net_send_debug );
Cvar_RegisterVariable( &net_recv_debug );
Cvar_FullSet( net_qport.name, buf, net_qport.flags ); Cvar_FullSet( net_qport.name, buf, net_qport.flags );
net_mempool = Mem_AllocPool( "Network Pool" ); net_mempool = Mem_AllocPool( "Network Pool" );

View file

@ -50,8 +50,10 @@ typedef enum
#include "netadr.h" #include "netadr.h"
extern convar_t net_showpackets; extern convar_t net_showpackets;
extern convar_t net_clockwindow; extern convar_t net_clockwindow;
extern convar_t net_send_debug;
extern convar_t net_recv_debug;
void NET_Init( void ); void NET_Init( void );
void NET_Shutdown( void ); void NET_Shutdown( void );