]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - net_main.c
no longer uses R_Shadow_VertexBuffer, instead uses aliasvert_vertex3f
[xonotic/darkplaces.git] / net_main.c
index e29480a309fd629d4d4926521ffb2c4dd2ae7b51..d00276406e6172c6d9fdeb6a0c399330a69b8ae6 100644 (file)
@@ -63,6 +63,7 @@ int unreliableMessagesReceived = 0;
 
 cvar_t net_messagetimeout = {0, "net_messagetimeout","300"};
 cvar_t hostname = {CVAR_SAVE, "hostname", "UNNAMED"};
+cvar_t developer_networking = {0, "developer_networking", "0"};
 
 qboolean       configRestored = false;
 
@@ -335,8 +336,8 @@ static void NET_Heartbeat_f (void)
 
 static void PrintSlistHeader(void)
 {
-       Con_Printf("Server          Map             Users\n");
-       Con_Printf("--------------- --------------- -----\n");
+       Con_Printf("Server Address        Name/Description                   Map             Users\n");
+       Con_Printf("--------------------- ---------------------------------- --------------- -----\n");
        slistLastShown = 0;
 }
 
@@ -344,14 +345,8 @@ static void PrintSlistHeader(void)
 static void PrintSlist(void)
 {
        int n;
-
        for (n = slistLastShown; n < hostCacheCount; n++)
-       {
-               if (hostcache[n].maxusers)
-                       Con_Printf("%-15.15s %-15.15s %2u/%2u\n", hostcache[n].name, hostcache[n].map, hostcache[n].users, hostcache[n].maxusers);
-               else
-                       Con_Printf("%-15.15s %-15.15s\n", hostcache[n].name, hostcache[n].map);
-       }
+               Con_Printf("%-21.21s %-34.34s %-15.15s %2u/%2u\n", hostcache[n].cname, hostcache[n].name, hostcache[n].map, hostcache[n].users, hostcache[n].maxusers);
        slistLastShown = n;
 }
 
@@ -361,12 +356,7 @@ static void PrintSlistTrailer(void)
        if (hostCacheCount)
                Con_Printf("== end list ==\n\n");
        else
-       {
-               if (gamemode == GAME_TRANSFUSION)
-                       Con_Printf("No Transfusion servers found.\n\n");
-               else
-                       Con_Printf("No Quake servers found.\n\n");
-       }
+               Con_Printf("No %s servers found.\n\n", gamename);
 }
 
 
@@ -377,10 +367,7 @@ void NET_SlistCommon (PollProcedure *sendProcedure, PollProcedure *pollProcedure
 
        if (! slistSilent)
        {
-               if (gamemode == GAME_TRANSFUSION)
-                       Con_Printf("Looking for Transfusion servers...\n");
-               else
-                       Con_Printf("Looking for Quake servers...\n");
+               Con_Printf("Looking for %s servers...\n", gamename);
                PrintSlistHeader();
        }
 
@@ -515,58 +502,19 @@ hostcache_t hostcache[HOSTCACHESIZE];
 
 qsocket_t *NET_Connect (char *host)
 {
-       qsocket_t               *ret;
-       int                             n;
+       qsocket_t *ret;
 
-       SetNetTime();
-
-       if (host && *host == 0)
-               host = NULL;
-
-       if (host)
-       {
-               if (strcasecmp (host, "local") == 0)
-               {
-                       net_driverlevel = 0;
-                       return dfunc.Connect (host);
-               }
-
-               if (hostCacheCount)
-               {
-                       for (n = 0; n < hostCacheCount; n++)
-                               if (strcasecmp (host, hostcache[n].name) == 0)
-                               {
-                                       host = hostcache[n].cname;
-                                       break;
-                               }
-                       if (n < hostCacheCount)
-                               goto JustDoIt;
-               }
-       }
-
-       slistSilent = host ? true : false;
-       NET_Slist_f ();
+       if (host == NULL || *host == 0)
+               return NULL;
 
-       while(slistInProgress)
-               NET_Poll();
+       SetNetTime();
 
-       if (host == NULL)
+       if (host && strcasecmp (host, "local") == 0)
        {
-               if (hostCacheCount != 1)
-                       return NULL;
-               host = hostcache[0].cname;
-               Con_Printf("Connecting to...\n%s @ %s\n\n", hostcache[0].name, host);
+               net_driverlevel = 0;
+               return dfunc.Connect (host);
        }
 
-       if (hostCacheCount)
-               for (n = 0; n < hostCacheCount; n++)
-                       if (strcasecmp (host, hostcache[n].name) == 0)
-                       {
-                               host = hostcache[n].cname;
-                               break;
-                       }
-
-JustDoIt:
        for (net_driverlevel = 0;net_driverlevel < net_numdrivers;net_driverlevel++)
        {
                if (net_drivers[net_driverlevel].initialized == false)
@@ -576,14 +524,6 @@ JustDoIt:
                        return ret;
        }
 
-       if (host)
-       {
-               Con_Printf("\n");
-               PrintSlistHeader();
-               PrintSlist();
-               PrintSlistTrailer();
-       }
-
        return NULL;
 }
 
@@ -708,7 +648,7 @@ returns -1 if the connection died
 int NET_SendMessage (qsocket_t *sock, sizebuf_t *data)
 {
        int             r;
-       
+
        if (!sock)
                return -1;
 
@@ -730,7 +670,7 @@ int NET_SendMessage (qsocket_t *sock, sizebuf_t *data)
 int NET_SendUnreliableMessage (qsocket_t *sock, sizebuf_t *data)
 {
        int             r;
-       
+
        if (!sock)
                return -1;
 
@@ -760,7 +700,7 @@ message to be transmitted.
 qboolean NET_CanSendMessage (qsocket_t *sock)
 {
        int             r;
-       
+
        if (!sock)
                return false;
 
@@ -770,7 +710,7 @@ qboolean NET_CanSendMessage (qsocket_t *sock)
        SetNetTime();
 
        r = sfunc.CanSendMessage(sock);
-       
+
        return r;
 }
 
@@ -808,71 +748,45 @@ int NET_SendToAll(sizebuf_t *data, int blocktime)
        double          start;
        int                     i;
        int                     count = 0;
-       qboolean        state1 [MAX_SCOREBOARD];
-       qboolean        state2 [MAX_SCOREBOARD];
+       qbyte           state [MAX_SCOREBOARD];
 
-       for (i=0, host_client = svs.clients ; i<svs.maxclients ; i++, host_client++)
+       for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
        {
-               if (!host_client->netconnection)
-                       continue;
-               if (host_client->active)
+               state[i] = 2;
+               if (host_client->netconnection && host_client->active)
                {
                        if (host_client->netconnection->driver == 0)
-                       {
                                NET_SendMessage(host_client->netconnection, data);
-                               state1[i] = true;
-                               state2[i] = true;
-                               continue;
-                       }
-                       count++;
-                       state1[i] = false;
-                       state2[i] = false;
-               }
-               else
-               {
-                       state1[i] = true;
-                       state2[i] = true;
+                       else
+                               state[i] = 0;
                }
        }
 
+       // for every player (simultaneously) wait for the first CanSendMessage
+       // and send the message, then wait for a second CanSendMessage (verifying
+       // it was received)
        start = Sys_DoubleTime();
-       while (count)
+       do
        {
                count = 0;
-               for (i=0, host_client = svs.clients ; i<svs.maxclients ; i++, host_client++)
+               for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
                {
-                       if (! state1[i])
+                       if (state[i] < 2)
                        {
-                               if (NET_CanSendMessage (host_client->netconnection))
-                               {
-                                       state1[i] = true;
-                                       NET_SendMessage(host_client->netconnection, data);
-                               }
-                               else
-                               {
-                                       NET_GetMessage (host_client->netconnection);
-                               }
                                count++;
-                               continue;
-                       }
-
-                       if (! state2[i])
-                       {
+                               // need to send to this one
                                if (NET_CanSendMessage (host_client->netconnection))
                                {
-                                       state2[i] = true;
+                                       if (state[i] == 0 && NET_SendMessage (host_client->netconnection, data) == -1)
+                                               state[i] = 2; // connection lost
+                                       state[i]++;
                                }
                                else
-                               {
                                        NET_GetMessage (host_client->netconnection);
-                               }
-                               count++;
-                               continue;
                        }
                }
-               if ((Sys_DoubleTime() - start) > blocktime)
-                       break;
        }
+       while (count && (Sys_DoubleTime() - start) < blocktime);
        return count;
 }
 
@@ -917,6 +831,7 @@ void NET_Init (void)
 
        Cvar_RegisterVariable (&net_messagetimeout);
        Cvar_RegisterVariable (&hostname);
+       Cvar_RegisterVariable (&developer_networking);
 
        Cmd_AddCommand ("net_slist", NET_Slist_f);
        Cmd_AddCommand ("net_inetslist", NET_InetSlist_f);