]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - lhnet.c
added Print versions of Printf functions and made all calls that do not need formatin...
[xonotic/darkplaces.git] / lhnet.c
diff --git a/lhnet.c b/lhnet.c
index 34052e14c55708895cafead6f5e51c1b5aaed1d8..58033bac8fe18646028a5621af32c318a558a675 100644 (file)
--- a/lhnet.c
+++ b/lhnet.c
@@ -444,17 +444,10 @@ lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address)
                case LHNETADDRESSTYPE_INET4:
                case LHNETADDRESSTYPE_INET6:
 #ifdef WIN32
-                       if (!lhnet_didWSAStartup && !WSAStartup(MAKEWORD(1, 1), &lhnet_winsockdata))
-                       {
-                               lhnet_didWSAStartup = 1;
-#else
+                       if (lhnet_didWSAStartup || (lhnet_didWSAStartup = !WSAStartup(MAKEWORD(1, 1), &lhnet_winsockdata)))
                        {
 #endif
-                               if (address->addresstype == LHNETADDRESSTYPE_INET6)
-                                       lhnetsocket->inetsocket = socket(LHNETADDRESSTYPE_INET6_FAMILY, SOCK_DGRAM, IPPROTO_UDP);
-                               else
-                                       lhnetsocket->inetsocket = socket(LHNETADDRESSTYPE_INET4_FAMILY, SOCK_DGRAM, IPPROTO_UDP);
-                               if (lhnetsocket->inetsocket != -1)
+                               if ((lhnetsocket->inetsocket = socket(address->addresstype == LHNETADDRESSTYPE_INET6 ? LHNETADDRESSTYPE_INET6_FAMILY : LHNETADDRESSTYPE_INET4_FAMILY, SOCK_DGRAM, IPPROTO_UDP)) != -1)
                                {
 #ifdef WIN32
                                        u_long _true = 1;
@@ -485,7 +478,11 @@ lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address)
                                }
                                else
                                        Con_Printf("LHNET_OpenSocket_Connectionless: socket returned error: %s\n", LHNETPRIVATE_StrError());
+#ifdef WIN32
                        }
+                       else
+                               Con_Print("LHNET_OpenSocket_Connectionless: WSAStartup failed\n");
+#endif
                        break;
                default:
                        break;
@@ -600,7 +597,7 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength,
                        switch (e)
                        {
                                case WSAECONNREFUSED:
-                                       Con_Printf("Connection refused\n");
+                                       Con_Print("Connection refused\n");
                                        return 0;
                        }
 #else
@@ -609,7 +606,7 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength,
                        switch (errno)
                        {
                                case ECONNREFUSED:
-                                       Con_Printf("Connection refused\n");
+                                       Con_Print("Connection refused\n");
                                        return 0;
                        }
 #endif
@@ -635,7 +632,7 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength,
                        switch (e)
                        {
                                case WSAECONNREFUSED:
-                                       Con_Printf("Connection refused\n");
+                                       Con_Print("Connection refused\n");
                                        return 0;
                        }
 #else
@@ -644,7 +641,7 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength,
                        switch (errno)
                        {
                                case ECONNREFUSED:
-                                       Con_Printf("Connection refused\n");
+                                       Con_Print("Connection refused\n");
                                        return 0;
                        }
 #endif
@@ -675,8 +672,8 @@ int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentleng
                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;
+               if (cl_fakelocalping_min.value || cl_fakelocalping_max.value)
+                       p->sentdoubletime = Sys_DoubleTime() + lhrandom(cl_fakelocalping_min.value, cl_fakelocalping_max.value) * (0.5 / 1000.0);
 #endif
                value = contentlength;
        }