Skip to content

Commit

Permalink
add sv_maxusrcmdprocessticks_warning
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyShorokhov committed Jun 29, 2021
1 parent aaffe43 commit 45a05e3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
25 changes: 25 additions & 0 deletions rehlds/dlls/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,31 @@ class CBasePlayer : public CBaseMonster

float m_flNextChatTime;

float GetRemainingMovementTimeForUserCmdProcessing() const { return m_flMovementTimeForUserCmdProcessingRemaining; }
float ConsumeMovementTimeForUserCmdProcessing( float flTimeNeeded )
{
if ( m_flMovementTimeForUserCmdProcessingRemaining <= 0.0f )
return 0.0f;

const float DIST_EPSILON = 0.03125f;
else if ( flTimeNeeded > m_flMovementTimeForUserCmdProcessingRemaining + FLT_EPSILON )
{
float flResult = m_flMovementTimeForUserCmdProcessingRemaining;
m_flMovementTimeForUserCmdProcessingRemaining = 0.0f;
return flResult;
}
else
{
m_flMovementTimeForUserCmdProcessingRemaining -= flTimeNeeded;
if ( m_flMovementTimeForUserCmdProcessingRemaining < 0.0f )
m_flMovementTimeForUserCmdProcessingRemaining = 0.0f;
return flTimeNeeded;
}
}

private:
// How much of a movement time buffer can we process from this user?
float m_flMovementTimeForUserCmdProcessingRemaining;
};

#define AUTOAIM_2DEGREES 0.0348994967025
Expand Down
1 change: 1 addition & 0 deletions rehlds/engine/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ extern cvar_t sv_rehlds_attachedentities_playeranimationspeed_fix;
extern cvar_t sv_rehlds_local_gametime;
extern cvar_t sv_rehlds_send_mapcycle;
extern cvar_t sv_usercmd_custom_random_seed;
extern cvar_t sv_maxusrcmdprocessticks_warning;
#endif
extern int sv_playermodel;

Expand Down
2 changes: 2 additions & 0 deletions rehlds/engine/sv_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ cvar_t sv_rehlds_send_mapcycle = { "sv_rehlds_send_mapcycle", "0", 0, 0.0f, null
cvar_t sv_rehlds_maxclients_from_single_ip = { "sv_rehlds_maxclients_from_single_ip", "5", 0, 5.0f, nullptr };
cvar_t sv_use_entity_file = { "sv_use_entity_file", "0", 0, 0.0f, nullptr };
cvar_t sv_usercmd_custom_random_seed = { "sv_usercmd_custom_random_seed", "0", 0, 0.0f, nullptr };
cvar_t sv_maxusrcmdprocessticks_warning = { "sv_maxusrcmdprocessticks_warning", "0", 0, 0.0f, nullptr };
#endif

delta_t *SV_LookupDelta(char *name)
Expand Down Expand Up @@ -8025,6 +8026,7 @@ void SV_Init(void)
Cvar_RegisterVariable(&sv_rollangle);
Cvar_RegisterVariable(&sv_use_entity_file);
Cvar_RegisterVariable(&sv_usercmd_custom_random_seed);
Cvar_RegisterVariable(&sv_maxusrcmdprocessticks_warning);
#endif

for (int i = 0; i < MAX_MODELS; i++)
Expand Down
21 changes: 21 additions & 0 deletions rehlds/engine/sv_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,27 @@ void SV_ForceFullClientsUpdate(void)

void SV_RunCmd(usercmd_t *ucmd, int random_seed)
{
const float playerFrameTime = (1.0f / sys_ticrate.value);
const float flTimeAllowedForProcessing = host_client->ConsumeMovementTimeForUserCmdProcessing( playerFrameTime );
bool isBot = host_client->fakeclient;
if ( !isBot && ( flTimeAllowedForProcessing < playerFrameTime ) )
{
// Make sure that the activity in command is erased because player cheated or dropped too many packets
double dblWarningFrequencyThrottle = sv_maxusrcmdprocessticks_warning.value;
if ( dblWarningFrequencyThrottle >= 0.0 )
{
static double s_dblLastWarningTime = 0.0;
double dblTimeNow = Sys_FloatTime();
if ( !s_dblLastWarningTime || ( dblTimeNow - s_dblLastWarningTime >= dblWarningFrequencyThrottle ) )
{
s_dblLastWarningTime = dblTimeNow;
Con_Printf( "sv_maxusrcmdprocessticks_warning at server tick %u: Ignored client %s usrcmd (%.6f < %.6f)!\n",
m_system->GetTick(), host_client->name, flTimeAllowedForProcessing, playerFrameTime );
}
}
return; // Don't process this command
}

usercmd_t cmd = *ucmd;
int i;
edict_t *ent;
Expand Down

0 comments on commit 45a05e3

Please sign in to comment.