r1311 - in trunk/code: client q3_ui qcommon server ui

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Fri Apr 11 14:39:03 EDT 2008


Author: thilo
Date: 2008-04-11 14:39:03 -0400 (Fri, 11 Apr 2008)
New Revision: 1311

Modified:
   trunk/code/client/cl_main.c
   trunk/code/client/cl_ui.c
   trunk/code/client/client.h
   trunk/code/q3_ui/ui_servers2.c
   trunk/code/qcommon/net_chan.c
   trunk/code/qcommon/qcommon.h
   trunk/code/server/sv_main.c
   trunk/code/ui/ui_main.c
Log:
- Revamp in-game server browser: you can now scan for games on multiple master servers, while retaining compatibility with old QVMs.
- Make Master server reporting/server queries ipv6 capable.


Modified: trunk/code/client/cl_main.c
===================================================================
--- trunk/code/client/cl_main.c	2008-04-10 16:21:49 UTC (rev 1310)
+++ trunk/code/client/cl_main.c	2008-04-11 18:39:03 UTC (rev 1311)
@@ -36,7 +36,6 @@
 cvar_t	*cl_timeout;
 cvar_t	*cl_maxpackets;
 cvar_t	*cl_packetdup;
-cvar_t	*cl_master;
 cvar_t	*cl_timeNudge;
 cvar_t	*cl_showTimeDelta;
 cvar_t	*cl_freezeDemo;
@@ -1817,13 +1816,8 @@
 CL_InitServerInfo
 ===================
 */
-void CL_InitServerInfo( serverInfo_t *server, serverAddress_t *address ) {
-	server->adr.type  = NA_IP;
-	server->adr.ip[0] = address->ip[0];
-	server->adr.ip[1] = address->ip[1];
-	server->adr.ip[2] = address->ip[2];
-	server->adr.ip[3] = address->ip[3];
-	server->adr.port  = address->port;
+void CL_InitServerInfo( serverInfo_t *server, netadr_t *address ) {
+	server->adr = *address;
 	server->clients = 0;
 	server->hostName[0] = '\0';
 	server->mapName[0] = '\0';
@@ -1844,11 +1838,12 @@
 ===================
 */
 void CL_ServersResponsePacket( netadr_t from, msg_t *msg ) {
-	int				i, count, max, total;
-	serverAddress_t addresses[MAX_SERVERSPERPACKET];
+	int				i, count, total;
+	netadr_t addresses[MAX_SERVERSPERPACKET];
 	int				numservers;
 	byte*			buffptr;
 	byte*			buffend;
+	netadrtype_t		family;
 	
 	Com_Printf("CL_ServersResponsePacket\n");
 
@@ -1858,71 +1853,74 @@
 		cls.numGlobalServerAddresses = 0;
 	}
 
-	if (cls.nummplayerservers == -1) {
-		cls.nummplayerservers = 0;
-	}
-
 	// parse through server response string
 	numservers = 0;
 	buffptr    = msg->data;
 	buffend    = buffptr + msg->cursize;
-	while (buffptr+1 < buffend) {
+	while (buffptr+1 < buffend)
+	{
 		// advance to initial token
-		do {
-			if (*buffptr++ == '\\')
-				break;		
+		do
+		{
+			if (*buffptr == '\\')
+			{
+				family = NA_IP;
+				break;
+			}
+			else if(*buffptr == '/')
+			{
+				family = NA_IP6;
+				break;
+			}
+			
+			buffptr++;
 		}
 		while (buffptr < buffend);
 
-		if ( buffptr >= buffend - 6 ) {
-			break;
+		buffptr++;
+		
+		if(family == NA_IP)
+		{
+			if (buffend - buffptr < sizeof(addresses[numservers].ip) + sizeof(addresses[numservers].port) + sizeof("\\EOT") - 1)
+				break;
+			
+			for(i = 0; i < sizeof(addresses[numservers].ip); i++)
+				addresses[numservers].ip[i] = *buffptr++;
 		}
+		else
+		{
+			if (buffend - buffptr < sizeof(addresses[numservers].ip6) + sizeof(addresses[numservers].port) + sizeof("\\EOT") - 1)
+				break;
+			
+			for(i = 0; i < sizeof(addresses[numservers].ip6); i++)
+				addresses[numservers].ip6[i] = *buffptr++;
+		}
 
-		// parse out ip
-		addresses[numservers].ip[0] = *buffptr++;
-		addresses[numservers].ip[1] = *buffptr++;
-		addresses[numservers].ip[2] = *buffptr++;
-		addresses[numservers].ip[3] = *buffptr++;
+		addresses[numservers].type = family;
 
 		// parse out port
-		addresses[numservers].port = (*buffptr++)<<8;
+		addresses[numservers].port = (*buffptr++) << 8;
 		addresses[numservers].port += *buffptr++;
 		addresses[numservers].port = BigShort( addresses[numservers].port );
 
 		// syntax check
-		if (*buffptr != '\\') {
+		if (*buffptr != '\\' && *buffptr != '/')
 			break;
-		}
-
-		Com_DPrintf( "server: %d ip: %d.%d.%d.%d:%d\n",numservers,
-				addresses[numservers].ip[0],
-				addresses[numservers].ip[1],
-				addresses[numservers].ip[2],
-				addresses[numservers].ip[3],
-				addresses[numservers].port );
-
+	
 		numservers++;
-		if (numservers >= MAX_SERVERSPERPACKET) {
+		if (numservers >= MAX_SERVERSPERPACKET)
 			break;
-		}
 
 		// parse out EOT
-		if (buffptr[1] == 'E' && buffptr[2] == 'O' && buffptr[3] == 'T') {
+		if (buffptr[1] == 'E' && buffptr[2] == 'O' && buffptr[3] == 'T')
 			break;
-		}
 	}
 
-	if (cls.masterNum == 0) {
-		count = cls.numglobalservers;
-		max = MAX_GLOBAL_SERVERS;
-	} else {
-		count = cls.nummplayerservers;
-		max = MAX_OTHER_SERVERS;
-	}
+	count = cls.numglobalservers;
 
-	for (i = 0; i < numservers && count < max; i++) {
+	for (i = 0; i < numservers && count < MAX_GLOBAL_SERVERS; i++) {
 		// build net address
-		serverInfo_t *server = (cls.masterNum == 0) ? &cls.globalServers[count] : &cls.mplayerServers[count];
+		serverInfo_t *server = &cls.globalServers[count];
 
 		CL_InitServerInfo( server, &addresses[i] );
 		// advance to next slot
@@ -1930,29 +1928,18 @@
 	}
 
 	// if getting the global list
-	if (cls.masterNum == 0) {
-		if ( cls.numGlobalServerAddresses < MAX_GLOBAL_SERVERS ) {
-			// if we couldn't store the servers in the main list anymore
-			for (; i < numservers && count >= max; i++) {
-				serverAddress_t *addr;
-				// just store the addresses in an additional list
-				addr = &cls.globalServerAddresses[cls.numGlobalServerAddresses++];
-				addr->ip[0] = addresses[i].ip[0];
-				addr->ip[1] = addresses[i].ip[1];
-				addr->ip[2] = addresses[i].ip[2];
-				addr->ip[3] = addresses[i].ip[3];
-				addr->port  = addresses[i].port;
-			}
+	if ( count >= MAX_GLOBAL_SERVERS && cls.numGlobalServerAddresses < MAX_GLOBAL_SERVERS )
+	{
+		// if we couldn't store the servers in the main list anymore
+		for (; i < numservers && cls.numGlobalServerAddresses < MAX_GLOBAL_SERVERS; i++)
+		{
+			// just store the addresses in an additional list
+			cls.globalServerAddresses[cls.numGlobalServerAddresses++] = addresses[i];
 		}
 	}
 
-	if (cls.masterNum == 0) {
-		cls.numglobalservers = count;
-		total = count + cls.numGlobalServerAddresses;
-	} else {
-		cls.nummplayerservers = count;
-		total = count;
-	}
+	cls.numglobalservers = count;
+	total = count + cls.numGlobalServerAddresses;
 
 	Com_Printf("%d servers parsed (total %d)\n", numservers, total);
 }
@@ -2672,7 +2659,6 @@
 
 	cl_timeout = Cvar_Get ("cl_timeout", "200", 0);
 
-	cl_master = Cvar_Get ("cl_master", MASTER_SERVER_NAME, CVAR_ARCHIVE);
 	cl_timeNudge = Cvar_Get ("cl_timeNudge", "0", CVAR_TEMP );
 	cl_shownet = Cvar_Get ("cl_shownet", "0", CVAR_TEMP );
 	cl_showSend = Cvar_Get ("cl_showSend", "0", CVAR_TEMP );
@@ -2898,12 +2884,6 @@
 		}
 	}
 
-	for (i = 0; i < MAX_OTHER_SERVERS; i++) {
-		if (NET_CompareAdr(from, cls.mplayerServers[i].adr)) {
-			CL_SetServerInfo(&cls.mplayerServers[i], info, ping);
-		}
-	}
-
 	for (i = 0; i < MAX_GLOBAL_SERVERS; i++) {
 		if (NET_CompareAdr(from, cls.globalServers[i].adr)) {
 			CL_SetServerInfo(&cls.globalServers[i], info, ping);
@@ -3260,44 +3240,50 @@
 */
 void CL_GlobalServers_f( void ) {
 	netadr_t	to;
-	int			i;
-	int			count;
-	char		*buffptr;
-	char		command[1024];
+	int			count, i, masterNum;
+	char		command[1024], *masteraddress;
 	
-	if ( Cmd_Argc() < 3) {
-		Com_Printf( "usage: globalservers <master# 0-1> <protocol> [keywords]\n");
+	if ((count = Cmd_Argc()) < 3 || (masterNum = atoi(Cmd_Argv(1))) < 0 || masterNum > 4)
+	{
+		Com_Printf( "usage: globalservers <master# 0-4> <protocol> [keywords]\n");
 		return;	
 	}
 
-	cls.masterNum = atoi( Cmd_Argv(1) );
+	sprintf(command, "sv_master%d", masterNum + 1);
+	masteraddress = Cvar_VariableString(command);
+	
+	if(!*masteraddress)
+	{
+		Com_Printf( "CL_GlobalServers_f: Error: No master server address given.\n");
+		return;	
+	}
 
-	Com_Printf( "Requesting servers from the master...\n");
-
 	// reset the list, waiting for response
 	// -1 is used to distinguish a "no response"
 
-	NET_StringToAdr( cl_master->string, &to, NA_IP );
-
-	if( cls.masterNum == 1 ) {
-		cls.nummplayerservers = -1;
-		cls.pingUpdateSource = AS_MPLAYER;
+	i = NET_StringToAdr(masteraddress, &to, NA_UNSPEC);
+	
+	if(!i)
+	{
+		Com_Printf( "CL_GlobalServers_f: Error: could not resolve address of master %s\n", masteraddress);
+		return;	
 	}
-	else {
-		cls.numglobalservers = -1;
-		cls.pingUpdateSource = AS_GLOBAL;
-	}
-	to.type = NA_IP;
-	to.port = BigShort(PORT_MASTER);
+	else if(i == 2)
+		to.port = BigShort(PORT_MASTER);
 
-	sprintf( command, "getservers %s", Cmd_Argv(2) );
+	Com_Printf("Requesting servers from master %s...\n", masteraddress);
 
-	// tack on keywords
-	buffptr = command + strlen( command );
-	count   = Cmd_Argc();
-	for (i=3; i<count; i++)
-		buffptr += sprintf( buffptr, " %s", Cmd_Argv(i) );
+	cls.numglobalservers = -1;
+	cls.pingUpdateSource = AS_GLOBAL;
 
+	Com_sprintf( command, sizeof(command), "getservers %s", Cmd_Argv(2) );
+
+	for (i=3; i < count; i++)
+	{
+		Q_strcat(command, sizeof(command), " ");
+		Q_strcat(command, sizeof(command), Cmd_Argv(i));
+	}
+
 	NET_OutOfBandPrint( NS_SERVER, to, "%s", command );
 }
 
@@ -3549,10 +3535,6 @@
 				server = &cls.localServers[0];
 				max = cls.numlocalservers;
 			break;
-			case AS_MPLAYER :
-				server = &cls.mplayerServers[0];
-				max = cls.nummplayerservers;
-			break;
 			case AS_GLOBAL :
 				server = &cls.globalServers[0];
 				max = cls.numglobalservers;
@@ -3561,6 +3543,8 @@
 				server = &cls.favoriteServers[0];
 				max = cls.numfavoriteservers;
 			break;
+			default:
+				return qfalse;
 		}
 		for (i = 0; i < max; i++) {
 			if (server[i].visible) {

Modified: trunk/code/client/cl_ui.c
===================================================================
--- trunk/code/client/cl_ui.c	2008-04-10 16:21:49 UTC (rev 1310)
+++ trunk/code/client/cl_ui.c	2008-04-11 18:39:03 UTC (rev 1311)
@@ -50,19 +50,17 @@
 void LAN_LoadCachedServers( void ) {
 	int size;
 	fileHandle_t fileIn;
-	cls.numglobalservers = cls.nummplayerservers = cls.numfavoriteservers = 0;
+	cls.numglobalservers = cls.numfavoriteservers = 0;
 	cls.numGlobalServerAddresses = 0;
 	if (FS_SV_FOpenFileRead("servercache.dat", &fileIn)) {
 		FS_Read(&cls.numglobalservers, sizeof(int), fileIn);
-		FS_Read(&cls.nummplayerservers, sizeof(int), fileIn);
 		FS_Read(&cls.numfavoriteservers, sizeof(int), fileIn);
 		FS_Read(&size, sizeof(int), fileIn);
-		if (size == sizeof(cls.globalServers) + sizeof(cls.favoriteServers) + sizeof(cls.mplayerServers)) {
+		if (size == sizeof(cls.globalServers) + sizeof(cls.favoriteServers)) {
 			FS_Read(&cls.globalServers, sizeof(cls.globalServers), fileIn);
-			FS_Read(&cls.mplayerServers, sizeof(cls.mplayerServers), fileIn);
 			FS_Read(&cls.favoriteServers, sizeof(cls.favoriteServers), fileIn);
 		} else {
-			cls.numglobalservers = cls.nummplayerservers = cls.numfavoriteservers = 0;
+			cls.numglobalservers = cls.numfavoriteservers = 0;
 			cls.numGlobalServerAddresses = 0;
 		}
 		FS_FCloseFile(fileIn);
@@ -78,12 +76,10 @@
 	int size;
 	fileHandle_t fileOut = FS_SV_FOpenFileWrite("servercache.dat");
 	FS_Write(&cls.numglobalservers, sizeof(int), fileOut);
-	FS_Write(&cls.nummplayerservers, sizeof(int), fileOut);
 	FS_Write(&cls.numfavoriteservers, sizeof(int), fileOut);
-	size = sizeof(cls.globalServers) + sizeof(cls.favoriteServers) + sizeof(cls.mplayerServers);
+	size = sizeof(cls.globalServers) + sizeof(cls.favoriteServers);
 	FS_Write(&size, sizeof(int), fileOut);
 	FS_Write(&cls.globalServers, sizeof(cls.globalServers), fileOut);
-	FS_Write(&cls.mplayerServers, sizeof(cls.mplayerServers), fileOut);
 	FS_Write(&cls.favoriteServers, sizeof(cls.favoriteServers), fileOut);
 	FS_FCloseFile(fileOut);
 }
@@ -104,10 +100,7 @@
 			servers = &cls.localServers[0];
 			count = MAX_OTHER_SERVERS;
 			break;
-		case AS_MPLAYER :
-			servers = &cls.mplayerServers[0];
-			count = MAX_OTHER_SERVERS;
-			break;
+		case AS_MPLAYER:
 		case AS_GLOBAL :
 			servers = &cls.globalServers[0];
 			count = MAX_GLOBAL_SERVERS;
@@ -141,10 +134,7 @@
 			count = &cls.numlocalservers;
 			servers = &cls.localServers[0];
 			break;
-		case AS_MPLAYER :
-			count = &cls.nummplayerservers;
-			servers = &cls.mplayerServers[0];
-			break;
+		case AS_MPLAYER:
 		case AS_GLOBAL :
 			max = MAX_GLOBAL_SERVERS;
 			count = &cls.numglobalservers;
@@ -188,10 +178,7 @@
 			count = &cls.numlocalservers;
 			servers = &cls.localServers[0];
 			break;
-		case AS_MPLAYER :
-			count = &cls.nummplayerservers;
-			servers = &cls.mplayerServers[0];
-			break;
+		case AS_MPLAYER:
 		case AS_GLOBAL :
 			count = &cls.numglobalservers;
 			servers = &cls.globalServers[0];
@@ -229,9 +216,7 @@
 		case AS_LOCAL :
 			return cls.numlocalservers;
 			break;
-		case AS_MPLAYER :
-			return cls.nummplayerservers;
-			break;
+		case AS_MPLAYER:
 		case AS_GLOBAL :
 			return cls.numglobalservers;
 			break;
@@ -255,12 +240,7 @@
 				return;
 			}
 			break;
-		case AS_MPLAYER :
-			if (n >= 0 && n < MAX_OTHER_SERVERS) {
-				Q_strncpyz(buf, NET_AdrToStringwPort( cls.mplayerServers[n].adr) , buflen );
-				return;
-			}
-			break;
+		case AS_MPLAYER:
 		case AS_GLOBAL :
 			if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
 				Q_strncpyz(buf, NET_AdrToStringwPort( cls.globalServers[n].adr) , buflen );
@@ -292,11 +272,7 @@
 				server = &cls.localServers[n];
 			}
 			break;
-		case AS_MPLAYER :
-			if (n >= 0 && n < MAX_OTHER_SERVERS) {
-				server = &cls.mplayerServers[n];
-			}
-			break;
+		case AS_MPLAYER:
 		case AS_GLOBAL :
 			if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
 				server = &cls.globalServers[n];
@@ -343,11 +319,7 @@
 				server = &cls.localServers[n];
 			}
 			break;
-		case AS_MPLAYER :
-			if (n >= 0 && n < MAX_OTHER_SERVERS) {
-				server = &cls.mplayerServers[n];
-			}
-			break;
+		case AS_MPLAYER:
 		case AS_GLOBAL :
 			if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
 				server = &cls.globalServers[n];
@@ -377,11 +349,7 @@
 				return &cls.localServers[n];
 			}
 			break;
-		case AS_MPLAYER :
-			if (n >= 0 && n < MAX_OTHER_SERVERS) {
-				return &cls.mplayerServers[n];
-			}
-			break;
+		case AS_MPLAYER:
 		case AS_GLOBAL :
 			if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
 				return &cls.globalServers[n];
@@ -514,9 +482,7 @@
 			case AS_LOCAL :
 				server = &cls.localServers[0];
 				break;
-			case AS_MPLAYER :
-				server = &cls.mplayerServers[0];
-				break;
+			case AS_MPLAYER:
 			case AS_GLOBAL :
 				server = &cls.globalServers[0];
 				count = MAX_GLOBAL_SERVERS;
@@ -538,11 +504,7 @@
 					cls.localServers[n].visible = visible;
 				}
 				break;
-			case AS_MPLAYER :
-				if (n >= 0 && n < MAX_OTHER_SERVERS) {
-					cls.mplayerServers[n].visible = visible;
-				}
-				break;
+			case AS_MPLAYER:
 			case AS_GLOBAL :
 				if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
 					cls.globalServers[n].visible = visible;
@@ -570,11 +532,7 @@
 				return cls.localServers[n].visible;
 			}
 			break;
-		case AS_MPLAYER :
-			if (n >= 0 && n < MAX_OTHER_SERVERS) {
-				return cls.mplayerServers[n].visible;
-			}
-			break;
+		case AS_MPLAYER:
 		case AS_GLOBAL :
 			if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
 				return cls.globalServers[n].visible;

Modified: trunk/code/client/client.h
===================================================================
--- trunk/code/client/client.h	2008-04-10 16:21:49 UTC (rev 1310)
+++ trunk/code/client/client.h	2008-04-11 18:39:03 UTC (rev 1311)
@@ -264,11 +264,6 @@
 } serverInfo_t;
 
 typedef struct {
-	byte	ip[4];
-	unsigned short	port;
-} serverAddress_t;
-
-typedef struct {
 	connstate_t	state;				// connection status
 
 	qboolean	cddialog;			// bring up the cd needed dialog next frame
@@ -295,18 +290,13 @@
 	serverInfo_t  globalServers[MAX_GLOBAL_SERVERS];
 	// additional global servers
 	int			numGlobalServerAddresses;
-	serverAddress_t		globalServerAddresses[MAX_GLOBAL_SERVERS];
+	netadr_t		globalServerAddresses[MAX_GLOBAL_SERVERS];
 
 	int			numfavoriteservers;
 	serverInfo_t	favoriteServers[MAX_OTHER_SERVERS];
 
-	int			nummplayerservers;
-	serverInfo_t	mplayerServers[MAX_OTHER_SERVERS];
-
 	int pingUpdateSource;		// source currently pinging or updating
 
-	int masterNum;
-
 	// update server info
 	netadr_t	updateServer;
 	char		updateChallenge[MAX_TOKEN_CHARS];

Modified: trunk/code/q3_ui/ui_servers2.c
===================================================================
--- trunk/code/q3_ui/ui_servers2.c	2008-04-10 16:21:49 UTC (rev 1310)
+++ trunk/code/q3_ui/ui_servers2.c	2008-04-11 18:39:03 UTC (rev 1311)
@@ -80,10 +80,13 @@
 #define GR_LOGO				30
 #define GR_LETTERS			31
 
-#define AS_LOCAL			0
-#define AS_MPLAYER			1
-#define AS_GLOBAL			2
-#define AS_FAVORITES		3
+#define UIAS_LOCAL			0
+#define UIAS_GLOBAL1			1
+#define UIAS_GLOBAL2			2
+#define UIAS_GLOBAL3			3
+#define UIAS_GLOBAL4			4
+#define UIAS_GLOBAL5			5
+#define UIAS_FAVORITES			6
 
 #define SORT_HOST			0
 #define SORT_MAP			1
@@ -99,7 +102,11 @@
 
 static const char *master_items[] = {
 	"Local",
-	"Internet",
+	"Internet1",
+	"Internet2",
+	"Internet3",
+	"Internet4",
+	"Internet5",
 	"Favorites",
 	NULL
 };
@@ -241,8 +248,6 @@
 static int				g_numlocalservers;
 static servernode_t		g_favoriteserverlist[MAX_FAVORITESERVERS];
 static int				g_numfavoriteservers;
-static servernode_t		g_mplayerserverlist[MAX_GLOBALSERVERS];
-static int				g_nummplayerservers;
 static int				g_servertype;
 static int				g_gametype;
 static int				g_sortkey;
@@ -403,7 +408,7 @@
 			g_arenaservers.punkbuster.generic.flags &= ~QMF_GRAYED;
 
 			// update status bar
-			if( g_servertype == AS_GLOBAL || g_servertype == AS_MPLAYER ) {
+			if( g_servertype >= UIAS_GLOBAL1 && g_servertype <= UIAS_GLOBAL5 ) {
 				g_arenaservers.statusbar.string = quake3worldMessage;
 			}
 			else {
@@ -438,7 +443,7 @@
 			}
 
 			// update status bar
-			if( g_servertype == AS_GLOBAL || g_servertype == AS_MPLAYER ) {
+			if( g_servertype >= UIAS_GLOBAL1 && g_servertype <= UIAS_GLOBAL5 ) {
 				g_arenaservers.statusbar.string = quake3worldMessage;
 			}
 			else {
@@ -618,7 +623,7 @@
 	int				i;
 
 
-	if ((pingtime >= ArenaServers_MaxPing()) && (g_servertype != AS_FAVORITES))
+	if ((pingtime >= ArenaServers_MaxPing()) && (g_servertype != UIAS_FAVORITES))
 	{
 		// slow global or local servers do not get entered
 		return;
@@ -809,7 +814,7 @@
 
 	g_arenaservers.refreshservers = qfalse;
 
-	if (g_servertype == AS_FAVORITES)
+	if (g_servertype == UIAS_FAVORITES)
 	{
 		// nonresponsive favorites must be shown
 		ArenaServers_InsertFavorites();
@@ -845,8 +850,8 @@
 
 	if (uis.realtime < g_arenaservers.refreshtime)
 	{
-	  if (g_servertype != AS_FAVORITES) {
-			if (g_servertype == AS_LOCAL) {
+	  if (g_servertype != UIAS_FAVORITES) {
+			if (g_servertype == UIAS_LOCAL) {
 				if (!trap_LAN_GetServerCount(g_servertype)) {
 					return;
 				}
@@ -920,7 +925,7 @@
 
 	// get results of servers query
 	// counts can increase as servers respond
-	if (g_servertype == AS_FAVORITES) {
+	if (g_servertype == UIAS_FAVORITES) {
 	  g_arenaservers.numqueriedservers = g_arenaservers.numfavoriteaddresses;
 	} else {
 	  g_arenaservers.numqueriedservers = trap_LAN_GetServerCount(g_servertype);
@@ -950,7 +955,7 @@
 
 		// get an address to ping
 
-		if (g_servertype == AS_FAVORITES) {
+		if (g_servertype == UIAS_FAVORITES) {
 		  strcpy( adrstr, g_arenaservers.favoriteaddresses[g_arenaservers.currentping] ); 		
 		} else {
 		  trap_LAN_GetServerAddressString(g_servertype, g_arenaservers.currentping, adrstr, MAX_ADDRESSLENGTH );
@@ -1007,19 +1012,12 @@
 	// place menu in zeroed state
 	ArenaServers_UpdateMenu();
 
-	if( g_servertype == AS_LOCAL ) {
+	if( g_servertype == UIAS_LOCAL ) {
 		trap_Cmd_ExecuteText( EXEC_APPEND, "localservers\n" );
 		return;
 	}
 
-	if( g_servertype == AS_GLOBAL || g_servertype == AS_MPLAYER ) {
-		if( g_servertype == AS_GLOBAL ) {
-			i = 0;
-		}
-		else {
-			i = 1;
-		}
-
+	if( g_servertype >= UIAS_GLOBAL1 && g_servertype <= UIAS_GLOBAL5 ) {
 		switch( g_arenaservers.gametype.curvalue ) {
 		default:
 		case GAMES_ALL:
@@ -1055,10 +1053,10 @@
 		protocol[0] = '\0';
 		trap_Cvar_VariableStringBuffer( "debug_protocol", protocol, sizeof(protocol) );
 		if (strlen(protocol)) {
-			trap_Cmd_ExecuteText( EXEC_APPEND, va( "globalservers %d %s%s\n", i, protocol, myargs ));
+			trap_Cmd_ExecuteText( EXEC_APPEND, va( "globalservers %d %s%s\n", g_servertype - 1, protocol, myargs ));
 		}
 		else {
-			trap_Cmd_ExecuteText( EXEC_APPEND, va( "globalservers %d %d%s\n", i, (int)trap_Cvar_VariableValue( "protocol" ), myargs ) );
+			trap_Cmd_ExecuteText( EXEC_APPEND, va( "globalservers %d %d%s\n", g_servertype - 1, (int)trap_Cvar_VariableValue( "protocol" ), myargs ) );
 		}
 	}
 }
@@ -1101,43 +1099,52 @@
 ArenaServers_SetType
 =================
 */
-void ArenaServers_SetType( int type )
+int ArenaServers_SetType( int type )
 {
-	if (g_servertype == type)
-		return;
+	if(type >= UIAS_GLOBAL1 && type <= UIAS_GLOBAL5)
+	{
+		char masterstr[2], cvarname[sizeof("sv_master1")];
+		
+		while(type <= UIAS_GLOBAL5)
+		{
+			Com_sprintf(cvarname, sizeof(cvarname), "sv_master%d", type);
+			trap_Cvar_VariableStringBuffer(cvarname, masterstr, sizeof(masterstr));
+			if(*masterstr)
+				break;
+			
+			type++;
+		}
+	}
 
 	g_servertype = type;
 
 	switch( type ) {
 	default:
-	case AS_LOCAL:
+	case UIAS_LOCAL:
 		g_arenaservers.remove.generic.flags |= (QMF_INACTIVE|QMF_HIDDEN);
 		g_arenaservers.serverlist = g_localserverlist;
 		g_arenaservers.numservers = &g_numlocalservers;
 		g_arenaservers.maxservers = MAX_LOCALSERVERS;
 		break;
 
-	case AS_GLOBAL:
+	case UIAS_GLOBAL1:
+	case UIAS_GLOBAL2:
+	case UIAS_GLOBAL3:
+	case UIAS_GLOBAL4:
+	case UIAS_GLOBAL5:
 		g_arenaservers.remove.generic.flags |= (QMF_INACTIVE|QMF_HIDDEN);
 		g_arenaservers.serverlist = g_globalserverlist;
 		g_arenaservers.numservers = &g_numglobalservers;
 		g_arenaservers.maxservers = MAX_GLOBALSERVERS;
 		break;
 
-	case AS_FAVORITES:
+	case UIAS_FAVORITES:
 		g_arenaservers.remove.generic.flags &= ~(QMF_INACTIVE|QMF_HIDDEN);
 		g_arenaservers.serverlist = g_favoriteserverlist;
 		g_arenaservers.numservers = &g_numfavoriteservers;
 		g_arenaservers.maxservers = MAX_FAVORITESERVERS;
 		break;
 
-	case AS_MPLAYER:
-		g_arenaservers.remove.generic.flags |= (QMF_INACTIVE|QMF_HIDDEN);
-		g_arenaservers.serverlist = g_mplayerserverlist;
-		g_arenaservers.numservers = &g_nummplayerservers;
-		g_arenaservers.maxservers = MAX_GLOBALSERVERS;
-		break;
-		
 	}
 
 	if( !*g_arenaservers.numservers ) {
@@ -1150,6 +1157,8 @@
 		ArenaServers_UpdateMenu();
 	}
 	strcpy(g_arenaservers.status.string,"hit refresh to update");
+	
+	return type;
 }
 
 /*
@@ -1181,7 +1190,6 @@
 */
 static void ArenaServers_Event( void* ptr, int event ) {
 	int		id;
-	int value;
 
 	id = ((menucommon_s*)ptr)->id;
 
@@ -1191,13 +1199,8 @@
 
 	switch( id ) {
 	case ID_MASTER:
-		value = g_arenaservers.master.curvalue;
-		if (value >= 1)
-		{
-			value++;
-		}
-		trap_Cvar_SetValue( "ui_browserMaster", value );
-		ArenaServers_SetType( value );
+		g_arenaservers.master.curvalue = ArenaServers_SetType(g_arenaservers.master.curvalue);
+		trap_Cvar_SetValue( "ui_browserMaster", g_arenaservers.master.curvalue);
 		break;
 
 	case ID_GAMETYPE:
@@ -1304,7 +1307,7 @@
 		return menu_move_sound;
 	}
 
-	if( ( key == K_DEL || key == K_KP_DEL ) && ( g_servertype == AS_FAVORITES ) &&
+	if( ( key == K_DEL || key == K_KP_DEL ) && ( g_servertype == UIAS_FAVORITES ) &&
 		( Menu_ItemAtCursor( &g_arenaservers.menu) == &g_arenaservers.list ) ) {
 		ArenaServers_Remove();
 		ArenaServers_UpdateMenu();
@@ -1328,7 +1331,6 @@
 */
 static void ArenaServers_MenuInit( void ) {
 	int			i;
-	int			type;
 	int			y;
 	int			value;
 	static char	statusbuffer[MAX_STATUSLENGTH];
@@ -1600,9 +1602,7 @@
 	g_arenaservers.punkbuster.curvalue = Com_Clamp( 0, 1, trap_Cvar_VariableValue( "cl_punkbuster" ) );
 
 	// force to initial state and refresh
-	type = g_servertype;
-	g_servertype = -1;
-	ArenaServers_SetType( type );
+	g_arenaservers.master.curvalue = g_servertype = ArenaServers_SetType(g_servertype);
 
 	trap_Cvar_Register(NULL, "debug_protocol", "", 0 );
 }

Modified: trunk/code/qcommon/net_chan.c
===================================================================
--- trunk/code/qcommon/net_chan.c	2008-04-10 16:21:49 UTC (rev 1310)
+++ trunk/code/qcommon/net_chan.c	2008-04-11 18:39:03 UTC (rev 1311)
@@ -673,17 +673,19 @@
 NET_StringToAdr
 
 Traps "localhost" for loopback, passes everything else to system
+return 0 on address not found, 1 on address found with port, 2 on address found without port.
 =============
 */
-qboolean	NET_StringToAdr( const char *s, netadr_t *a, netadrtype_t family ) {
-	qboolean	r;
+int NET_StringToAdr( const char *s, netadr_t *a, netadrtype_t family )
+{
 	char	base[MAX_STRING_CHARS], *search;
 	char	*port = NULL;
 
 	if (!strcmp (s, "localhost")) {
 		Com_Memset (a, 0, sizeof(*a));
 		a->type = NA_LOOPBACK;
-		return qtrue;
+// as NA_LOOPBACK doesn't require ports report port was given.
+		return 1;
 	}
 
 	Q_strncpyz( base, s, sizeof( base ) );
@@ -719,19 +721,20 @@
 		search = base;
 	}
 
-	r = Sys_StringToAdr( search, a, family );
-
-	if ( !r ) {
+	if(!Sys_StringToAdr(search, a, family))
+	{
 		a->type = NA_BAD;
-		return qfalse;
+		return 0;
 	}
 
-	if ( port ) {
-		a->port = BigShort( (short)atoi( port ) );
-	} else {
-		a->port = BigShort( PORT_SERVER );
+	if(port)
+	{
+		a->port = BigShort((short) atoi(port));
+		return 1;
 	}
-
-	return qtrue;
+	else
+	{
+		a->port = BigShort(PORT_SERVER);
+		return 2;
+	}
 }
-

Modified: trunk/code/qcommon/qcommon.h
===================================================================
--- trunk/code/qcommon/qcommon.h	2008-04-10 16:21:49 UTC (rev 1310)
+++ trunk/code/qcommon/qcommon.h	2008-04-11 18:39:03 UTC (rev 1311)
@@ -171,7 +171,7 @@
 qboolean	NET_IsLocalAddress (netadr_t adr);
 const char	*NET_AdrToString (netadr_t a);
 const char      *NET_AdrToStringwPort (netadr_t a);
-qboolean	NET_StringToAdr ( const char *s, netadr_t *a, netadrtype_t family);
+int		NET_StringToAdr ( const char *s, netadr_t *a, netadrtype_t family);
 qboolean	NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message);
 void		NET_JoinMulticast6(void);
 void		NET_LeaveMulticast6(void);

Modified: trunk/code/server/sv_main.c
===================================================================
--- trunk/code/server/sv_main.c	2008-04-10 16:21:49 UTC (rev 1310)
+++ trunk/code/server/sv_main.c	2008-04-11 18:39:03 UTC (rev 1311)
@@ -252,7 +252,7 @@
 			sv_master[i]->modified = qfalse;
 	
 			Com_Printf( "Resolving %s\n", sv_master[i]->string );
-			if ( !NET_StringToAdr( sv_master[i]->string, &adr[i], NA_IP ) ) {
+			if ( !NET_StringToAdr( sv_master[i]->string, &adr[i], NA_UNSPEC ) ) {
 				// if the address failed to resolve, clear it
 				// so we don't take repeated dns hits
 				Com_Printf( "Couldn't resolve address: %s\n", sv_master[i]->string );
@@ -263,9 +263,7 @@
 			if ( !strchr( sv_master[i]->string, ':' ) ) {
 				adr[i].port = BigShort( PORT_MASTER );
 			}
-			Com_Printf( "%s resolved to %i.%i.%i.%i:%i\n", sv_master[i]->string,
-				adr[i].ip[0], adr[i].ip[1], adr[i].ip[2], adr[i].ip[3],
-				BigShort( adr[i].port ) );
+			Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToStringwPort(adr[i]));
 		}
 
 

Modified: trunk/code/ui/ui_main.c
===================================================================
--- trunk/code/ui/ui_main.c	2008-04-10 16:21:49 UTC (rev 1310)
+++ trunk/code/ui/ui_main.c	2008-04-11 18:39:03 UTC (rev 1311)
@@ -2495,12 +2495,8 @@
 		
 		if (key == K_MOUSE2) {
 			ui_netSource.integer--;
-			if (ui_netSource.integer == AS_MPLAYER)
-				ui_netSource.integer--;
 		} else {
 			ui_netSource.integer++;
-			if (ui_netSource.integer == AS_MPLAYER)
-				ui_netSource.integer++;
 		}
     
 		if (ui_netSource.integer >= numNetSources) {
@@ -5972,20 +5968,14 @@
 	}
 
 	uiInfo.serverStatus.refreshtime = uiInfo.uiDC.realTime + 5000;
-	if( ui_netSource.integer == AS_GLOBAL || ui_netSource.integer == AS_MPLAYER ) {
-		if( ui_netSource.integer == AS_GLOBAL ) {
-			i = 0;
-		}
-		else {
-			i = 1;
-		}
+	if( ui_netSource.integer == AS_GLOBAL ) {
 
 		ptr = UI_Cvar_VariableString("debug_protocol");
 		if (strlen(ptr)) {
-			trap_Cmd_ExecuteText( EXEC_NOW, va( "globalservers %d %s full empty\n", i, ptr));
+			trap_Cmd_ExecuteText( EXEC_NOW, va( "globalservers 0 %s full empty\n", ptr));
 		}
 		else {
-			trap_Cmd_ExecuteText( EXEC_NOW, va( "globalservers %d %d full empty\n", i, (int)trap_Cvar_VariableValue( "protocol" ) ) );
+			trap_Cmd_ExecuteText( EXEC_NOW, va( "globalservers 0 %d full empty\n", (int)trap_Cvar_VariableValue( "protocol" ) ) );
 		}
 	}
 }




More information about the quake3-commits mailing list