From 14418daa3cb38466864cd7cc53001bbb1bac2b22 Mon Sep 17 00:00:00 2001 From: havoc Date: Sun, 25 May 2003 22:46:31 +0000 Subject: [PATCH] some cleanups to hostcache (got rid of driver/address stuff and expanded the strings, also increased number of cache slots) 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 | 2 -- net.h | 14 +++++------ net_dgrm.c | 41 ++++++++++++++++-------------- net_loop.c | 10 ++++---- net_main.c | 73 ++++++++---------------------------------------------- server.h | 2 -- sv_main.c | 29 +++++++++++----------- sv_user.c | 14 +++++------ 8 files changed, 65 insertions(+), 120 deletions(-) diff --git a/cl_main.c b/cl_main.c index 03e34070..cdd48bad 100644 --- 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 386379ab..4a69b872 100644 --- 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; diff --git a/net_dgrm.c b/net_dgrm.c index b3f7fae2..59ad6e68 100644 --- a/net_dgrm.c +++ b/net_dgrm.c @@ -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; } diff --git a/net_loop.c b/net_loop.c index 47d8d0e1..72d35700 100644 --- a/net_loop.c +++ b/net_loop.c @@ -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; } diff --git a/net_main.c b/net_main.c index 51c3f3f4..d0027640 100644 --- a/net_main.c +++ b/net_main.c @@ -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; } diff --git a/server.h b/server.h index a54fbf00..b9f3aa86 100644 --- 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; diff --git a/sv_main.c b/sv_main.c index 73827de4..40cab13e 100644 --- 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 diff --git a/sv_user.c b/sv_user.c index f895390f..48a576cd 100644 --- 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: -- 2.39.2