// for Z_Malloc/Z_Free in quake
#ifndef STANDALONETEST
+#include "quakedef.h"
#include "zone.h"
+#include "sys.h"
+#include "netconn.h"
#else
#define Z_Malloc malloc
#define Z_Free free
int sourceport;
int destinationport;
time_t timeout;
+#ifndef STANDALONETEST
+ double sentdoubletime;
+#endif
struct lhnetpacket_s *next, *prev;
}
lhnetpacket_t;
for (p = lhnet_packetlist.next;p != &lhnet_packetlist;p = pnext)
{
pnext = p->next;
+ if (p->timeout < currenttime)
+ {
+ // unlink and free
+ p->next->prev = p->prev;
+ p->prev->next = p->next;
+ Z_Free(p);
+ continue;
+ }
+#ifndef STANDALONETEST
+ if (p->sentdoubletime && Sys_DoubleTime() < p->sentdoubletime)
+ continue;
+#endif
if (value == 0 && p->destinationport == lhnetsocket->address.addressdata.loop.port)
{
if (p->length <= maxcontentlength)
p->prev->next = p->next;
Z_Free(p);
}
- else if (p->timeout < currenttime)
- {
- // unlink and free
- p->next->prev = p->prev;
- p->prev->next = p->next;
- Z_Free(p);
- }
}
}
else if (lhnetsocket->address.addresstype == LHNETADDRESSTYPE_INET4)
p->prev = p->next->prev;
p->next->prev = p;
p->prev->next = p;
+#ifndef STANDALONETEST
+ if (cl_fakelocalping_min.integer || cl_fakelocalping_max.integer)
+ p->sentdoubletime = Sys_DoubleTime() + (cl_fakelocalping_min.integer + ((cl_fakelocalping_max.integer - cl_fakelocalping_min.integer) * (rand() & 255) / 256)) / 1000.0;
+#endif
value = contentlength;
}
else if (lhnetsocket->address.addresstype == LHNETADDRESSTYPE_INET4)
cvar_t hostname = {CVAR_SAVE, "hostname", "UNNAMED"};
cvar_t developer_networking = {0, "developer_networking", "0"};
+cvar_t cl_fakelocalping_min = {0, "cl_fakelocalping_min","0"};
+cvar_t cl_fakelocalping_max = {0, "cl_fakelocalping_max","0"};
+static cvar_t cl_fakepacketloss_receive = {0, "cl_fakepacketloss_receive","0"};
+static cvar_t cl_fakepacketloss_send = {0, "cl_fakepacketloss_send","0"};
+static cvar_t sv_fakepacketloss_receive = {0, "sv_fakepacketloss_receive","0"};
+static cvar_t sv_fakepacketloss_send = {0, "sv_fakepacketloss_send","0"};
+
+
/* statistic counters */
static int packetsSent = 0;
static int packetsReSent = 0;
int NetConn_Read(lhnetsocket_t *mysocket, void *data, int maxlength, lhnetaddress_t *peeraddress)
{
int length = LHNET_Read(mysocket, data, maxlength, peeraddress);
+ int i;
+ if (cl_fakepacketloss_receive.integer)
+ for (i = 0;i < cl_numsockets;i++)
+ if (cl_sockets[i] == mysocket && (rand() % 100) < cl_fakepacketloss_receive.integer)
+ return 0;
+ if (sv_fakepacketloss_receive.integer)
+ for (i = 0;i < cl_numsockets;i++)
+ if (sv_sockets[i] == mysocket && (rand() % 100) < sv_fakepacketloss_receive.integer)
+ return 0;
if (developer_networking.integer && length != 0)
{
char addressstring[128], addressstring2[128];
int NetConn_Write(lhnetsocket_t *mysocket, const void *data, int length, const lhnetaddress_t *peeraddress)
{
- int ret = LHNET_Write(mysocket, data, length, peeraddress);
+ int ret;
+ int i;
+ if (cl_fakepacketloss_send.integer)
+ for (i = 0;i < cl_numsockets;i++)
+ if (cl_sockets[i] == mysocket && (rand() % 100) < cl_fakepacketloss_send.integer)
+ return length;
+ if (sv_fakepacketloss_send.integer)
+ for (i = 0;i < cl_numsockets;i++)
+ if (sv_sockets[i] == mysocket && (rand() % 100) < sv_fakepacketloss_send.integer)
+ return length;
+ ret = LHNET_Write(mysocket, data, length, peeraddress);
if (developer_networking.integer)
{
char addressstring[128], addressstring2[128];
Cvar_RegisterVariable(&net_messagetimeout);
Cvar_RegisterVariable(&net_messagerejointimeout);
Cvar_RegisterVariable(&net_connecttimeout);
+ Cvar_RegisterVariable(&cl_fakelocalping_min);
+ Cvar_RegisterVariable(&cl_fakelocalping_max);
+ Cvar_RegisterVariable(&cl_fakepacketloss_receive);
+ Cvar_RegisterVariable(&cl_fakepacketloss_send);
+ Cvar_RegisterVariable(&sv_fakepacketloss_receive);
+ Cvar_RegisterVariable(&sv_fakepacketloss_send);
Cvar_RegisterVariable(&hostname);
Cvar_RegisterVariable(&developer_networking);
Cvar_RegisterVariable(&cl_netport);