]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
some cleanups to hostcache (got rid of driver/address stuff and expanded the strings...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 25 May 2003 22:46:31 +0000 (22:46 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 25 May 2003 22:46:31 +0000 (22:46 +0000)
connecting to a server is now much more direct (does not use hostcache)
now ignores the address string received in server info packets because it's often bogus in dp (sorry...  but not really avoidable)
slist reports now include the address of the server (useful!!) and are much wider (79 characters) to give more room for info
the NOROUTINGFIX option has been kind of merged away, whether the server uses it or not is still optional (search for routing fix)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3038 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
net.h
net_dgrm.c
net_loop.c
net_main.c
server.h
sv_main.c
sv_user.c

index 03e340702f19cd01f4900e44344f39289f932fd0..cdd48bad020a847fa172d62cfe69fa885ff75912 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -1481,7 +1481,6 @@ void CL_SendCmd (void)
        // send the unreliable message
                CL_SendMove (&cmd);
        }
-#ifndef NOROUTINGFIX
        else if (cls.signon == 0 && !cls.demoplayback)
        {
                // LordHavoc: fix for NAT routing of netquake:
@@ -1507,7 +1506,6 @@ void CL_SendCmd (void)
                        }
                }
        }
-#endif
 
        if (cls.demoplayback)
        {
diff --git a/net.h b/net.h
index 386379ab7bbaa7a6ccf7364fadb150c11d9694f7..4a69b87201a9f3fd71c0abcd119a4f47c59e547a 100644 (file)
--- a/net.h
+++ b/net.h
@@ -227,18 +227,18 @@ void NET_FreeQSocket(qsocket_t *);
 double SetNetTime(void);
 
 
-#define HOSTCACHESIZE  8
+#define HOSTCACHESIZE  128
 
 typedef struct
 {
-       char    name[16];
-       char    map[16];
-       char    cname[32];
+       char    name[64];
+       char    map[64];
+       char    cname[64];
        int             users;
        int             maxusers;
-       int             driver;
-       int             ldriver;
-       struct qsockaddr addr;
+       //int           driver;
+       //int           ldriver;
+       //struct qsockaddr addr;
 } hostcache_t;
 
 extern int hostCacheCount;
index b3f7fae2c4d67a41bc63a311506051ef0e4ab17a..59ad6e685cab95bffb9ec29f544d8fdbb7538b89 100644 (file)
@@ -497,7 +497,7 @@ void NET_Stats_f (void)
        }
 }
 
-
+/*
 static qboolean testInProgress = false;
 static int             testPollCount;
 static int             testDriver;
@@ -751,7 +751,7 @@ JustDoIt:
        SZ_Clear(&net_message);
        SchedulePollProcedure(&test2PollProcedure, 0.05);
 }
-
+*/
 
 int Datagram_Init (void)
 {
@@ -777,8 +777,8 @@ int Datagram_Init (void)
 #ifdef BAN_TEST
        Cmd_AddCommand ("ban", NET_Ban_f);
 #endif
-       Cmd_AddCommand ("test", Test_f);
-       Cmd_AddCommand ("test2", Test2_f);
+       //Cmd_AddCommand ("test", Test_f);
+       //Cmd_AddCommand ("test2", Test2_f);
 
        return 0;
 }
@@ -1106,6 +1106,7 @@ static qboolean Datagram_HandleServerInfo (struct qsockaddr *readaddr)
        //struct qsockaddr myaddr;
        int control;
        int c, n, i;
+       char cname[256];
 
        if (net_message.cursize < (int)sizeof(int))
                return false;
@@ -1133,15 +1134,16 @@ static qboolean Datagram_HandleServerInfo (struct qsockaddr *readaddr)
        if (c != CCREP_SERVER_INFO)
                return false;
 
-       dfunc.GetAddrFromName(MSG_ReadString(), readaddr);
+       // LordHavoc: because the UDP driver reports 0.0.0.0:26000 as the address
+       // string we just ignore it and keep the real address
+       MSG_ReadString();
+       // hostcache only uses text addresses
+       strcpy(cname, dfunc.AddrToString(readaddr));
        // search the cache for this server
        for (n = 0; n < hostCacheCount; n++)
-               if (dfunc.AddrCompare(readaddr, &hostcache[n].addr) == 0)
-                       break;
-
-       // is it already there?
-       if (n < hostCacheCount)
-               return false;;
+               //if (dfunc.AddrCompare(readaddr, &hostcache[n].addr) == 0)
+               if (!strcmp(cname, hostcache[n].cname))
+                       return false;
 
        // add it
        hostCacheCount++;
@@ -1152,16 +1154,18 @@ static qboolean Datagram_HandleServerInfo (struct qsockaddr *readaddr)
        c = MSG_ReadByte();
        if (c != NET_PROTOCOL_VERSION)
        {
-               strcpy(hostcache[n].cname, hostcache[n].name);
-               hostcache[n].cname[14] = 0;
+               strncpy(hostcache[n].cname, hostcache[n].name, sizeof(hostcache[n].cname) - 1);
+               hostcache[n].cname[sizeof(hostcache[n].cname) - 1] = 0;
                strcpy(hostcache[n].name, "*");
-               strcat(hostcache[n].name, hostcache[n].cname);
+               strncat(hostcache[n].name, hostcache[n].cname, sizeof(hostcache[n].name) - 1);
+               hostcache[n].name[sizeof(hostcache[n].name) - 1] = 0;
        }
-       memcpy(&hostcache[n].addr, readaddr, sizeof(struct qsockaddr));
-       hostcache[n].driver = net_driverlevel;
-       hostcache[n].ldriver = net_landriverlevel;
-       strcpy(hostcache[n].cname, dfunc.AddrToString(readaddr));
+       strcpy(hostcache[n].cname, cname);
+       //memcpy(&hostcache[n].addr, readaddr, sizeof(struct qsockaddr));
+       //hostcache[n].driver = net_driverlevel;
+       //hostcache[n].ldriver = net_landriverlevel;
 
+       /*
        // check for a name conflict
        for (i = 0; i < hostCacheCount; i++)
        {
@@ -1180,6 +1184,7 @@ static qboolean Datagram_HandleServerInfo (struct qsockaddr *readaddr)
                        i = -1;
                }
        }
+       */
 
        return true;
 }
index 47d8d0e166f38a6b4d7bd6283a1def630770ddbe..72d3570047628a80d83238c38a62494b0dd918f2 100644 (file)
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 See the GNU General Public License for more details.
 
@@ -62,7 +62,7 @@ void Loop_SearchForHosts (qboolean xmit)
        strcpy(hostcache[0].map, sv.name);
        hostcache[0].users = net_activeconnections;
        hostcache[0].maxusers = svs.maxclients;
-       hostcache[0].driver = net_driverlevel;
+       //hostcache[0].driver = net_driverlevel;
        strcpy(hostcache[0].cname, "local");
 }
 
@@ -77,7 +77,7 @@ qsocket_t *Loop_Connect (const char *host)
 {
        if (strcmp(host,"local") != 0)
                return NULL;
-       
+
        localconnectpending = true;
 
        if (!loop_client)
@@ -108,8 +108,8 @@ qsocket_t *Loop_Connect (const char *host)
 
        loop_client->driverdata = (void *)loop_server;
        loop_server->driverdata = (void *)loop_client;
-       
-       return loop_client;     
+
+       return loop_client;
 }
 
 
index 51c3f3f41012f7f7b23aa247bc2d527eec09a741..d00276406e6172c6d9fdeb6a0c399330a69b8ae6 100644 (file)
@@ -336,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;
 }
 
@@ -345,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;
 }
 
@@ -508,58 +502,19 @@ hostcache_t hostcache[HOSTCACHESIZE];
 
 qsocket_t *NET_Connect (char *host)
 {
-       qsocket_t               *ret;
-       int                             n;
-
-       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;
-               }
-       }
+       qsocket_t *ret;
 
-       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)
@@ -569,14 +524,6 @@ JustDoIt:
                        return ret;
        }
 
-       if (host)
-       {
-               Con_Printf("\n");
-               PrintSlistHeader();
-               PrintSlist();
-               PrintSlistTrailer();
-       }
-
        return NULL;
 }
 
index a54fbf00e8d70a74477fe5bcc777cfd8a8526e54..b9f3aa86576ecc1ab392a2ceabdcd0831f41de0c 100644 (file)
--- a/server.h
+++ b/server.h
@@ -109,13 +109,11 @@ typedef struct client_s
        // only valid before spawned
        qboolean sendsignon;
 
-#ifndef NOROUTINGFIX
        // LordHavoc: to make netquake protocol get through NAT routers, have to wait for client to ack
        // waiting for connect from client (stage 1)
        qboolean waitingforconnect;
        // send server info in next datagram (stage 2)
        qboolean sendserverinfo;
-#endif
 
        // reliable messages must be sent periodically
        double last_message;
index 73827de419f9fae920ecf696fb8f77863c67458e..40cab13e6a5fb15e9569e2e60ac40556d645ba1e 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -291,9 +291,6 @@ void SV_SendServerinfo (client_t *client)
 
        MSG_WriteByte (&client->message, svc_signonnum);
        MSG_WriteByte (&client->message, 1);
-
-       client->sendsignon = true;
-       client->spawned = false;                // need prespawn, spawn, etc
 }
 
 /*
@@ -341,13 +338,17 @@ void SV_ConnectClient (int clientnum)
                        client->spawn_parms[i] = (&pr_global_struct->parm1)[i];
        }
 
-#if NOROUTINGFIX
+       client->sendserverinfo = false;
+       client->sendsignon = true;
+       client->spawned = false;                // need prespawn, spawn, etc
+       // LordHavoc: 1 = attempt to work through NAT routers
+#if 0
+       // send serverinfo immediately (may get lost if client is behind a NAT router)
+       client->waitingforconnect = false;
        SV_SendServerinfo (client);
 #else
-       // send serverinfo on first nop
+       // send serverinfo only after receiving a nop from client
        client->waitingforconnect = true;
-       client->sendsignon = true;
-       client->spawned = false;                // need prespawn, spawn, etc
 #endif
 }
 
@@ -1498,14 +1499,6 @@ void SV_SendClientMessages (void)
                if (!host_client->active)
                        continue;
 
-#ifndef NOROUTINGFIX
-               if (host_client->sendserverinfo)
-               {
-                       host_client->sendserverinfo = false;
-                       SV_SendServerinfo (host_client);
-               }
-#endif
-
                if (host_client->spawned)
                {
                        if (!SV_SendClientDatagram (host_client))
@@ -1520,6 +1513,12 @@ void SV_SendClientMessages (void)
                // between signon stages
                        if (!host_client->sendsignon)
                        {
+                               if (host_client->sendserverinfo)
+                               {
+                                       host_client->sendserverinfo = false;
+                                       SV_SendServerinfo (host_client);
+                               }
+
                                if (realtime - host_client->last_message > 5)
                                        SV_SendNop (host_client);
                                continue;       // don't send out non-signon messages
index f895390fd635365e710092243376677092d08ccb..48a576cd0529afd6aff4c902952376994af15821 100644 (file)
--- a/sv_user.c
+++ b/sv_user.c
@@ -540,6 +540,12 @@ nextmsg:
                if (!ret)
                        return true;
 
+               if (host_client->waitingforconnect)
+               {
+                       host_client->waitingforconnect = false;
+                       host_client->sendserverinfo = true;
+               }
+
                MSG_BeginReading ();
 
                while (1)
@@ -556,14 +562,6 @@ nextmsg:
 
                        cmd = MSG_ReadChar ();
 
-#ifndef NOROUTINGFIX
-                       if (cmd != -1 && host_client->waitingforconnect)
-                       {
-                               host_client->waitingforconnect = false;
-                               host_client->sendserverinfo = true;
-                       }
-#endif
-
                        switch (cmd)
                        {
                        case -1: