From b5034f28d6bde81b4afa2417fc9f05b455d6373a Mon Sep 17 00:00:00 2001 From: "Zephaniah E. Hull" Date: Wed, 19 Jan 2000 16:35:26 +0000 Subject: [PATCH] The real speed cheat fix! --- qw_server/server.h | 4 +-- qw_server/sv_main.c | 10 ++---- qw_server/sv_user.c | 83 +++++++++++++-------------------------------- 3 files changed, 28 insertions(+), 69 deletions(-) diff --git a/qw_server/server.h b/qw_server/server.h index 911dbe0..281afb6 100644 --- a/qw_server/server.h +++ b/qw_server/server.h @@ -193,8 +193,8 @@ typedef struct client_s int delta_sequence; // -1 = no compression int ping; netchan_t netchan; - int msecs[MAX_MSECS], msec_count, msec_head, msec_total, msec_pool; - double frame_time; + int msecs, msec_cheating; + double last_check; } client_t; // a client can leave the server in one of four ways: diff --git a/qw_server/sv_main.c b/qw_server/sv_main.c index 48fdabd..bd3fae0 100644 --- a/qw_server/sv_main.c +++ b/qw_server/sv_main.c @@ -714,13 +714,9 @@ void SVC_DirectConnect (void) newcl->sendinfo = true; // QuakeForge stuff. - for (i=0; imsecs[i] = 0; - - newcl->msec_count = 0; - newcl->msec_head = 0; - newcl->msec_total = 0; - newcl->frame_time = realtime; + newcl->msecs = 0; + newcl->msec_cheating = 0; + newcl->last_check = realtime; } int Rcon_Validate (void) diff --git a/qw_server/sv_user.c b/qw_server/sv_user.c index d4c7a1f..a0ac56c 100644 --- a/qw_server/sv_user.c +++ b/qw_server/sv_user.c @@ -1368,6 +1368,7 @@ void SV_PreRunCmd(void) /* maximum msec offset we will allow before penalizing the player */ #define POOLMAX 150 +#define CHECK_TIME 10 /* =========== SV_RunCmd @@ -1376,71 +1377,33 @@ SV_RunCmd void SV_RunCmd (usercmd_t *ucmd, qboolean inside) { edict_t *ent; - int i, n, oldmsec, idealmsec; + int i, n, oldmsec; double tmp_time; // To prevent a infinite loop if (!inside) { - oldmsec = ucmd->msec; - // Calculate the ideal msec. - tmp_time = realtime - host_client->frame_time; - idealmsec = tmp_time * 1000; + host_client->msecs += ucmd->msec; - if (loss) - idealmsec /= (loss + 1); + if ((tmp_time = realtime - host_client->last_check) >= CHECK_TIME) { + tmp_time *= 1000; + if (host_client->msecs > tmp_time) { + host_client->msec_cheating++; + SV_BroadcastPrintf(PRINT_HIGH, + va("Err, %s may be CHEATING! %d %f %d\n", + host_client->name, host_client->msecs, tmp_time, + host_client->msec_cheating)); - // Cap it at a max of 250 msec though.. - idealmsec = min(idealmsec, 250); - idealmsec = max(idealmsec, 10); + if (host_client->msec_cheating >= 2) { + SV_BroadcastPrintf(PRINT_HIGH, + va("*WHACK* %s (%s) has been caught cheating!\n", + host_client->name, NET_AdrToString(host_client->netchan.remote_address))); + SV_DropClient(host_client); + } + } - host_client->msec_total -= host_client->msecs[host_client->msec_head]; - host_client->msec_total += idealmsec; - - host_client->msecs[host_client->msec_head] = idealmsec; - host_client->msec_head = (host_client->msec_head + 1) % MSECSIZE; - host_client->msec_count = min(MSECSIZE, host_client->msec_count + 1); - - host_client->msec_pool += idealmsec - oldmsec; - -#if 0 - if (abs(host_client->msec_pool) > POOLMAX) - { - printf("tmp_t: %f, realt: %f, frame_t: %f, loss: %d, total: %d\n", - tmp_time, realtime, host_client->frame_time, loss, - host_client->msec_total); -/* - printf("%3d %3d %3d %3d %3d ", - host_client->msecs[0], - host_client->msecs[1], - host_client->msecs[2], - host_client->msecs[3], - host_client->msecs[4]); -*/ - if (abs(host_client->msec_pool) > POOLMAX) - printf("*** "); - else - printf(" "); - - printf("oldmsec: %d, msec: %d, pool: %d\n", oldmsec, - idealmsec, host_client->msec_pool); + host_client->msecs = 0; + host_client->last_check = realtime; } -#endif - - if (abs(host_client->msec_pool) > POOLMAX) - { - /* if our pool exceeds POOLMAX msec, empty it into msec. This - should cause the client to 'jitter' back a bit as his - position is reset. */ - ucmd->msec = oldmsec - host_client->msec_pool; - host_client->msec_pool = 0; - } else - { - /* trust the client - if he's cheating, his pool will overflow - anyway within a couple of packets. */ - ucmd->msec = oldmsec; - } - - host_client->frame_time = realtime; } cmd = *ucmd; @@ -1712,13 +1675,13 @@ void SV_ExecuteClientMessage (client_t *cl) if (net_drop < 20) { while (net_drop > 2) { - SV_RunCmd (&cl->lastcmd, 1); + SV_RunCmd (&cl->lastcmd, 0); net_drop--; } if (net_drop > 1) - SV_RunCmd (&oldest, 1); + SV_RunCmd (&oldest, 0); if (net_drop > 0) - SV_RunCmd (&oldcmd, 1); + SV_RunCmd (&oldcmd, 0); } SV_RunCmd (&newcmd, 0);