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 38cb2f7 commit b840b43
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 57 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
78 changes: 21 additions & 57 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 Expand Up @@ -1042,63 +1063,6 @@ void SV_RunCmd(usercmd_t *ucmd, int random_seed)

if (!host_client->fakeclient)
SV_RestoreMove(host_client);

// If we have to restore the view angle then do so right now

// TODO: Implement: in `player.h` & `player.cpp`
/*
QAngle m_qangLockViewangles;
int m_iLockViewanglesTickNumber;
int GetLockViewanglesTickNumber() const { return m_iLockViewanglesTickNumber; }
QAngle GetLockViewanglesData() const { return m_qangLockViewangles; }
////////////
void CCSPlayer::NoteWeaponFired()
{
Assert( m_pCurrentCommand );
if( m_pCurrentCommand )
{
m_iLastWeaponFireUsercmd = m_pCurrentCommand->command_number;
}
// Remember the tickcount when the weapon was fired and lock viewangles here!
if ( m_iLockViewanglesTickNumber != gpGlobals->tickcount )
{
m_iLockViewanglesTickNumber = gpGlobals->tickcount;
m_qangLockViewangles = pl.v_angle;
}
}
*/

/**
Implement in CCSPlayer::FireBullet:
// Let the player remember the usercmd he fired a weapon on. Assists in making decisions about lag compensation.
if ( pPlayer )
pPlayer->NoteWeaponFired();
if ( bBulletHitPlayer && !bShotHitTeammate )
{ // Guarantee that the bullet that hit an enemy trumps the player viewangles
// that are locked in for the duration of the server simulation ticks
m_iLockViewanglesTickNumber = gpGlobals->tickcount;
m_qangLockViewangles = pl.v_angle;
}
*/

/*
Implement in SV_RunCmd():
// player->IsBot() == sv_player->fakeclient
// tickcount == m_System->GetTick()
if ( !player->IsBot() &&
( gpGlobals->tickcount - player->GetLockViewanglesTickNumber() < sv_maxusrcmdprocessticks_holdaim.value ) )
{
player->pl.v_angle = player->GetLockViewanglesData();
}
*/
}

int SV_ValidateClientCommand(char *pszCommand)
Expand Down

0 comments on commit b840b43

Please sign in to comment.