From 3c4b5fabb6719f02221dcfa5c79d0a87ea7d2192 Mon Sep 17 00:00:00 2001 From: Spoike Date: Sat, 7 Apr 2018 12:33:06 +0000 Subject: [PATCH] Make the default port re-brandable to reduce confusion with TCs. Make sure TCs send server query broadcasts. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5235 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/cl_main.c | 44 ++++++++++++++++++++++----------- engine/client/net_master.c | 3 ++- engine/common/config_fteqw.h | 5 ++-- engine/common/config_minimal.h | 5 ++-- engine/common/config_nocompat.h | 1 + engine/common/config_wastes.h | 1 + engine/common/net_wins.c | 34 ++++++++++++++++--------- engine/common/protocol.h | 7 ++++++ engine/server/pr_lua.c | 44 ++++++++++++++++----------------- 9 files changed, 91 insertions(+), 53 deletions(-) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 20f1389af..41cd7aa3a 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -69,7 +69,19 @@ cvar_t *hud_tracking_show; cvar_t *hud_miniscores_show; extern cvar_t net_compress; -cvar_t cl_defaultport = CVARAFD("cl_defaultport", STRINGIFY(PORT_QWSERVER), "port", 0, "The default port to connect to servers.\nQW: "STRINGIFY(PORT_QWSERVER)", NQ: "STRINGIFY(PORT_NQSERVER)", Q2: "STRINGIFY(PORT_Q2SERVER)"."); +cvar_t cl_defaultport = + #ifdef GAME_DEFAULTPORT //remove the confusing port alias if we're running as a TC, as well as info about irrelevant games. + CVARFD("cl_defaultport", STRINGIFY(PORT_DEFAULTSERVER), 0, "The default port used to connect to servers.") + #else + CVARAFD("cl_defaultport", STRINGIFY(PORT_DEFAULTSERVER), "port", 0, "The default port used to connect to servers." + "\nQW: "STRINGIFY(PORT_QWSERVER) + ", NQ: "STRINGIFY(PORT_NQSERVER) + ", Q2: "STRINGIFY(PORT_Q2SERVER) + ", Q3: "STRINGIFY(PORT_Q3SERVER) + "." + ) + #endif + ; cvar_t cfg_save_name = CVARFD("cfg_save_name", "fte", CVAR_ARCHIVE|CVAR_NOTFROMSERVER, "This is the config name that is saved by default when no argument is specified."); @@ -586,7 +598,7 @@ void CL_SendConnectPacket (netadr_t *to, int mtu, if (!to) { to = &addr; - if (!NET_StringToAdr (cls.servername, PORT_QWSERVER, to)) + if (!NET_StringToAdr (cls.servername, PORT_DEFAULTSERVER, to)) { Con_TPrintf ("CL_SendConnectPacket: Bad server address \"%s\"\n", cls.servername); connectinfo.trying = false; @@ -2453,7 +2465,7 @@ void CL_Packet_f (void) return; } - if (!NET_StringToAdr (Cmd_Argv(1), PORT_QWSERVER, &adr)) + if (!NET_StringToAdr (Cmd_Argv(1), PORT_DEFAULTSERVER, &adr)) { Con_Printf ("Bad address: %s\n", Cmd_Argv(1)); return; @@ -2814,7 +2826,7 @@ void CL_ConnectionlessPacket (void) netadr_t adr; char *data = MSG_ReadStringLine(); Con_TPrintf ("redirect to %s\n", data); - if (NET_StringToAdr(data, PORT_QWSERVER, &adr)) + if (NET_StringToAdr(data, PORT_DEFAULTSERVER, &adr)) { data = "\xff\xff\xff\xffgetchallenge\n"; @@ -4354,17 +4366,19 @@ void CL_Init (void) "Use a scheme of tcp:// or tls:// to connect via non-udp protocols." #endif #if defined(NQPROT) || defined(Q2CLIENT) || defined(Q3CLIENT) - "\nDefault port is port "STRINGIFY(PORT_QWSERVER)"." -#ifdef NQPROT - " NQ:"STRINGIFY(PORT_NQSERVER)"." -#endif - " QW:"STRINGIFY(PORT_QWSERVER)"." -#ifdef Q2CLIENT - " Q2:"STRINGIFY(PORT_Q2SERVER)"." -#endif -#ifdef Q3CLIENT - " Q3:"STRINGIFY(PORT_Q3SERVER)"." -#endif + "\nDefault port is port "STRINGIFY(PORT_DEFAULTSERVER)"." + #ifndef GAME_DEFAULTPORT + #ifdef NQPROT + " NQ:"STRINGIFY(PORT_NQSERVER)"." + #endif + " QW:"STRINGIFY(PORT_QWSERVER)"." + #ifdef Q2CLIENT + " Q2:"STRINGIFY(PORT_Q2SERVER)"." + #endif + #ifdef Q3CLIENT + " Q3:"STRINGIFY(PORT_Q3SERVER)"." + #endif + #endif #endif ); Cmd_AddCommandD ("cl_transfer", CL_Transfer_f, "Connect to a different server, disconnecting from the current server only when the new server replies."); diff --git a/engine/client/net_master.c b/engine/client/net_master.c index cae615fdc..1f7ca2740 100644 --- a/engine/client/net_master.c +++ b/engine/client/net_master.c @@ -2636,8 +2636,9 @@ void MasterInfo_Refresh(void) Master_LoadMasterList("servers.txt", false, MT_MASTERUDP, MP_QUAKEWORLD, 1); - Master_AddMaster("255.255.255.255:"STRINGIFY(PORT_QWSERVER), MT_BCAST, MP_QUAKEWORLD, "Nearby QuakeWorld UDP servers."); + Master_AddMaster("255.255.255.255:"STRINGIFY(PORT_DEFAULTSERVER), MT_BCAST, MP_DPMASTER, "Nearby Game Servers."); #ifndef QUAKETC + Master_AddMaster("255.255.255.255:"STRINGIFY(PORT_QWSERVER), MT_BCAST, MP_QUAKEWORLD, "Nearby QuakeWorld UDP servers."); Master_AddMasterHTTP("http://www.gameaholic.com/servers/qspy-quakeworld", MT_MASTERHTTP, MP_QUAKEWORLD, "gameaholic's QW master"); Master_AddMasterHTTP("https://www.quakeservers.net/lists/servers/global.txt",MT_MASTERHTTP, MP_QUAKEWORLD, "QuakeServers.net (http)"); #endif diff --git a/engine/common/config_fteqw.h b/engine/common/config_fteqw.h index f2c1dceaf..1af02ef6b 100644 --- a/engine/common/config_fteqw.h +++ b/engine/common/config_fteqw.h @@ -12,10 +12,11 @@ //#define BRANDING_ICON "fte_eukara.ico" //The file to use in windows' resource files - for linux your game should include an icon.[png|ico] file in the game's data. //filesystem rebranding -//#define GAME_SHORTNAME "wastes" //short alphanumeric description +//#define GAME_SHORTNAME "quake" //short alphanumeric description //#define GAME_FULLNAME FULLENGINENAME //full name of the game we're playing //#define GAME_BASEGAMES GAME_SHORTNAME //comma-separate list of basegame strings to use -//#define GAME_PROTOCOL "FTE-Wastes" //so other games won't show up in the server browser +//#define GAME_PROTOCOL "FTE-Quake" //so other games won't show up in the server browser +//#define GAME_DEFAULTPORT 27500 //slightly reduces the chance of people connecting to the wrong type of server //#define GAME_IDENTIFYINGFILES NULL //with multiple games, this string-list gives verification that the basedir is actually valid. if null, will just be assumed correct. //#define GAME_DOWNLOADSURL NULL //url for the package manger to update from //#define GAME_DEFAULTCMDS NULL //a string containing the things you want to exec in order to override default.cfg diff --git a/engine/common/config_minimal.h b/engine/common/config_minimal.h index b99217c00..66a85eea6 100644 --- a/engine/common/config_minimal.h +++ b/engine/common/config_minimal.h @@ -14,10 +14,11 @@ //#define BRANDING_ICON "fte_eukara.ico" //The file to use in windows' resource files - for linux your game should include an icon.[png|ico] file in the game's data. //filesystem rebranding -//#define GAME_SHORTNAME "wastes" //short alphanumeric description +//#define GAME_SHORTNAME "quake" //short alphanumeric description //#define GAME_FULLNAME FULLENGINENAME //full name of the game we're playing //#define GAME_BASEGAMES GAME_SHORTNAME //comma-separate list of basegame strings to use -//#define GAME_PROTOCOL "FTE-Wastes" //so other games won't show up in the server browser +//#define GAME_PROTOCOL "FTE-Quake" //so other games won't show up in the server browser +//#define GAME_DEFAULTPORT 27500 //slightly reduces the chance of people connecting to the wrong type of server //#define GAME_IDENTIFYINGFILES NULL //with multiple games, this string-list gives verification that the basedir is actually valid. if null, will just be assumed correct. //#define GAME_DOWNLOADSURL NULL //url for the package manger to update from //#define GAME_DEFAULTCMDS NULL //a string containing the things you want to exec in order to override default.cfg diff --git a/engine/common/config_nocompat.h b/engine/common/config_nocompat.h index a664ca468..a47581e20 100644 --- a/engine/common/config_nocompat.h +++ b/engine/common/config_nocompat.h @@ -16,6 +16,7 @@ //#define GAME_FULLNAME FULLENGINENAME //full name of the game we're playing //#define GAME_BASEGAMES GAME_SHORTNAME //comma-separate list of basegame strings to use //#define GAME_PROTOCOL "FTE-Generic" //so other games won't show up in the server browser +//#define GAME_DEFAULTPORT 27500 //slightly reduces the chance of people connecting to the wrong type of server //#define GAME_IDENTIFYINGFILES NULL //with multiple games, this string-list gives verification that the basedir is actually valid. if null, will just be assumed correct. //#define GAME_DOWNLOADSURL NULL //url for the package manger to update from //#define GAME_DEFAULTCMDS NULL //a string containing the things you want to exec in order to override default.cfg diff --git a/engine/common/config_wastes.h b/engine/common/config_wastes.h index a3ea6225f..17d0c0a53 100644 --- a/engine/common/config_wastes.h +++ b/engine/common/config_wastes.h @@ -15,6 +15,7 @@ #define GAME_FULLNAME FULLENGINENAME //full name of the game we're playing #define GAME_BASEGAMES GAME_SHORTNAME //comma-separate list of basegame strings to use #define GAME_PROTOCOL "FTE-Wastes" //so other games won't show up in the server browser +#define GAME_DEFAULTPORT 27500 //FIXME: change me! //#define GAME_IDENTIFYINGFILES NULL //with multiple games, this string-list gives verification that the basedir is actually valid. if null, will just be assumed correct. //#define GAME_DOWNLOADSURL NULL //url for the package manger to update from //#define GAME_DEFAULTCMDS NULL //a string containing the things you want to diff --git a/engine/common/net_wins.c b/engine/common/net_wins.c index 655045518..e1b0617ca 100644 --- a/engine/common/net_wins.c +++ b/engine/common/net_wins.c @@ -3076,9 +3076,11 @@ ftenet_generic_connection_t *FTENET_Datagram_EstablishConnection(qboolean isserv int family; int port; int bindtries; + const int bindmaxtries = 100; int bufsz; qboolean hybrid = false; int protocol; + char addrstr[128]; switch(adr.type) { @@ -3101,7 +3103,7 @@ ftenet_generic_connection_t *FTENET_Datagram_EstablishConnection(qboolean isserv if (adr.type == NA_INVALID) { - Con_Printf("unable to resolve local address %s\n", address); + Con_Printf(CON_ERROR "unable to resolve local address %s\n", address); return NULL; //couldn't resolve the name } temp = NetadrToSockadr(&adr, &qs); @@ -3167,24 +3169,34 @@ ftenet_generic_connection_t *FTENET_Datagram_EstablishConnection(qboolean isserv //try and find an unused port. port = ntohs(((struct sockaddr_in*)&qs)->sin_port); - for (bindtries = 100; bindtries > 0; bindtries--) + for (bindtries = 0; bindtries < bindmaxtries; bindtries++) { - ((struct sockaddr_in*)&qs)->sin_port = htons((unsigned short)(port+100-bindtries)); + ((struct sockaddr_in*)&qs)->sin_port = htons((unsigned short)(port+bindtries)); if ((bind(newsocket, (struct sockaddr *)&qs, temp) == INVALID_SOCKET)) { + if (port == 0) + { //if binding to an ephemerial port failed, binding to the admin-only ports won't work any better... + bindtries = bindmaxtries; + break; + } continue; } break; } - if (!bindtries) + if (bindtries == bindmaxtries) { SockadrToNetadr(&qs, &adr); - //mneh, reuse qs. - NET_AdrToString((char*)&qs, sizeof(qs), &adr); - Con_Printf("Unable to listen at %s\n", (char*)&qs); + NET_AdrToString(addrstr, sizeof(addrstr), &adr); + Con_Printf(CON_ERROR "Unable to listen at %s\n", addrstr); closesocket(newsocket); return NULL; } + else if (bindtries && isserver) + { + SockadrToNetadr(&qs, &adr); + NET_AdrToString(addrstr, sizeof(addrstr), &adr); + Con_Printf(CON_ERROR "Unable to bind to port %i, bound to %s instead\n", port, addrstr); + } if (ioctlsocket (newsocket, FIONBIO, &_true) == -1) Sys_Error ("UDP_OpenSocket: ioctl FIONBIO: %s", strerror(neterrno())); @@ -7260,7 +7272,7 @@ void SVNET_AddPort_f(void) { svs.sockets = FTENET_CreateCollection(true); #ifndef SERVERONLY - FTENET_AddToCollection(svs.sockets, "SVLoopback", STRINGIFY(PORT_QWSERVER), NA_LOOPBACK, NP_DGRAM); + FTENET_AddToCollection(svs.sockets, "SVLoopback", STRINGIFY(PORT_DEFAULTSERVER), NA_LOOPBACK, NP_DGRAM); #endif } @@ -7449,7 +7461,7 @@ void QDECL SV_Port_Callback(struct cvar_s *var, char *oldvalue) { FTENET_AddToCollection(svs.sockets, var->name, var->string, NA_IP, NP_DGRAM); } -cvar_t sv_port_ipv4 = CVARC("sv_port", STRINGIFY(PORT_QWSERVER), SV_Port_Callback); +cvar_t sv_port_ipv4 = CVARC("sv_port", STRINGIFY(PORT_DEFAULTSERVER), SV_Port_Callback); #endif #ifdef IPPROTO_IPV6 void QDECL SV_PortIPv6_Callback(struct cvar_s *var, char *oldvalue) @@ -7553,7 +7565,7 @@ void NET_InitServer(void) { svs.sockets = FTENET_CreateCollection(true); #ifndef SERVERONLY - FTENET_AddToCollection(svs.sockets, "SVLoopback", STRINGIFY(PORT_QWSERVER), NA_LOOPBACK, NP_DGRAM); + FTENET_AddToCollection(svs.sockets, "SVLoopback", STRINGIFY(PORT_DEFAULTSERVER), NA_LOOPBACK, NP_DGRAM); #endif } @@ -7591,7 +7603,7 @@ void NET_InitServer(void) #ifndef SERVERONLY svs.sockets = FTENET_CreateCollection(true); - FTENET_AddToCollection(svs.sockets, "SVLoopback", STRINGIFY(PORT_QWSERVER), NA_LOOPBACK, NP_DGRAM); + FTENET_AddToCollection(svs.sockets, "SVLoopback", STRINGIFY(PORT_DEFAULTSERVER), NA_LOOPBACK, NP_DGRAM); #endif } } diff --git a/engine/common/protocol.h b/engine/common/protocol.h index a5df0740b..43db506fd 100644 --- a/engine/common/protocol.h +++ b/engine/common/protocol.h @@ -123,6 +123,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //========================================= +//#define GAME_DEFAULTPORT XXXXX //rebranding allows selection of a different default port, which slightly reduces protocol conflicts. #define PORT_NQSERVER 26000 #define PORT_DPMASTER PORT_Q3MASTER #define PORT_QWCLIENT 27001 @@ -133,6 +134,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define PORT_Q3MASTER 27950 #define PORT_Q3SERVER 27960 +#ifdef GAME_DEFAULTPORT + #define PORT_DEFAULTSERVER GAME_DEFAULTPORT +#else + #define PORT_DEFAULTSERVER PORT_QWSERVER +#endif + //hexen2: 26900 //========================================= diff --git a/engine/server/pr_lua.c b/engine/server/pr_lua.c index 358bc91c4..6b85d4304 100644 --- a/engine/server/pr_lua.c +++ b/engine/server/pr_lua.c @@ -2235,26 +2235,26 @@ static int bi_lua_qtrue (lua_State *L) break; default: -// case LUA_TUSERDATA: +// case LUA_TUSERDATA: // case LUA_TTHREAD: // case LUA_TLIGHTUSERDATA: -// case LUA_TNONE: -// case LUA_TNIL: - lua_pushboolean(L, false); - break; - case LUA_TBOOLEAN: - lua_pushvalue(L, 1); - break; - - case LUA_TNUMBER: - lua_pushboolean(L, lua_tonumber(L, 1) != 0); - break; - - case LUA_TFUNCTION: //functions are always considered true. otherwise they're nil and not functions. - lua_pushboolean(L, true); - break; - case LUA_TTABLE: - //might be a vector or an entity. +// case LUA_TNONE: +// case LUA_TNIL: + lua_pushboolean(L, false); + break; + case LUA_TBOOLEAN: + lua_pushvalue(L, 1); + break; + + case LUA_TNUMBER: + lua_pushboolean(L, lua_tonumber(L, 1) != 0); + break; + + case LUA_TFUNCTION: //functions are always considered true. otherwise they're nil and not functions. + lua_pushboolean(L, true); + break; + case LUA_TTABLE: + //might be a vector or an entity. lua_getfield(L, 1, "entnum"); if (!lua_isnil(L, -1)) { //okay, so its a table with a valid entnum field. must be an entity. @@ -2264,10 +2264,10 @@ static int bi_lua_qtrue (lua_State *L) { //assume that its a vector. //note that this means that any table without x|y|z fields will be considered false. vec3_t v; - lua_readvector(L, 1, v); - lua_pushboolean(L, v[0] || v[1] || v[2]); - } - break; + lua_readvector(L, 1, v); + lua_pushboolean(L, v[0] || v[1] || v[2]); + } + break; } return 1; }