- 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.
This commit is contained in:
Thilo Schulz 2008-04-11 18:39:03 +00:00
parent 75cfef1afb
commit 9a8cc99a93
8 changed files with 182 additions and 259 deletions

View file

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

View file

@ -50,19 +50,17 @@ LAN_LoadCachedServers
void LAN_LoadCachedServers( void ) { void LAN_LoadCachedServers( void ) {
int size; int size;
fileHandle_t fileIn; fileHandle_t fileIn;
cls.numglobalservers = cls.nummplayerservers = cls.numfavoriteservers = 0; cls.numglobalservers = cls.numfavoriteservers = 0;
cls.numGlobalServerAddresses = 0; cls.numGlobalServerAddresses = 0;
if (FS_SV_FOpenFileRead("servercache.dat", &fileIn)) { if (FS_SV_FOpenFileRead("servercache.dat", &fileIn)) {
FS_Read(&cls.numglobalservers, sizeof(int), fileIn); FS_Read(&cls.numglobalservers, sizeof(int), fileIn);
FS_Read(&cls.nummplayerservers, sizeof(int), fileIn);
FS_Read(&cls.numfavoriteservers, sizeof(int), fileIn); FS_Read(&cls.numfavoriteservers, sizeof(int), fileIn);
FS_Read(&size, 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.globalServers, sizeof(cls.globalServers), fileIn);
FS_Read(&cls.mplayerServers, sizeof(cls.mplayerServers), fileIn);
FS_Read(&cls.favoriteServers, sizeof(cls.favoriteServers), fileIn); FS_Read(&cls.favoriteServers, sizeof(cls.favoriteServers), fileIn);
} else { } else {
cls.numglobalservers = cls.nummplayerservers = cls.numfavoriteservers = 0; cls.numglobalservers = cls.numfavoriteservers = 0;
cls.numGlobalServerAddresses = 0; cls.numGlobalServerAddresses = 0;
} }
FS_FCloseFile(fileIn); FS_FCloseFile(fileIn);
@ -78,12 +76,10 @@ void LAN_SaveServersToCache( void ) {
int size; int size;
fileHandle_t fileOut = FS_SV_FOpenFileWrite("servercache.dat"); fileHandle_t fileOut = FS_SV_FOpenFileWrite("servercache.dat");
FS_Write(&cls.numglobalservers, sizeof(int), fileOut); FS_Write(&cls.numglobalservers, sizeof(int), fileOut);
FS_Write(&cls.nummplayerservers, sizeof(int), fileOut);
FS_Write(&cls.numfavoriteservers, 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(&size, sizeof(int), fileOut);
FS_Write(&cls.globalServers, sizeof(cls.globalServers), 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_Write(&cls.favoriteServers, sizeof(cls.favoriteServers), fileOut);
FS_FCloseFile(fileOut); FS_FCloseFile(fileOut);
} }
@ -104,10 +100,7 @@ static void LAN_ResetPings(int source) {
servers = &cls.localServers[0]; servers = &cls.localServers[0];
count = MAX_OTHER_SERVERS; count = MAX_OTHER_SERVERS;
break; break;
case AS_MPLAYER : case AS_MPLAYER:
servers = &cls.mplayerServers[0];
count = MAX_OTHER_SERVERS;
break;
case AS_GLOBAL : case AS_GLOBAL :
servers = &cls.globalServers[0]; servers = &cls.globalServers[0];
count = MAX_GLOBAL_SERVERS; count = MAX_GLOBAL_SERVERS;
@ -141,10 +134,7 @@ static int LAN_AddServer(int source, const char *name, const char *address) {
count = &cls.numlocalservers; count = &cls.numlocalservers;
servers = &cls.localServers[0]; servers = &cls.localServers[0];
break; break;
case AS_MPLAYER : case AS_MPLAYER:
count = &cls.nummplayerservers;
servers = &cls.mplayerServers[0];
break;
case AS_GLOBAL : case AS_GLOBAL :
max = MAX_GLOBAL_SERVERS; max = MAX_GLOBAL_SERVERS;
count = &cls.numglobalservers; count = &cls.numglobalservers;
@ -188,10 +178,7 @@ static void LAN_RemoveServer(int source, const char *addr) {
count = &cls.numlocalservers; count = &cls.numlocalservers;
servers = &cls.localServers[0]; servers = &cls.localServers[0];
break; break;
case AS_MPLAYER : case AS_MPLAYER:
count = &cls.nummplayerservers;
servers = &cls.mplayerServers[0];
break;
case AS_GLOBAL : case AS_GLOBAL :
count = &cls.numglobalservers; count = &cls.numglobalservers;
servers = &cls.globalServers[0]; servers = &cls.globalServers[0];
@ -229,9 +216,7 @@ static int LAN_GetServerCount( int source ) {
case AS_LOCAL : case AS_LOCAL :
return cls.numlocalservers; return cls.numlocalservers;
break; break;
case AS_MPLAYER : case AS_MPLAYER:
return cls.nummplayerservers;
break;
case AS_GLOBAL : case AS_GLOBAL :
return cls.numglobalservers; return cls.numglobalservers;
break; break;
@ -255,12 +240,7 @@ static void LAN_GetServerAddressString( int source, int n, char *buf, int buflen
return; return;
} }
break; break;
case AS_MPLAYER : case AS_MPLAYER:
if (n >= 0 && n < MAX_OTHER_SERVERS) {
Q_strncpyz(buf, NET_AdrToStringwPort( cls.mplayerServers[n].adr) , buflen );
return;
}
break;
case AS_GLOBAL : case AS_GLOBAL :
if (n >= 0 && n < MAX_GLOBAL_SERVERS) { if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
Q_strncpyz(buf, NET_AdrToStringwPort( cls.globalServers[n].adr) , buflen ); Q_strncpyz(buf, NET_AdrToStringwPort( cls.globalServers[n].adr) , buflen );
@ -292,11 +272,7 @@ static void LAN_GetServerInfo( int source, int n, char *buf, int buflen ) {
server = &cls.localServers[n]; server = &cls.localServers[n];
} }
break; break;
case AS_MPLAYER : case AS_MPLAYER:
if (n >= 0 && n < MAX_OTHER_SERVERS) {
server = &cls.mplayerServers[n];
}
break;
case AS_GLOBAL : case AS_GLOBAL :
if (n >= 0 && n < MAX_GLOBAL_SERVERS) { if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
server = &cls.globalServers[n]; server = &cls.globalServers[n];
@ -343,11 +319,7 @@ static int LAN_GetServerPing( int source, int n ) {
server = &cls.localServers[n]; server = &cls.localServers[n];
} }
break; break;
case AS_MPLAYER : case AS_MPLAYER:
if (n >= 0 && n < MAX_OTHER_SERVERS) {
server = &cls.mplayerServers[n];
}
break;
case AS_GLOBAL : case AS_GLOBAL :
if (n >= 0 && n < MAX_GLOBAL_SERVERS) { if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
server = &cls.globalServers[n]; server = &cls.globalServers[n];
@ -377,11 +349,7 @@ static serverInfo_t *LAN_GetServerPtr( int source, int n ) {
return &cls.localServers[n]; return &cls.localServers[n];
} }
break; break;
case AS_MPLAYER : case AS_MPLAYER:
if (n >= 0 && n < MAX_OTHER_SERVERS) {
return &cls.mplayerServers[n];
}
break;
case AS_GLOBAL : case AS_GLOBAL :
if (n >= 0 && n < MAX_GLOBAL_SERVERS) { if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
return &cls.globalServers[n]; return &cls.globalServers[n];
@ -514,9 +482,7 @@ static void LAN_MarkServerVisible(int source, int n, qboolean visible ) {
case AS_LOCAL : case AS_LOCAL :
server = &cls.localServers[0]; server = &cls.localServers[0];
break; break;
case AS_MPLAYER : case AS_MPLAYER:
server = &cls.mplayerServers[0];
break;
case AS_GLOBAL : case AS_GLOBAL :
server = &cls.globalServers[0]; server = &cls.globalServers[0];
count = MAX_GLOBAL_SERVERS; count = MAX_GLOBAL_SERVERS;
@ -538,11 +504,7 @@ static void LAN_MarkServerVisible(int source, int n, qboolean visible ) {
cls.localServers[n].visible = visible; cls.localServers[n].visible = visible;
} }
break; break;
case AS_MPLAYER : case AS_MPLAYER:
if (n >= 0 && n < MAX_OTHER_SERVERS) {
cls.mplayerServers[n].visible = visible;
}
break;
case AS_GLOBAL : case AS_GLOBAL :
if (n >= 0 && n < MAX_GLOBAL_SERVERS) { if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
cls.globalServers[n].visible = visible; cls.globalServers[n].visible = visible;
@ -570,11 +532,7 @@ static int LAN_ServerIsVisible(int source, int n ) {
return cls.localServers[n].visible; return cls.localServers[n].visible;
} }
break; break;
case AS_MPLAYER : case AS_MPLAYER:
if (n >= 0 && n < MAX_OTHER_SERVERS) {
return cls.mplayerServers[n].visible;
}
break;
case AS_GLOBAL : case AS_GLOBAL :
if (n >= 0 && n < MAX_GLOBAL_SERVERS) { if (n >= 0 && n < MAX_GLOBAL_SERVERS) {
return cls.globalServers[n].visible; return cls.globalServers[n].visible;

View file

@ -263,11 +263,6 @@ typedef struct {
int punkbuster; int punkbuster;
} serverInfo_t; } serverInfo_t;
typedef struct {
byte ip[4];
unsigned short port;
} serverAddress_t;
typedef struct { typedef struct {
connstate_t state; // connection status connstate_t state; // connection status
@ -295,18 +290,13 @@ typedef struct {
serverInfo_t globalServers[MAX_GLOBAL_SERVERS]; serverInfo_t globalServers[MAX_GLOBAL_SERVERS];
// additional global servers // additional global servers
int numGlobalServerAddresses; int numGlobalServerAddresses;
serverAddress_t globalServerAddresses[MAX_GLOBAL_SERVERS]; netadr_t globalServerAddresses[MAX_GLOBAL_SERVERS];
int numfavoriteservers; int numfavoriteservers;
serverInfo_t favoriteServers[MAX_OTHER_SERVERS]; serverInfo_t favoriteServers[MAX_OTHER_SERVERS];
int nummplayerservers;
serverInfo_t mplayerServers[MAX_OTHER_SERVERS];
int pingUpdateSource; // source currently pinging or updating int pingUpdateSource; // source currently pinging or updating
int masterNum;
// update server info // update server info
netadr_t updateServer; netadr_t updateServer;
char updateChallenge[MAX_TOKEN_CHARS]; char updateChallenge[MAX_TOKEN_CHARS];

View file

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

View file

@ -673,17 +673,19 @@ void QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len
NET_StringToAdr NET_StringToAdr
Traps "localhost" for loopback, passes everything else to system 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 ) { int NET_StringToAdr( const char *s, netadr_t *a, netadrtype_t family )
qboolean r; {
char base[MAX_STRING_CHARS], *search; char base[MAX_STRING_CHARS], *search;
char *port = NULL; char *port = NULL;
if (!strcmp (s, "localhost")) { if (!strcmp (s, "localhost")) {
Com_Memset (a, 0, sizeof(*a)); Com_Memset (a, 0, sizeof(*a));
a->type = NA_LOOPBACK; 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 ) ); Q_strncpyz( base, s, sizeof( base ) );
@ -719,19 +721,20 @@ qboolean NET_StringToAdr( const char *s, netadr_t *a, netadrtype_t family ) {
search = base; search = base;
} }
r = Sys_StringToAdr( search, a, family ); if(!Sys_StringToAdr(search, a, family))
{
if ( !r ) {
a->type = NA_BAD; a->type = NA_BAD;
return qfalse; return 0;
} }
if ( port ) { if(port)
a->port = BigShort( (short)atoi( port ) ); {
} else { a->port = BigShort((short) atoi(port));
a->port = BigShort( PORT_SERVER ); return 1;
}
else
{
a->port = BigShort(PORT_SERVER);
return 2;
} }
return qtrue;
} }

View file

@ -171,7 +171,7 @@ qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b);
qboolean NET_IsLocalAddress (netadr_t adr); qboolean NET_IsLocalAddress (netadr_t adr);
const char *NET_AdrToString (netadr_t a); const char *NET_AdrToString (netadr_t a);
const char *NET_AdrToStringwPort (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); qboolean NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message);
void NET_JoinMulticast6(void); void NET_JoinMulticast6(void);
void NET_LeaveMulticast6(void); void NET_LeaveMulticast6(void);

View file

@ -252,7 +252,7 @@ void SV_MasterHeartbeat( void ) {
sv_master[i]->modified = qfalse; sv_master[i]->modified = qfalse;
Com_Printf( "Resolving %s\n", sv_master[i]->string ); 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 // if the address failed to resolve, clear it
// so we don't take repeated dns hits // so we don't take repeated dns hits
Com_Printf( "Couldn't resolve address: %s\n", sv_master[i]->string ); Com_Printf( "Couldn't resolve address: %s\n", sv_master[i]->string );
@ -263,9 +263,7 @@ void SV_MasterHeartbeat( void ) {
if ( !strchr( sv_master[i]->string, ':' ) ) { if ( !strchr( sv_master[i]->string, ':' ) ) {
adr[i].port = BigShort( PORT_MASTER ); adr[i].port = BigShort( PORT_MASTER );
} }
Com_Printf( "%s resolved to %i.%i.%i.%i:%i\n", sv_master[i]->string, Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToStringwPort(adr[i]));
adr[i].ip[0], adr[i].ip[1], adr[i].ip[2], adr[i].ip[3],
BigShort( adr[i].port ) );
} }

View file

@ -2495,12 +2495,8 @@ static qboolean UI_NetSource_HandleKey(int flags, float *special, int key) {
if (key == K_MOUSE2) { if (key == K_MOUSE2) {
ui_netSource.integer--; ui_netSource.integer--;
if (ui_netSource.integer == AS_MPLAYER)
ui_netSource.integer--;
} else { } else {
ui_netSource.integer++; ui_netSource.integer++;
if (ui_netSource.integer == AS_MPLAYER)
ui_netSource.integer++;
} }
if (ui_netSource.integer >= numNetSources) { if (ui_netSource.integer >= numNetSources) {
@ -5972,20 +5968,14 @@ static void UI_StartServerRefresh(qboolean full)
} }
uiInfo.serverStatus.refreshtime = uiInfo.uiDC.realTime + 5000; uiInfo.serverStatus.refreshtime = uiInfo.uiDC.realTime + 5000;
if( ui_netSource.integer == AS_GLOBAL || ui_netSource.integer == AS_MPLAYER ) { if( ui_netSource.integer == AS_GLOBAL ) {
if( ui_netSource.integer == AS_GLOBAL ) {
i = 0;
}
else {
i = 1;
}
ptr = UI_Cvar_VariableString("debug_protocol"); ptr = UI_Cvar_VariableString("debug_protocol");
if (strlen(ptr)) { 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 { 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" ) ) );
} }
} }
} }