예제 #1
0
/*
=================
ArenaServers_StopRefresh
=================
*/
static void ArenaServers_StopRefresh( void )
{
	int count;

	if (!serverStatus.refreshActive) {
		// not currently refreshing
		return;
	}
	serverStatus.refreshActive = qfalse;
	Com_Printf("%d servers listed in browser with %d players.\n",
					serverStatus.numDisplayServers,
					serverStatus.numPlayersOnServers);
	count = trap_LAN_GetServerCount(g_arenaservers.master.curvalue);
	if (count - serverStatus.numDisplayServers > 0) {
		if ( ui_browserShowAwOnly.integer ) {
			Com_Printf("%d servers not listed because they aren't running Afterwards or have pings over %d\n",
						count - serverStatus.numDisplayServers,
						(int) trap_Cvar_VariableValue("cl_maxPing"));
		} else {
			Com_Printf("%d servers not listed due to packet loss or pings over %d\n",
						count - serverStatus.numDisplayServers,
						(int) trap_Cvar_VariableValue("cl_maxPing"));
		}
	}

	ArenaServers_UpdateMenu( qtrue );
}
예제 #2
0
/*
=================
ArenaServers_DoRefresh
=================
*/
static void ArenaServers_DoRefresh( void )
{
	qboolean wait = qfalse;

	if (!serverStatus.refreshActive) {
		return;
	}
	if (g_arenaservers.master.curvalue != AS_FAVORITES) {
		if (g_arenaservers.master.curvalue == AS_LOCAL) {
			if (!trap_LAN_GetServerCount(g_arenaservers.master.curvalue)) {
				if ( uis.realtime > serverStatus.refreshtime ) {
					serverStatus.refreshtime = uis.realtime + 3000;
					trap_Cmd_ExecuteText( EXEC_NOW, "localservers\n" );
				}
				wait = qtrue;
			}
		} else {
			if (trap_LAN_GetServerCount(g_arenaservers.master.curvalue) < 0) {
				wait = qtrue;
			}
		}
	}

	if (uis.realtime < serverStatus.refreshtime || wait) {
		return;
	}

//	ArenaServers_BuildDisplayList(qtrue);
//	Com_Printf("Number of Servers: %i\n", serverStatus.numDisplayServers);
//	ArenaServers_UpdateMenu();

	// if still trying to retrieve pings
	if (trap_LAN_UpdateVisiblePings(g_arenaservers.master.curvalue)) {
		serverStatus.refreshtime = uis.realtime + 500;
	} else if (!wait) {
		// get the last servers in the list
		ArenaServers_BuildDisplayList( qfalse );
		// stop the refresh
		ArenaServers_StopRefresh();
	}
	//
	ArenaServers_BuildDisplayList( qfalse );
}
예제 #3
0
/*
=================
ArenaServers_DoRefresh
=================
*/
static void ArenaServers_DoRefresh( void )
{
	int		i;
	int		j;
	int		time;
	int		maxPing;
	char	adrstr[MAX_ADDRESSLENGTH];
	char	info[MAX_INFO_STRING];

	if (uis.realtime < g_arenaservers.refreshtime)
	{
	  if (g_servertype != UIAS_FAVORITES) {
			if (g_servertype == UIAS_LOCAL) {
				if (!trap_LAN_GetServerCount(AS_LOCAL)) {
					return;
				}
			}
			if (trap_LAN_GetServerCount(ArenaServers_SourceForLAN()) < 0) {
			  // still waiting for response
			  return;
			}
	  }
	}

	if (uis.realtime < g_arenaservers.nextpingtime)
	{
		// wait for time trigger
		return;
	}

	// trigger at 10Hz intervals
	g_arenaservers.nextpingtime = uis.realtime + 10;

	// process ping results
	maxPing = ArenaServers_MaxPing();
	for (i=0; i<MAX_PINGREQUESTS; i++)
	{
		trap_LAN_GetPing( i, adrstr, MAX_ADDRESSLENGTH, &time );
		if (!adrstr[0])
		{
			// ignore empty or pending pings
			continue;
		}

		// find ping result in our local list
		for (j=0; j<MAX_PINGREQUESTS; j++)
			if (!Q_stricmp( adrstr, g_arenaservers.pinglist[j].adrstr ))
				break;

		if (j < MAX_PINGREQUESTS)
		{
			// found it
			if (!time)
			{
				time = uis.realtime - g_arenaservers.pinglist[j].start;
				if (time < maxPing)
				{
					// still waiting
					continue;
				}
			}

			if (time > maxPing)
			{
				// stale it out
				info[0] = '\0';
				time    = maxPing;
			}
			else
			{
				trap_LAN_GetPingInfo( i, info, MAX_INFO_STRING );
			}

			// insert ping results
			ArenaServers_Insert( adrstr, info, time );

			// clear this query from internal list
			g_arenaservers.pinglist[j].adrstr[0] = '\0';
   		}

		// clear this query from external list
		trap_LAN_ClearPing( i );
	}

	// get results of servers query
	// counts can increase as servers respond
	if (g_servertype == UIAS_FAVORITES) {
	  g_arenaservers.numqueriedservers = g_arenaservers.numfavoriteaddresses;
	} else {
	  g_arenaservers.numqueriedservers = trap_LAN_GetServerCount(ArenaServers_SourceForLAN());
	}

//	if (g_arenaservers.numqueriedservers > g_arenaservers.maxservers)
//		g_arenaservers.numqueriedservers = g_arenaservers.maxservers;

	// send ping requests in reasonable bursts
	// iterate ping through all found servers
	for (i=0; i<MAX_PINGREQUESTS && g_arenaservers.currentping < g_arenaservers.numqueriedservers; i++)
	{
		if (trap_LAN_GetPingQueueCount() >= MAX_PINGREQUESTS)
		{
			// ping queue is full
			break;
		}

		// find empty slot
		for (j=0; j<MAX_PINGREQUESTS; j++)
			if (!g_arenaservers.pinglist[j].adrstr[0])
				break;

		if (j >= MAX_PINGREQUESTS)
			// no empty slots available yet - wait for timeout
			break;

		// get an address to ping

		if (g_servertype == UIAS_FAVORITES) {
		  strcpy( adrstr, g_arenaservers.favoriteaddresses[g_arenaservers.currentping] ); 		
		} else {
		  trap_LAN_GetServerAddressString(ArenaServers_SourceForLAN(), g_arenaservers.currentping, adrstr, MAX_ADDRESSLENGTH );
		}

		strcpy( g_arenaservers.pinglist[j].adrstr, adrstr );
		g_arenaservers.pinglist[j].start = uis.realtime;

		trap_Cmd_ExecuteText( EXEC_NOW, va( "ping %s\n", adrstr )  );
		
		// advance to next server
		g_arenaservers.currentping++;
	}

	if (!trap_LAN_GetPingQueueCount())
	{
		// all pings completed
		ArenaServers_StopRefresh();
		return;
	}

	// update the user interface with ping status
	ArenaServers_UpdateMenu();
}
예제 #4
0
/*
=================
ArenaServers_UpdateMenu
=================
*/
static void ArenaServers_UpdateMenu( qboolean full ) {
	static char info[MAX_STRING_CHARS];
	int			index;
	char*		buff;
	table_t*	tableptr;
	int			ping;
	int			clients;
	int			maxclients;
	int			gametype;
	char		hostname[MAX_HOSTNAMELENGTH];
	char		mapname[MAX_MAPNAMELENGTH];
	char		*pingColor;
	char		*gametypeColor;

	g_arenaservers.numqueriedservers = trap_LAN_GetServerCount(g_arenaservers.master.curvalue);
	if( g_arenaservers.numqueriedservers > 0 ) {
		// servers found
		if( serverStatus.refreshActive ) {
			// show progress
			Com_sprintf( g_arenaservers.status.string, MAX_STATUSLENGTH, "Found %d Servers. Refreshing... (%d)", 
				g_arenaservers.numqueriedservers, serverStatus.numRefreshedServers);
			g_arenaservers.statusbar.string  = "Press SPACE to stop";

			// disable controls during refresh
			g_arenaservers.master.generic.flags		|= QMF_GRAYED;
			g_arenaservers.gametype.generic.flags	|= QMF_GRAYED;
			g_arenaservers.sortkey.generic.flags	|= QMF_GRAYED;
			g_arenaservers.showempty.generic.flags	|= QMF_GRAYED;
			g_arenaservers.showfull.generic.flags	|= QMF_GRAYED;
			g_arenaservers.showawonly.generic.flags	|= QMF_GRAYED;
			g_arenaservers.list.generic.flags		|= QMF_GRAYED;
			g_arenaservers.refresh.generic.flags	|= QMF_GRAYED;
			g_arenaservers.go.generic.flags			|= QMF_GRAYED;
			g_arenaservers.favorite.generic.flags	|= QMF_GRAYED;
			g_arenaservers.info.generic.flags		|= QMF_GRAYED;
		}
		else {
			// all servers pinged - enable controls
			g_arenaservers.master.generic.flags		&= ~QMF_GRAYED;
			g_arenaservers.gametype.generic.flags	&= ~QMF_GRAYED;
			g_arenaservers.sortkey.generic.flags	&= ~QMF_GRAYED;
			g_arenaservers.showempty.generic.flags	&= ~QMF_GRAYED;
			g_arenaservers.showfull.generic.flags	&= ~QMF_GRAYED;
			g_arenaservers.showawonly.generic.flags	&= ~QMF_GRAYED;
			g_arenaservers.list.generic.flags		&= ~QMF_GRAYED;
			g_arenaservers.refresh.generic.flags	&= ~QMF_GRAYED;
			g_arenaservers.go.generic.flags			&= ~QMF_GRAYED;
			g_arenaservers.favorite.generic.flags	&= ~QMF_GRAYED;
			g_arenaservers.info.generic.flags		&= ~QMF_GRAYED;

			// update status bar
			if ( ui_browserShowAwOnly.integer ) {
				strcpy(g_arenaservers.status.string, va("%i Servers running Afterwards with %i Players found.", 
					serverStatus.numDisplayServers, serverStatus.numPlayersOnServers));
			} else {
				strcpy(g_arenaservers.status.string, va("%i Servers with %i Players found.", 
					serverStatus.numDisplayServers, serverStatus.numPlayersOnServers));
			}

			if( g_servertype == AS_GLOBAL || g_servertype == AS_MPLAYER ) {
				g_arenaservers.statusbar.string = quake3worldMessage;
			}
			else {
				g_arenaservers.statusbar.string = "";
			}
			if (!(g_arenaservers.grlogo.generic.flags & QMF_HIDDEN)) {
				g_arenaservers.statusbar.string = globalRankingsMessage;
			}

		}
	}
	else {
		// no servers found
		if( serverStatus.refreshActive ) {
			strcpy( g_arenaservers.status.string,"Scanning For Servers." );
			g_arenaservers.statusbar.string = "Press SPACE to stop";

			// disable controls during refresh
			g_arenaservers.master.generic.flags		|= QMF_GRAYED;
			g_arenaservers.gametype.generic.flags	|= QMF_GRAYED;
			g_arenaservers.sortkey.generic.flags	|= QMF_GRAYED;
			g_arenaservers.showempty.generic.flags	|= QMF_GRAYED;
			g_arenaservers.showfull.generic.flags	|= QMF_GRAYED;
			g_arenaservers.showawonly.generic.flags	|= QMF_GRAYED;
			g_arenaservers.list.generic.flags		|= QMF_GRAYED;
			g_arenaservers.refresh.generic.flags	|= QMF_GRAYED;
			g_arenaservers.go.generic.flags			|= QMF_GRAYED;
			g_arenaservers.favorite.generic.flags	|= QMF_GRAYED;
			g_arenaservers.info.generic.flags		|= QMF_GRAYED;
		}
		else {
			if( g_arenaservers.numqueriedservers < 0 ) {
				strcpy(g_arenaservers.status.string,"No Response From Master Server." );
			}
			else {
				if ( ui_browserShowAwOnly.integer ) strcpy(g_arenaservers.status.string,"No Servers running Afterwards found." );
				else strcpy(g_arenaservers.status.string,"No Servers Found." );
			}

			// update status bar
			if( g_servertype == AS_GLOBAL || g_servertype == AS_MPLAYER ) {
				g_arenaservers.statusbar.string = quake3worldMessage;
			}
			else {
				g_arenaservers.statusbar.string = "";
			}

			// end of refresh - set control state
			g_arenaservers.master.generic.flags		&= ~QMF_GRAYED;
			g_arenaservers.gametype.generic.flags	&= ~QMF_GRAYED;
			g_arenaservers.sortkey.generic.flags	&= ~QMF_GRAYED;
			g_arenaservers.showempty.generic.flags	&= ~QMF_GRAYED;
			g_arenaservers.showfull.generic.flags	&= ~QMF_GRAYED;
			g_arenaservers.showawonly.generic.flags	&= ~QMF_GRAYED;
			g_arenaservers.list.generic.flags		|= QMF_GRAYED;
			g_arenaservers.refresh.generic.flags	&= ~QMF_GRAYED;
			g_arenaservers.go.generic.flags			|= QMF_GRAYED;
			g_arenaservers.favorite.generic.flags	&= ~QMF_GRAYED;
			g_arenaservers.info.generic.flags		&= ~QMF_GRAYED;
		}

		// zero out list box
		g_arenaservers.list.numitems = 0;
		g_arenaservers.list.curvalue = 0;
		g_arenaservers.list.top      = 0;

		// update picture
		ArenaServers_UpdatePicture();
		return;
	}

	for (index = 0; (index < serverStatus.numDisplayServers && index < MAX_LISTBOXITEMS && (index < 11 || full)); index++ ) {

		tableptr = &g_arenaservers.table[index];
		buff = tableptr->buff;

		trap_LAN_GetServerInfo(g_arenaservers.master.curvalue, serverStatus.displayServers[index], info, MAX_STRING_CHARS);

		Q_strncpyz(mapname, Info_ValueForKey(info, "mapname"), MAX_MAPNAMELENGTH ); 
		clients = atoi(Info_ValueForKey(info, "clients"));
		maxclients = atoi(Info_ValueForKey(info, "sv_maxclients"));
		
		ping = atoi(Info_ValueForKey(info, "ping"));
		if (ping == -1) {
			// if we ever see a ping that is out of date, do a server refresh
			// UI_UpdatePendingPings();
		}

		if( ping < 200 ) 
			pingColor = S_COLOR_GREEN;
		else if( ping < 400 ) 
			pingColor = S_COLOR_YELLOW;
		else 
			pingColor = S_COLOR_RED;

		if (ping <= 0) {
			Q_strncpyz( hostname, Info_ValueForKey( info, "addr"), MAX_HOSTNAMELENGTH );
		} else {
			if ( g_arenaservers.master.curvalue == AS_LOCAL ) {
				Com_sprintf( hostname, sizeof(hostname), "%s [%s]",
					Info_ValueForKey(info, "hostname"),
					netnames[atoi(Info_ValueForKey(info, "nettype"))] );
			}
			else {
				Q_strncpyz( hostname, Info_ValueForKey( info, "hostname"), MAX_HOSTNAMELENGTH );
			}
		}
		UI_DeleteColorCodes( hostname );

		gametype = atoi(Info_ValueForKey(info, "gametype"));
		if ( gametype > GT_MAX_GAME_TYPE ) gametype = GT_MAX_GAME_TYPE;		

		// CHANGE "awbeta2" back to "afterwards"!!!
		if ( Q_stricmp(Info_ValueForKey(info, "game"), "afterwards") == 0 ) {
			// afterwards game -> show color code and gametype short
			switch (gametype) {
				case 0: gametypeColor = ""; break; // orange
				case 1: gametypeColor = S_COLOR_RED; break;
				default: gametypeColor = S_COLOR_YELLOW;
			}
		} else {
			// not an afterwards game -> yellow and "--" for gametype
			gametype = GT_MAX_GAME_TYPE;
			gametypeColor = S_COLOR_YELLOW;
		}

		Com_sprintf( buff, MAX_LISTBOXWIDTH+8, "%s%s  %-32.32s  %-16.16s  %2d/%2d  %s%3d", 
			gametypeColor, gamenames[gametype], hostname, mapname, clients, maxclients, pingColor, ping );

	}

	// Com_sprintf( g_arenaservers.status.string, MAX_STATUSLENGTH, "%d of %d Arena Servers.", serverStatus.numDisplayServers, *g_arenaservers.numservers );

	g_arenaservers.list.numitems = (serverStatus.numDisplayServers < MAX_LISTBOXITEMS) ? serverStatus.numDisplayServers : MAX_LISTBOXITEMS ;
	g_arenaservers.list.curvalue = 0;
	g_arenaservers.list.top      = 0;

	// update picture
	ArenaServers_UpdatePicture();
}
예제 #5
0
/*
==================
ArenaServers_BuildDisplayList
==================
*/
static void ArenaServers_BuildDisplayList(qboolean force) {
	int i, count, clients, maxClients, ping, game, visible;
	char info[MAX_STRING_CHARS];
	qboolean startRefresh = qtrue;
	static int numinvisible;

/*	if (!(force || uis.realtime > serverStatus.nextDisplayRefresh)) {
		return;
	}
	// if we shouldn't reset
	if ( force == 2 ) {
		force = 0;
	}*/

	if (force) {
		numinvisible = 0;
		// clear number of displayed servers
		serverStatus.numDisplayServers = 0;
		serverStatus.numRefreshedServers = 0;
		serverStatus.numPlayersOnServers = 0;
		// set list box index to zero
		//Menu_SetFeederSelection(NULL, FEEDER_SERVERS, 0, NULL);
		g_arenaservers.list.numitems = 0;
		g_arenaservers.list.curvalue = 0;
		g_arenaservers.list.top      = 0;
		// mark all servers as visible so we store ping updates for them
		trap_LAN_MarkServerVisible(g_arenaservers.master.curvalue, -1, qtrue);
	}

	// get the server count (comes from the master)
	count = trap_LAN_GetServerCount(g_arenaservers.master.curvalue);
	if (count == -1 || (g_arenaservers.master.curvalue == AS_LOCAL && count == 0) ) {
		// still waiting on a response from the master
		serverStatus.numDisplayServers = 0;
		serverStatus.numRefreshedServers = 0;
		serverStatus.numPlayersOnServers = 0;
		serverStatus.nextDisplayRefresh = uis.realtime + 500;
		return;
	}

	visible = qfalse;
	for (i = 0; i < count; i++) {
		// if we already got info for this server
		if (!trap_LAN_ServerIsVisible(g_arenaservers.master.curvalue, i)) {
			continue;
		}
		visible = qtrue;
		// get the ping for this server
		ping = trap_LAN_GetServerPing(g_arenaservers.master.curvalue, i);
		if (ping > 0 || g_arenaservers.master.curvalue == AS_FAVORITES) {

			trap_LAN_GetServerInfo(g_arenaservers.master.curvalue, i, info, MAX_STRING_CHARS);

			serverStatus.numRefreshedServers++;

			clients = atoi(Info_ValueForKey(info, "clients"));
			maxClients = atoi(Info_ValueForKey(info, "sv_maxclients"));

			if (ui_browserShowAwOnly.integer) {
				// CHANGE "awbeta2" back to "afterwards"!!!
				if (Q_stricmp(Info_ValueForKey(info, "game"), "afterwards") != 0 && g_arenaservers.master.curvalue != AS_FAVORITES ) {
					trap_LAN_MarkServerVisible(g_arenaservers.master.curvalue, i, qfalse);
					continue;
				}
			}

			if (ui_browserShowEmpty.integer == 0) {
				if (clients == 0) {
					trap_LAN_MarkServerVisible(g_arenaservers.master.curvalue, i, qfalse);
					continue;
				}
			}

			if (ui_browserShowFull.integer == 0) {
				if (clients == maxClients) {
					trap_LAN_MarkServerVisible(g_arenaservers.master.curvalue, i, qfalse);
					continue;
				}
			}

			if (g_gametype) {
				game = atoi(Info_ValueForKey(info, "gametype"));
				if (game != g_gametype-1) {
					trap_LAN_MarkServerVisible(g_arenaservers.master.curvalue, i, qfalse);
					continue;
				}
			}
				
			// make sure we never add a favorite server twice
			if (g_arenaservers.master.curvalue == AS_FAVORITES) {
				UI_RemoveServerFromDisplayList(i);
			}
			// insert the server into the list
			UI_BinaryServerInsertion(i);
			// increase clients count
			clients = atoi(Info_ValueForKey(info, "clients"));
			serverStatus.numPlayersOnServers += clients;
			// done with this server
			if (ping > 0) {
				trap_LAN_MarkServerVisible(g_arenaservers.master.curvalue, i, qfalse);
				numinvisible++;
			}
		}
	}

//	serverStatus.refreshtime = uis.realtime;

	ArenaServers_UpdateMenu( force );

	// if there were no servers visible for ping updates
	if (!visible) {
//		UI_StopServerRefresh();
//		serverStatus.nextDisplayRefresh = 0;
	}
}