From 2b39517c2d6edb6f008150eaaebf5318029c8939 Mon Sep 17 00:00:00 2001 From: Christopher Schwarz Date: Sat, 10 Oct 2009 18:59:32 +0000 Subject: * (bug 4296) Server browser fixes - Fix "refresh" creating duplicate servers - Fix featured server status not being cached - Fix not giving you the server you clicked on (Rezyn) --- src/client/cl_main.c | 44 ++++++++++---------------------------------- src/client/cl_ui.c | 3 +-- src/client/client.h | 9 ++------- src/ui/ui_main.c | 22 ++++++++++++++++++---- 4 files changed, 31 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/client/cl_main.c b/src/client/cl_main.c index 738347ea..09c42e63 100644 --- a/src/client/cl_main.c +++ b/src/client/cl_main.c @@ -2315,7 +2315,7 @@ void CL_InitServerInfo( serverInfo_t *server, netadr_t *address ) { server->clients = 0; server->hostName[0] = '\0'; server->mapName[0] = '\0'; - server->label = NULL; + server->label[0] = '\0'; server->maxClients = 0; server->maxPing = 0; server->minPing = 0; @@ -2378,47 +2378,25 @@ CL_GSRFeaturedLabel Parses from the data an arbitrary text string labelling the servers in the following getserversresponse packet. -Either this matches an existing label, or it is copied into a new one. -The relevant buffer, or NULL, is returned, and *data is advanced as appropriate +The result is copied to *buf, and *data is advanced as appropriate =================== */ -char *CL_GSRFeaturedLabel( byte **data ) +void CL_GSRFeaturedLabel( byte **data, char *buf, int size ) { - char label[ MAX_FEATLABEL_CHARS ] = { 0 }, *l = label; - int i; + char *l = buf; + buf[0] = '\0'; // copy until '\0' which indicates field break // or slash which indicates beginning of server list while( **data && **data != '\\' && **data != '/' ) { - if( l < &label[ sizeof( label ) - 1 ] ) + if( l < &buf[ size - 1 ] ) *l = **data; - else if( l == &label[ sizeof( label ) - 1 ] ) + else if( l == &buf[ size - 1 ] ) Com_DPrintf( S_COLOR_YELLOW "Warning: " "CL_GSRFeaturedLabel: overflow\n" ); l++, (*data)++; } - - if( !label[ 0 ] ) - return NULL; - - // find the label in the stored array - for( i = 0; i < cls.numFeaturedServerLabels; i++ ) - { - l = cls.featuredServerLabels[ i ]; - if( strcmp( label, l ) == 0 ) - return l; - } - if( i == MAX_FEATURED_LABELS ) - { - Com_DPrintf( S_COLOR_YELLOW "Warning: CL_GSRFeaturedLabel: " - "ran out of label space, dropping %s\n", label ); - return NULL; - } - if( i == 0 ) - l = cls.featuredServerLabels[ 0 ]; - Q_strncpyz( l, label, sizeof( *cls.featuredServerLabels ) ); - return l; } #define MAX_SERVERSPERPACKET 256 @@ -2434,7 +2412,7 @@ void CL_ServersResponsePacket( const netadr_t* from, msg_t *msg, qboolean extend int numservers; byte* buffptr; byte* buffend; - char *label = NULL; + char label[MAX_FEATLABEL_CHARS]; Com_DPrintf("CL_ServersResponsePacket%s\n", (extended) ? " (extended)" : ""); @@ -2445,7 +2423,6 @@ void CL_ServersResponsePacket( const netadr_t* from, msg_t *msg, qboolean extend cls.numGlobalServerAddresses = 0; cls.numMasterPackets = 0; cls.receivedMasterPackets = 0; - cls.numFeaturedServerLabels = 0; } // parse through server response string @@ -2487,8 +2464,7 @@ void CL_ServersResponsePacket( const netadr_t* from, msg_t *msg, qboolean extend "%d of %d\n", ind, cls.numMasterPackets ); cls.receivedMasterPackets |= ( 1 << ( ind - 1 ) ); - label = CL_GSRFeaturedLabel( &buffptr ); - Com_DPrintf( "CL_GSRFeaturedLabel: %s\n", label ); + CL_GSRFeaturedLabel( &buffptr, label, sizeof( label ) ); } // now skip to the server list for(; buffptr < buffend && *buffptr != '\\' && *buffptr != '/'; @@ -2549,7 +2525,7 @@ void CL_ServersResponsePacket( const netadr_t* from, msg_t *msg, qboolean extend serverInfo_t *server = &cls.globalServers[count]; CL_InitServerInfo( server, &addresses[i] ); - server->label = label; + Q_strncpyz( server->label, label, sizeof( server->label ) ); // advance to next slot count++; } diff --git a/src/client/cl_ui.c b/src/client/cl_ui.c index 6c00a353..4c1ff9ed 100644 --- a/src/client/cl_ui.c +++ b/src/client/cl_ui.c @@ -285,8 +285,7 @@ static void LAN_GetServerInfo( int source, int n, char *buf, int buflen ) { buf[0] = '\0'; Info_SetValueForKey( info, "hostname", server->hostName); Info_SetValueForKey( info, "mapname", server->mapName); - if( server->label ) - Info_SetValueForKey( info, "label", server->label); + Info_SetValueForKey( info, "label", server->label); Info_SetValueForKey( info, "clients", va("%i",server->clients)); Info_SetValueForKey( info, "sv_maxclients", va("%i",server->maxClients)); Info_SetValueForKey( info, "ping", va("%i",server->ping)); diff --git a/src/client/client.h b/src/client/client.h index 5a1106b4..206d5dd9 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -283,12 +283,13 @@ typedef struct { char info[MAX_INFO_STRING]; } ping_t; +#define MAX_FEATLABEL_CHARS 1024 typedef struct { netadr_t adr; char hostName[MAX_HOSTNAME_LENGTH]; char mapName[MAX_NAME_LENGTH]; char game[MAX_NAME_LENGTH]; - char *label; // for featured servers, NULL otherwise + char label[MAX_FEATLABEL_CHARS]; // for featured servers, NULL otherwise int netType; int gameType; int clients; @@ -299,9 +300,6 @@ typedef struct { qboolean visible; } serverInfo_t; -#define MAX_FEATURED_LABELS 8 -#define MAX_FEATLABEL_CHARS 1024 - typedef struct { connstate_t state; // connection status @@ -338,9 +336,6 @@ typedef struct { int numfavoriteservers; serverInfo_t favoriteServers[MAX_OTHER_SERVERS]; - int numFeaturedServerLabels; - char featuredServerLabels[ MAX_FEATURED_LABELS ][ MAX_FEATLABEL_CHARS ]; - int pingUpdateSource; // source currently pinging or updating // update server info diff --git a/src/ui/ui_main.c b/src/ui/ui_main.c index 83092c72..3eb63c5d 100644 --- a/src/ui/ui_main.c +++ b/src/ui/ui_main.c @@ -273,13 +273,19 @@ UI_InsertServerIntoDisplayList static void UI_InsertServerIntoDisplayList( int num, int position ) { int i; + static char info[MAX_STRING_CHARS]; if( position < 0 || position > uiInfo.serverStatus.numDisplayServers ) return; - // + + trap_LAN_GetServerInfo( ui_netSource.integer, num, info, MAX_STRING_CHARS ); + uiInfo.serverStatus.numDisplayServers++; + if( Info_ValueForKey( info, "label" )[0] ) + uiInfo.serverStatus.numFeaturedServers++; + for( i = uiInfo.serverStatus.numDisplayServers; i > position; i-- ) uiInfo.serverStatus.displayServers[i] = uiInfo.serverStatus.displayServers[i-1]; @@ -294,6 +300,7 @@ UI_RemoveServerFromDisplayList static void UI_RemoveServerFromDisplayList( int num ) { int i, j; + static char info[MAX_STRING_CHARS]; for( i = 0; i < uiInfo.serverStatus.numDisplayServers; i++ ) { @@ -301,6 +308,10 @@ static void UI_RemoveServerFromDisplayList( int num ) { uiInfo.serverStatus.numDisplayServers--; + trap_LAN_GetServerInfo( ui_netSource.integer, num, info, MAX_STRING_CHARS ); + if( Info_ValueForKey( info, "label" )[0] ) + uiInfo.serverStatus.numFeaturedServers--; + for( j = i; j < uiInfo.serverStatus.numDisplayServers; j++ ) uiInfo.serverStatus.displayServers[j] = uiInfo.serverStatus.displayServers[j+1]; @@ -837,6 +848,7 @@ static void UI_BuildServerDisplayList( qboolean force ) numinvisible = 0; // clear number of displayed servers uiInfo.serverStatus.numDisplayServers = 0; + uiInfo.serverStatus.numFeaturedServers = 0; uiInfo.serverStatus.numPlayersOnServers = 0; // set list box index to zero Menu_SetFeederSelection( NULL, FEEDER_SERVERS, 0, NULL ); @@ -851,6 +863,7 @@ static void UI_BuildServerDisplayList( qboolean force ) { // still waiting on a response from the master uiInfo.serverStatus.numDisplayServers = 0; + uiInfo.serverStatus.numFeaturedServers = 0; uiInfo.serverStatus.numPlayersOnServers = 0; uiInfo.serverStatus.nextDisplayRefresh = uiInfo.uiDC.realTime + 500; return; @@ -907,8 +920,6 @@ static void UI_BuildServerDisplayList( qboolean force ) if( ping > 0 ) { trap_LAN_MarkServerVisible( ui_netSource.integer, i, qfalse ); - if( Info_ValueForKey( info, "label" )[0] ) - uiInfo.serverStatus.numFeaturedServers++; numinvisible++; } } @@ -3683,9 +3694,12 @@ static void UI_FeederSelection( float feederID, int index ) trap_CIN_PlayCinematic( va( "%s.roq", uiInfo.mapList[ui_selectedMap.integer].mapLoadName ), 0, 0, 0, 0, ( CIN_loop | CIN_silent ) ); } - else if( feederID == FEEDER_SERVERS ) + else if( feederID == FEEDER_SERVERS || feederID == FEEDER_FEATURED ) { const char *mapName = NULL; + + if( feederID == FEEDER_SERVERS ) + index += UI_FeederCount( FEEDER_FEATURED ); uiInfo.serverStatus.currentServer = index; trap_LAN_GetServerInfo( ui_netSource.integer, uiInfo.serverStatus.displayServers[index], info, MAX_STRING_CHARS ); -- cgit