Skip to content

Commit 97fbaea

Browse files
committed
implement
1 parent aaffe43 commit 97fbaea

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

rehlds/dlls/player.h

-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ class CBasePlayer : public CBaseMonster
321321
char m_SbarString1[ SBAR_STRING_SIZE ];
322322

323323
float m_flNextChatTime;
324-
325324
};
326325

327326
#define AUTOAIM_2DEGREES 0.0348994967025

rehlds/engine/server.h

+1
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_warning;
381382
#endif
382383
extern int sv_playermodel;
383384

rehlds/engine/sv_main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ 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 };
213214
#endif
214215

215216
delta_t *SV_LookupDelta(char *name)
@@ -8025,6 +8026,7 @@ void SV_Init(void)
80258026
Cvar_RegisterVariable(&sv_rollangle);
80268027
Cvar_RegisterVariable(&sv_use_entity_file);
80278028
Cvar_RegisterVariable(&sv_usercmd_custom_random_seed);
8029+
Cvar_RegisterVariable(&sv_maxusrcmdprocessticks_warning);
80288030
#endif
80298031

80308032
for (int i = 0; i < MAX_MODELS; i++)

rehlds/engine/sv_user.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,30 @@ 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+
const float playerFrameTime = (1.0f / sys_ticrate.value);
760+
const 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+
757781
usercmd_t cmd = *ucmd;
758782
int i;
759783
edict_t *ent;
@@ -804,6 +828,7 @@ void SV_RunCmd(usercmd_t *ucmd, int random_seed)
804828
SV_ForceFullClientsUpdate();
805829
#endif // REHLDS_FIXES
806830
}
831+
807832
sv_player->v.clbasevelocity[0] = 0;
808833
sv_player->v.clbasevelocity[1] = 0;
809834
sv_player->v.clbasevelocity[2] = 0;

rehlds/rehlds/rehlds_interfaces_impl.h

+24
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ 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;
7073
#endif
7174
public:
7275
CGameClient(int id, client_t* cl);
@@ -251,6 +254,27 @@ class CGameClient : public IGameClient
251254
void SetupLocalGameTime() { m_localGameTimeBase = g_psv.time; }
252255
double GetLocalGameTime() const { return g_psv.time - m_localGameTimeBase; }
253256
double GetLocalGameTimeBase() const { return m_localGameTimeBase; }
257+
258+
float GetRemainingMovementTimeForUserCmdProcessing() const { return m_flMovementTimeForUserCmdProcessingRemaining; }
259+
float ConsumeMovementTimeForUserCmdProcessing( float flTimeNeeded )
260+
{
261+
const float FLT_EPSILON = 0.03125f;
262+
if ( m_flMovementTimeForUserCmdProcessingRemaining <= 0.0f )
263+
return 0.0f;
264+
else if ( flTimeNeeded > m_flMovementTimeForUserCmdProcessingRemaining + FLT_EPSILON )
265+
{
266+
float flResult = m_flMovementTimeForUserCmdProcessingRemaining;
267+
m_flMovementTimeForUserCmdProcessingRemaining = 0.0f;
268+
return flResult;
269+
}
270+
else
271+
{
272+
m_flMovementTimeForUserCmdProcessingRemaining -= flTimeNeeded;
273+
if ( m_flMovementTimeForUserCmdProcessingRemaining < 0.0f )
274+
m_flMovementTimeForUserCmdProcessingRemaining = 0.0f;
275+
return flTimeNeeded;
276+
}
277+
}
254278
#endif
255279
};
256280

0 commit comments

Comments
 (0)