Skip to content

Commit

Permalink
DELAY PACKET: Tidy-up limit checking
Browse files Browse the repository at this point in the history
  • Loading branch information
meag committed Dec 18, 2017
1 parent e0d8a80 commit 3918618
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions client.h
Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions net.c
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
17 changes: 11 additions & 6 deletions rulesets.c
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit 3918618

Please sign in to comment.