]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - net_wins.c
cleaned up shadow volume culling somewhat
[xonotic/darkplaces.git] / net_wins.c
index 240b9187d70bc66f500a58ea3f4a834bbe1db42f..16c1eb7a153339bc6db1abcf941b7f6558d35c93 100644 (file)
@@ -22,8 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "quakedef.h"
 #include "winquake.h"
 
-extern cvar_t hostname;
-
 #define MAXHOSTNAMELEN         256
 
 static int net_acceptsocket = -1;              // socket for fielding new connections
@@ -68,10 +66,10 @@ BOOL PASCAL FAR BlockingHook(void)
     MSG                msg;
     BOOL       ret;
  
-       if ((Sys_FloatTime() - blocktime) > 2.0)
+       if ((Sys_DoubleTime() - blocktime) > 2.0)
        {
                WSACancelBlockingCall();
-               return FALSE;
+               return false;
        }
 
     /* get the next message, if any */ 
@@ -83,12 +81,12 @@ BOOL PASCAL FAR BlockingHook(void)
         DispatchMessage(&msg); 
     } 
  
-    /* TRUE if we got a message */ 
+    /* true if we got a message */ 
     return ret; 
 } 
 
 
-void WINS_GetLocalAddress()
+void WINS_GetLocalAddress(void)
 {
        struct hostent  *local = NULL;
        char                    buff[MAXHOSTNAMELEN];
@@ -100,7 +98,7 @@ void WINS_GetLocalAddress()
        if (pgethostname(buff, MAXHOSTNAMELEN) == SOCKET_ERROR)
                return;
 
-       blocktime = Sys_FloatTime();
+       blocktime = Sys_DoubleTime();
        WSASetBlockingHook(BlockingHook);
        local = pgethostbyname(buff);
        WSAUnhookBlockingHook();
@@ -110,7 +108,7 @@ void WINS_GetLocalAddress()
        myAddr = *(int *)local->h_addr_list[0];
 
        addr = ntohl(myAddr);
-       sprintf(my_tcpip_address, "%d.%d.%d.%d", (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
+       sprintf(my_tcpip_address, "%d.%d.%d.%d", (int) ((addr >> 24) & 0xff), (int) ((addr >> 16) & 0xff), (int) ((addr >> 8) & 0xff), (int) (addr & 0xff));
 }
 
 
@@ -129,7 +127,7 @@ int WINS_Init (void)
        
        if (hInst == NULL)
        {
-               Con_SafePrintf ("Failed to load winsock.dll\n");
+               Con_SafePrintf ("Failed to load wsock32.dll\n");
                winsock_lib_initialized = false;
                return -1;
        }
@@ -156,7 +154,7 @@ int WINS_Init (void)
                !pgethostname || !pgethostbyname || !pgethostbyaddr ||
                !pgetsockname)
        {
-               Con_SafePrintf ("Couldn't GetProcAddress from winsock.dll\n");
+               Con_SafePrintf ("Couldn't GetProcAddress from wsock32.dll\n");
                return -1;
        }
 
@@ -321,7 +319,7 @@ this lets you type only as much of the net address as required, using
 the local network components to fill in the rest
 ============
 */
-static int PartialIPAddress (char *in, struct qsockaddr *hostaddr)
+static int PartialIPAddress (const char *in, struct qsockaddr *hostaddr)
 {
        char buff[256];
        char *b;
@@ -385,7 +383,7 @@ int WINS_CheckNewConnections (void)
        if (net_acceptsocket == -1)
                return -1;
 
-       if (precvfrom (net_acceptsocket, buf, sizeof(buf), MSG_PEEK, NULL, NULL) > 0)
+       if (precvfrom (net_acceptsocket, buf, sizeof(buf), MSG_PEEK, NULL, NULL) >= 0)
        {
                return net_acceptsocket;
        }
@@ -394,15 +392,30 @@ int WINS_CheckNewConnections (void)
 
 //=============================================================================
 
-int WINS_Read (int socket, byte *buf, int len, struct qsockaddr *addr)
+int WINS_Recv (qbyte *buf, int len, struct qsockaddr *addr)
+{
+       return WINS_Read (net_acceptsocket, buf, len, addr);
+}
+
+//=============================================================================
+
+int WINS_Send (qbyte *buf, int len, struct qsockaddr *addr)
+{
+       return WINS_Write (net_acceptsocket, buf, len, addr);
+}
+
+//=============================================================================
+
+int WINS_Read (int socket, qbyte *buf, int len, struct qsockaddr *addr)
 {
        int addrlen = sizeof (struct qsockaddr);
        int ret;
+       int errno;
 
        ret = precvfrom (socket, buf, len, 0, (struct sockaddr *)addr, &addrlen);
        if (ret == -1)
        {
-               int errno = pWSAGetLastError();
+                errno = pWSAGetLastError();
 
                if (errno == WSAEWOULDBLOCK || errno == WSAECONNREFUSED)
                        return 0;
@@ -427,7 +440,7 @@ int WINS_MakeSocketBroadcastCapable (int socket)
 
 //=============================================================================
 
-int WINS_Broadcast (int socket, byte *buf, int len)
+int WINS_Broadcast (int socket, qbyte *buf, int len)
 {
        int ret;
 
@@ -449,7 +462,7 @@ int WINS_Broadcast (int socket, byte *buf, int len)
 
 //=============================================================================
 
-int WINS_Write (int socket, byte *buf, int len, struct qsockaddr *addr)
+int WINS_Write (int socket, qbyte *buf, int len, struct qsockaddr *addr)
 {
        int ret;
 
@@ -463,7 +476,7 @@ int WINS_Write (int socket, byte *buf, int len, struct qsockaddr *addr)
 
 //=============================================================================
 
-char *WINS_AddrToString (struct qsockaddr *addr)
+char *WINS_AddrToString (const struct qsockaddr *addr)
 {
        static char buffer[22];
        int haddr;
@@ -475,7 +488,7 @@ char *WINS_AddrToString (struct qsockaddr *addr)
 
 //=============================================================================
 
-int WINS_StringToAddr (char *string, struct qsockaddr *addr)
+int WINS_StringToAddr (const char *string, struct qsockaddr *addr)
 {
        int ha1, ha2, ha3, ha4, hp;
        int ipaddr;
@@ -507,7 +520,7 @@ int WINS_GetSocketAddr (int socket, struct qsockaddr *addr)
 
 //=============================================================================
 
-int WINS_GetNameFromAddr (struct qsockaddr *addr, char *name)
+int WINS_GetNameFromAddr (const struct qsockaddr *addr, char *name)
 {
        struct hostent *hostentry;
 
@@ -524,7 +537,7 @@ int WINS_GetNameFromAddr (struct qsockaddr *addr, char *name)
 
 //=============================================================================
 
-int WINS_GetAddrFromName(char *name, struct qsockaddr *addr)
+int WINS_GetAddrFromName(const char *name, struct qsockaddr *addr)
 {
        struct hostent *hostentry;
 
@@ -544,7 +557,7 @@ int WINS_GetAddrFromName(char *name, struct qsockaddr *addr)
 
 //=============================================================================
 
-int WINS_AddrCompare (struct qsockaddr *addr1, struct qsockaddr *addr2)
+int WINS_AddrCompare (const struct qsockaddr *addr1, const struct qsockaddr *addr2)
 {
        if (addr1->sa_family != addr2->sa_family)
                return -1;
@@ -572,4 +585,3 @@ int WINS_SetSocketPort (struct qsockaddr *addr, int port)
        return 0;
 }
 
-//=============================================================================