From a4997d06477335e9e8162df8c09057d69cbeecc5 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 15 Jun 2023 18:09:59 +0300 Subject: [PATCH] engine: server: port old engine's fullupdate ratelimit, but simplify it --- engine/server/server.h | 1 + engine/server/sv_client.c | 13 ++++++++++++- engine/server/sv_main.c | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/engine/server/server.h b/engine/server/server.h index 99f77ef1..8170491a 100644 --- a/engine/server/server.h +++ b/engine/server/server.h @@ -471,6 +471,7 @@ extern convar_t sv_userinfo_enable_penalty; extern convar_t sv_userinfo_penalty_time; extern convar_t sv_userinfo_penalty_multiplier; extern convar_t sv_userinfo_penalty_attempts; +extern convar_t sv_fullupdate_penalty_time; //=========================================================== // diff --git a/engine/server/sv_client.c b/engine/server/sv_client.c index 88e2e175..e8237635 100644 --- a/engine/server/sv_client.c +++ b/engine/server/sv_client.c @@ -3090,10 +3090,18 @@ void SV_ExecuteClientCommand( sv_client_t *cl, const char *s ) if( !u->name && sv.state == ss_active ) { + qboolean fullupdate = !Q_strcmp( Cmd_Argv( 0 ), "fullupdate" ); + + if( fullupdate ) + { + if( sv_fullupdate_penalty_time.value && host.realtime < cl->fullupdate_next_calltime ) + return; + } + // custom client commands svgame.dllFuncs.pfnClientCommand( cl->edict ); - if( !Q_strcmp( Cmd_Argv( 0 ), "fullupdate" )) + if( fullupdate ) { // resend the ambient sounds for demo recording SV_RestartAmbientSounds(); @@ -3103,6 +3111,9 @@ void SV_ExecuteClientCommand( sv_client_t *cl, const char *s ) SV_RestartStaticEnts(); // resend the viewentity SV_UpdateClientView( cl ); + + if( sv_fullupdate_penalty_time.value ) + cl->fullupdate_next_calltime = host.realtime + sv_fullupdate_penalty_time.value; } } } diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index 74f288dc..7f6f176b 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -144,7 +144,7 @@ CVAR_DEFINE_AUTO( sv_userinfo_enable_penalty, "1", FCVAR_ARCHIVE, "enable penalt CVAR_DEFINE_AUTO( sv_userinfo_penalty_time, "0.3", FCVAR_ARCHIVE, "initial penalty time" ); CVAR_DEFINE_AUTO( sv_userinfo_penalty_multiplier, "2", FCVAR_ARCHIVE, "penalty time multiplier" ); CVAR_DEFINE_AUTO( sv_userinfo_penalty_attempts, "4", FCVAR_ARCHIVE, "if max attempts count was exceeded, penalty time will be increased" ); - +CVAR_DEFINE_AUTO( sv_fullupdate_penalty_time, "1", FCVAR_ARCHIVE, "allow fullupdate command only once in this timewindow (set 0 to disable)" ); //============================================================================ /* @@ -938,6 +938,7 @@ void SV_Init( void ) Cvar_RegisterVariable( &sv_userinfo_penalty_time ); Cvar_RegisterVariable( &sv_userinfo_penalty_multiplier ); Cvar_RegisterVariable( &sv_userinfo_penalty_attempts ); + Cvar_RegisterVariable( &sv_fullupdate_penalty_time ); // when we in developer-mode automatically turn cheats on if( host_developer.value ) Cvar_SetValue( "sv_cheats", 1.0f );