Skip to content

Commit 2d4e425

Browse files
committed
...
1 parent 6dbab25 commit 2d4e425

File tree

4 files changed

+55
-28
lines changed

4 files changed

+55
-28
lines changed

rehlds/engine/server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ extern cvar_t sv_rehlds_attachedentities_playeranimationspeed_fix;
378378
extern cvar_t sv_rehlds_local_gametime;
379379
extern cvar_t sv_rehlds_send_mapcycle;
380380
extern cvar_t sv_usercmd_custom_random_seed;
381+
extern cvar_t sv_maxusrcmdprocessticks;
381382
extern cvar_t sv_maxusrcmdprocessticks_warning;
382383
#endif
383384
extern int sv_playermodel;

rehlds/engine/sv_main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ cvar_t sv_rehlds_send_mapcycle = { "sv_rehlds_send_mapcycle", "0", 0, 0.0f, null
210210
cvar_t sv_rehlds_maxclients_from_single_ip = { "sv_rehlds_maxclients_from_single_ip", "5", 0, 5.0f, nullptr };
211211
cvar_t sv_use_entity_file = { "sv_use_entity_file", "0", 0, 0.0f, nullptr };
212212
cvar_t sv_usercmd_custom_random_seed = { "sv_usercmd_custom_random_seed", "0", 0, 0.0f, nullptr };
213-
cvar_t sv_maxusrcmdprocessticks_warning = { "sv_maxusrcmdprocessticks_warning", "0", 0, 0.0f, nullptr };
213+
cvar_t sv_maxusrcmdprocessticks = { "sv_maxusrcmdprocessticks", "16", 0, 0.0f, nullptr };
214+
cvar_t sv_maxusrcmdprocessticks_warning = { "sv_maxusrcmdprocessticks_warning", "-1", 0, 0.0f, nullptr };
214215
#endif
215216

216217
delta_t *SV_LookupDelta(char *name)
@@ -8026,6 +8027,7 @@ void SV_Init(void)
80268027
Cvar_RegisterVariable(&sv_rollangle);
80278028
Cvar_RegisterVariable(&sv_use_entity_file);
80288029
Cvar_RegisterVariable(&sv_usercmd_custom_random_seed);
8030+
Cvar_RegisterVariable(&sv_maxusrcmdprocessticks);
80298031
Cvar_RegisterVariable(&sv_maxusrcmdprocessticks_warning);
80308032
#endif
80318033

rehlds/engine/sv_user.cpp

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -754,30 +754,6 @@ void SV_ForceFullClientsUpdate(void)
754754

755755
void SV_RunCmd(usercmd_t *ucmd, int random_seed)
756756
{
757-
#ifdef REHLDS_FIXES
758-
auto gameClient = g_GameClients[host_client - g_psvs.clients];
759-
float playerFrameTime = (1.0f / sys_ticrate.value);
760-
float flTimeAllowedForProcessing = gameClient->ConsumeMovementTimeForUserCmdProcessing( playerFrameTime );
761-
bool isBot = host_client->fakeclient;
762-
if ( !isBot && ( flTimeAllowedForProcessing < playerFrameTime ) )
763-
{
764-
// Make sure that the activity in command is erased because player cheated or dropped too many packets
765-
double dblWarningFrequencyThrottle = sv_maxusrcmdprocessticks_warning.value;
766-
if ( dblWarningFrequencyThrottle >= 0.0 )
767-
{
768-
static double s_dblLastWarningTime = 0.0;
769-
double dblTimeNow = Sys_FloatTime();
770-
if ( !s_dblLastWarningTime || ( dblTimeNow - s_dblLastWarningTime >= dblWarningFrequencyThrottle ) )
771-
{
772-
s_dblLastWarningTime = dblTimeNow;
773-
Con_Printf( "sv_maxusrcmdprocessticks_warning at server tick %u: Ignored client %s usrcmd (%.6f < %.6f)!\n",
774-
/* System::GetTick() */ 1337, host_client->name, flTimeAllowedForProcessing, playerFrameTime );
775-
}
776-
}
777-
return; // Don't process this command
778-
}
779-
#endif // REHLDS_FIXES
780-
781757
usercmd_t cmd = *ucmd;
782758
int i;
783759
edict_t *ent;
@@ -814,6 +790,54 @@ void SV_RunCmd(usercmd_t *ucmd, int random_seed)
814790
}
815791
#endif
816792

793+
#ifdef REHLDS_FIXES
794+
#define TICK_INTERVAL (1.0f / sys_ticrate.value)
795+
796+
CGameClient* gameClient = g_GameClients[host_client - g_psvs.clients];
797+
bool bRunNullCmd = false;
798+
if (int numUsrCmdProcessTicksMax = (int)sv_maxusrcmdprocessticks.value)
799+
{
800+
// Grant the client some time buffer to execute user commands
801+
gameClient->m_flMovementTimeForUserCmdProcessingRemaining += TICK_INTERVAL;
802+
803+
// but never accumulate more than N ticks
804+
if (gameClient->GetRemainingMovementTimeForUserCmdProcessing() > numUsrCmdProcessTicksMax * TICK_INTERVAL)
805+
{
806+
gameClient->m_flMovementTimeForUserCmdProcessingRemaining = numUsrCmdProcessTicksMax * TICK_INTERVAL;
807+
bRunNullCmd = true;
808+
}
809+
}
810+
/*else
811+
{
812+
// Otherwise we don't care to track time
813+
m_flMovementTimeForUserCmdProcessingRemaining = FLT_MAX;
814+
}
815+
*/
816+
817+
float playerFrameTime = TICK_INTERVAL;
818+
float flTimeAllowedForProcessing = gameClient->ConsumeMovementTimeForUserCmdProcessing(playerFrameTime);
819+
bool isBot = host_client->fakeclient;
820+
821+
if (!isBot && (flTimeAllowedForProcessing < playerFrameTime))
822+
{
823+
// Make sure that the activity in command is erased because player cheated or dropped too many packets
824+
double dblWarningFrequencyThrottle = sv_maxusrcmdprocessticks_warning.value;
825+
if (dblWarningFrequencyThrottle >= 0.0)
826+
{
827+
static double s_dblLastWarningTime = 0.0;
828+
double dblTimeNow = Sys_FloatTime();
829+
if (!s_dblLastWarningTime || (dblTimeNow - s_dblLastWarningTime >= dblWarningFrequencyThrottle))
830+
{
831+
s_dblLastWarningTime = dblTimeNow;
832+
Con_Printf("sv_maxusrcmdprocessticks_warning at server tick %u: Ignored client %s usrcmd (%.6f < %.6f)!\n",
833+
/* System::GetTick() */ 123, host_client->name, flTimeAllowedForProcessing, playerFrameTime);
834+
}
835+
}
836+
837+
return; // Don't process this command
838+
}
839+
#endif // REHLDS_FIXES
840+
817841
gEntityInterface.pfnCmdStart(sv_player, ucmd, random_seed);
818842
frametime = float(ucmd->msec * 0.001);
819843
host_client->svtimebase = frametime + host_client->svtimebase;

rehlds/rehlds/rehlds_interfaces_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ class CGameClient : public IGameClient
6767

6868
#ifdef REHLDS_FIXES
6969
double m_localGameTimeBase;
70-
71-
// How much of a movement time buffer can we process from this user?
72-
float m_flMovementTimeForUserCmdProcessingRemaining;
7370
#endif
7471
public:
7572
CGameClient(int id, client_t* cl);
@@ -254,6 +251,9 @@ class CGameClient : public IGameClient
254251
void SetupLocalGameTime() { m_localGameTimeBase = g_psv.time; }
255252
double GetLocalGameTime() const { return g_psv.time - m_localGameTimeBase; }
256253
double GetLocalGameTimeBase() const { return m_localGameTimeBase; }
254+
255+
// How much of a movement time buffer can we process from this user?
256+
float m_flMovementTimeForUserCmdProcessingRemaining;
257257

258258
float GetRemainingMovementTimeForUserCmdProcessing() const { return m_flMovementTimeForUserCmdProcessingRemaining; }
259259
float ConsumeMovementTimeForUserCmdProcessing( float flTimeNeeded )

0 commit comments

Comments
 (0)