From 3918618bbc81ca312ba26046f2ffb1fced3467a3 Mon Sep 17 00:00:00 2001 From: meag Date: Mon, 27 Nov 2017 11:34:24 +0000 Subject: [PATCH] DELAY PACKET: Tidy-up limit checking --- client.h | 1 + net.c | 4 ++-- rulesets.c | 17 +++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/client.h b/client.h index 56644e575..4d9a6158d 100644 --- a/client.h +++ b/client.h @@ -999,6 +999,7 @@ extern cvar_t cl_delay_packet_dev; #define CL_MAX_DELAYED_PACKETS 16 /* 13 * 16 = 208 ms, should be enough */ #define CL_MAX_PACKET_DELAY 75 /* total delay two times more */ +#define CL_MAX_PACKET_DELAY_DEVIATION 5 typedef struct cl_delayed_packet_s { diff --git a/net.c b/net.c index cb1a521a9..1db66a841 100644 --- a/net.c +++ b/net.c @@ -132,7 +132,7 @@ static qbool NET_PacketQueueAdd(packet_queue_t* queue, byte* data, int size, net { cl_delayed_packet_t* next = &queue->packets[queue->tail]; double time = Sys_DoubleTime(); - float deviation = f_rnd(-bound(0, cl_delay_packet_dev.value, 12), bound(0, cl_delay_packet_dev.value, 12)); + float deviation = f_rnd(-bound(0, cl_delay_packet_dev.integer, CL_MAX_PACKET_DELAY_DEVIATION), bound(0, cl_delay_packet_dev.integer, CL_MAX_PACKET_DELAY_DEVIATION)); // If buffer is full, can't prevent packet loss - drop this packet if (next->time && queue->head == queue->tail) @@ -141,7 +141,7 @@ static qbool NET_PacketQueueAdd(packet_queue_t* queue, byte* data, int size, net memmove(next->data, data, size); next->length = size; next->addr = addr; - next->time = time + 0.001 * bound(0, 0.5 * cl_delay_packet.value + deviation, CL_MAX_PACKET_DELAY); + next->time = time + 0.001 * bound(0, 0.5 * cl_delay_packet.integer + deviation, CL_MAX_PACKET_DELAY); NET_PacketQueueSetNextIndex(&queue->tail); return true; diff --git a/rulesets.c b/rulesets.c index 2513ceb98..f821f5ba1 100644 --- a/rulesets.c +++ b/rulesets.c @@ -445,7 +445,7 @@ void Rulesets_OnChange_allow_scripts (cvar_t *var, char *value, qbool *cancel) p = Info_ValueForKey(cl.serverinfo, "status"); progress = (strstr (p, "left")) ? true : false; - val = Q_atoi(value);; + val = Q_atoi(value); if (cls.state >= ca_connected && progress && !cl.spectator) { Com_Printf ("%s changes are not allowed during the match.\n", var->name); @@ -468,16 +468,21 @@ void Rulesets_OnChange_allow_scripts (cvar_t *var, char *value, qbool *cancel) void Rulesets_OnChange_cl_delay_packet(cvar_t *var, char *value, qbool *cancel) { - int ival = Q_atoi(value); // this is used in the code - float fval = Q_atof(value); // this is used to check value validity + int ival = Q_atoi(value); - if (ival == var->integer && fval == var->value) { + if (ival == var->integer) { // no change return; } - if (fval < 0) { - Com_Printf("%s doesn't allow negative values\n", var->name); + if (var == &cl_delay_packet && (ival < 0 || ival > CL_MAX_PACKET_DELAY * 2)) { + Com_Printf("%s must be between 0 and %d\n", var->name, CL_MAX_PACKET_DELAY * 2); + *cancel = true; + return; + } + + if (var == &cl_delay_packet_dev && (ival < 0 || ival > CL_MAX_PACKET_DELAY_DEVIATION)) { + Com_Printf("%s must be between 0 and %d\n", var->name, CL_MAX_PACKET_DELAY_DEVIATION); *cancel = true; return; }