]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - lhnet.c
added "sv_saveentfile" command to allow easy dumping of .ent files from maps so they...
[xonotic/darkplaces.git] / lhnet.c
diff --git a/lhnet.c b/lhnet.c
index 3854e2d4731aa738f3ae1d49e75368ea67c2fcc3..16cf41748734bcac2fded46bad9e4db14f4b3e08 100644 (file)
--- a/lhnet.c
+++ b/lhnet.c
@@ -9,7 +9,7 @@
 #include <winsock.h>
 #else
 #include <netdb.h>
-//#include <netinet/in.h>
+#include <netinet/in.h>
 //#include <arpa/inet.h>
 #include <unistd.h>
 #include <sys/socket.h>
 
 // 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
@@ -296,6 +299,9 @@ typedef struct lhnetpacket_s
        int sourceport;
        int destinationport;
        time_t timeout;
+#ifndef STANDALONETEST
+       double sentdoubletime;
+#endif
        struct lhnetpacket_s *next, *prev;
 }
 lhnetpacket_t;
@@ -481,6 +487,18 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength,
                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)
@@ -497,13 +515,6 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int 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)
@@ -521,11 +532,23 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength,
                {
 #ifdef WIN32
                        int e = WSAGetLastError();
-                       if (e == WSAEWOULDBLOCK || e == WSAECONNREFUSED)
+                       if (e == WSAEWOULDBLOCK)
                                return 0;
+                       switch (e)
+                       {
+                               case WSAECONNREFUSED:
+                                       Con_Printf("Connection refused\n");
+                                       return 0;
+                       }
 #else
-                       if (errno == EWOULDBLOCK || errno == ECONNREFUSED)
+                       if (errno == EWOULDBLOCK)
                                return 0;
+                       switch (errno)
+                       {
+                               case ECONNREFUSED:
+                                       Con_Printf("Connection refused\n");
+                                       return 0;
+                       }
 #endif
                }
        }
@@ -544,11 +567,23 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength,
                {
 #ifdef WIN32
                        int e = WSAGetLastError();
-                       if (e == WSAEWOULDBLOCK || e == WSAECONNREFUSED)
+                       if (e == WSAEWOULDBLOCK)
                                return 0;
+                       switch (e)
+                       {
+                               case WSAECONNREFUSED:
+                                       Con_Printf("Connection refused\n");
+                                       return 0;
+                       }
 #else
-                       if (errno == EWOULDBLOCK || errno == ECONNREFUSED)
+                       if (errno == EWOULDBLOCK)
                                return 0;
+                       switch (errno)
+                       {
+                               case ECONNREFUSED:
+                                       Con_Printf("Connection refused\n");
+                                       return 0;
+                       }
 #endif
                }
        }
@@ -558,7 +593,7 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength,
 int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentlength, const lhnetaddress_t *address)
 {
        int value = -1;
-       if (!lhnetsocket || !address || !content || maxcontentlength < 1)
+       if (!lhnetsocket || !address || !content || contentlength < 1)
                return -1;
        if (lhnetsocket->address.addresstype != address->addresstype)
                return -1;
@@ -576,6 +611,10 @@ int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentleng
                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)