engine: server: add cvar to disable bandwidth test on server side

This commit is contained in:
Alibek Omarov 2024-06-01 05:27:35 +03:00
parent 3e1209d3a4
commit a9c0a4be23
4 changed files with 33 additions and 4 deletions

View File

@ -475,6 +475,7 @@ extern convar_t sv_fullupdate_penalty_time;
extern convar_t sv_log_outofband;
extern convar_t sv_allow_autoaim;
extern convar_t sv_aim;
extern convar_t sv_allow_testpacket;
//===========================================================
//
@ -503,6 +504,7 @@ void SV_ActivateServer( int runPhysics );
qboolean SV_SpawnServer( const char *server, const char *startspot, qboolean background );
model_t *SV_ModelHandle( int modelindex );
void SV_DeactivateServer( void );
void SV_FreeTestPacket( void );
//
// sv_phys.c

View File

@ -852,7 +852,7 @@ static void SV_TestBandWidth( netadr_t from )
}
// quickly reject invalid packets
if( !svs.testpacket_buf ||
if( !sv_allow_testpacket.value || !svs.testpacket_buf ||
( packetsize <= FRAGMENT_MIN_SIZE ) ||
( packetsize > FRAGMENT_MAX_SIZE ))
{
@ -2035,7 +2035,7 @@ static qboolean SV_Kill_f( sv_client_t *cl )
{
if( !SV_IsValidEdict( cl->edict ))
return true;
if( cl->state != cs_spawned )
{
SV_ClientPrintf( cl, "Can't suicide - not connected!\n" );
@ -2424,7 +2424,7 @@ static qboolean SV_EntList_f( sv_client_t *cl )
// filter by string
if( Cmd_Argc() > 1 )
{
{
if( !Q_stricmpext( Cmd_Argv( 1 ), STRING( ent->v.classname ) ) && !Q_stricmpext( Cmd_Argv( 1 ), STRING( ent->v.targetname ) ) )
continue;
}

View File

@ -906,6 +906,21 @@ qboolean CRC32_MapFile( dword *crcvalue, const char *filename, qboolean multipla
return 1;
}
void SV_FreeTestPacket( void )
{
if( svs.testpacket_buf )
{
Mem_Free( svs.testpacket_buf );
svs.testpacket_buf = NULL;
}
if( svs.testpacket_crcs )
{
Mem_Free( svs.testpacket_crcs );
svs.testpacket_crcs = NULL;
}
}
/*
================
SV_GenerateTestPacket
@ -917,7 +932,13 @@ static void SV_GenerateTestPacket( void )
uint32_t crc;
file_t *file;
byte *filepos;
int i, filesize;
int i;
if( !sv_allow_testpacket.value )
{
SV_FreeTestPacket();
return;
}
// testpacket already generated once, exit
// testpacket and lookup table takes ~300k of memory

View File

@ -150,6 +150,8 @@ CVAR_DEFINE_AUTO( sv_userinfo_penalty_attempts, "4", FCVAR_ARCHIVE, "if max atte
CVAR_DEFINE_AUTO( sv_fullupdate_penalty_time, "1", FCVAR_ARCHIVE, "allow fullupdate command only once in this timewindow (set 0 to disable)" );
CVAR_DEFINE_AUTO( sv_log_outofband, "0", FCVAR_ARCHIVE, "log out of band messages, can be useful for server admins and for engine debugging" );
CVAR_DEFINE_AUTO( sv_allow_testpacket, "1", FCVAR_ARCHIVE, "allow generating and sending a big blob of data to test maximum packet size" );
//============================================================================
/*
================
@ -973,6 +975,7 @@ void SV_Init( void )
Cvar_RegisterVariable( &sv_userinfo_penalty_attempts );
Cvar_RegisterVariable( &sv_fullupdate_penalty_time );
Cvar_RegisterVariable( &sv_log_outofband );
Cvar_RegisterVariable( &sv_allow_testpacket );
// when we in developer-mode automatically turn cheats on
if( host_developer.value ) Cvar_SetValue( "sv_cheats", 1.0f );
@ -1115,6 +1118,9 @@ void SV_Shutdown( const char *finalmsg )
SV_FreeClients();
svs.maxclients = 0;
// release test packet blob
SV_FreeTestPacket();
// release all models
Mod_FreeAll();