Exemple #1
0
/*
================
idServerScan::NetScan
================
*/
void idServerScan::NetScan( ) {
	if ( !idAsyncNetwork::client.IsPortInitialized() ) {
		// if the port isn't open, initialize it, but wait for a short
		// time to let the OS do whatever magic things it needs to do...
		idAsyncNetwork::client.InitPort();
		// start the scan one second from now...
		scan_state = WAIT_ON_INIT;
		endWaitTime = Sys_Milliseconds() + 1000;
		return;
	}

	// make sure the client port is open
	idAsyncNetwork::client.InitPort();

	scan_state = NET_SCAN;
	challenge++;
	
	idList<networkServer_t>::Clear();
	m_sortedServers.Clear();
	cur_info = 0;
	net_info.Clear();
	listGUI->Clear();
	GUIUpdateSelected();
	common->DPrintf( "NetScan with challenge %d\n", challenge );
	
	while ( cur_info < Min( net_servers.Num(), MAX_PINGREQUESTS ) ) {
		netadr_t serv = net_servers[ cur_info ].adr;
		EmitGetInfo( serv );
		net_servers[ cur_info ].time = Sys_Milliseconds();
		net_info.SetInt( Sys_NetAdrToString( serv ), cur_info );
		cur_info++;
	}
}
Exemple #2
0
/*
================
idServerScan::SetupLANScan
================
*/
void idServerScan::SetupLANScan( ) {	
	Clear();
	GUIUpdateSelected();
	scan_state = LAN_SCAN;
	challenge++;
	lan_pingtime = Sys_Milliseconds();
	common->DPrintf( "SetupLANScan with challenge %d\n", challenge );
}
Exemple #3
0
/*
================
idServerScan::InfoResponse
================
*/
int idServerScan::InfoResponse( networkServer_t &server ) {
	if ( scan_state == IDLE ) {
		return false;
	}

	idStr serv = Sys_NetAdrToString( server.adr );

	if ( server.challenge != challenge ) {
		common->DPrintf( "idServerScan::InfoResponse - ignoring response from %s, wrong challenge %d.", serv.c_str(), server.challenge );
		return false;
	}

	if ( scan_state == NET_SCAN ) {	
		const idKeyValue *info = net_info.FindKey( serv.c_str() );
		if ( !info ) {
			common->DPrintf( "idServerScan::InfoResponse NET_SCAN: reply from unknown %s\n", serv.c_str() );
			return false;
		}
		int id = atoi( info->GetValue() );
		net_info.Delete( serv.c_str() );
		inServer_t iserv = net_servers[ id ];
		server.ping = Sys_Milliseconds() - iserv.time;
		server.id = iserv.id;
	} else {
		server.ping = Sys_Milliseconds() - lan_pingtime;
		server.id = 0;

		// check for duplicate servers
		for ( int i = 0; i < Num() ; i++ ) {
			if ( memcmp( &(*this)[ i ].adr, &server.adr, sizeof(netadr_t) ) == 0 ) {
				common->DPrintf( "idServerScan::InfoResponse LAN_SCAN: duplicate server %s\n", serv.c_str() );
				return true;
			}
		}
	}

	const char *si_map = server.serverInfo.GetString( "si_map" );
	const idDecl *mapDecl = declManager->FindType( DECL_MAPDEF, si_map, false );
	const idDeclEntityDef *mapDef = static_cast< const idDeclEntityDef * >( mapDecl );
	if ( mapDef ) {
		const char *mapName = common->GetLanguageDict()->GetString( mapDef->dict.GetString( "name", si_map ) );
		server.serverInfo.Set( "si_mapName", mapName );
	} else {
		server.serverInfo.Set( "si_mapName", si_map );
	}

	int index = Append( server );
	// for now, don't maintain sorting when adding new info response servers
	m_sortedServers.Append( Num()-1 );
	if ( listGUI->IsConfigured( ) && !IsFiltered( server ) ) {
		GUIAdd( Num()-1, server );
	}
	if ( listGUI->GetSelection( NULL, 0 ) == ( Num()-1 ) ) {
		GUIUpdateSelected();
	}

	return index;
}
/*
================
idServerScan::ApplyFilter
================
*/
void idServerScan::ApplyFilter() {
	int i;
	networkServer_t serv;
	idStr s;
	listGUI->SetStateChanges( false );
	listGUI->Clear();
	for( i = m_sortAscending ? 0 : m_sortedServers.Num() - 1;
			m_sortAscending ? i < m_sortedServers.Num() : i >= 0;
			m_sortAscending ? i++ : i-- ) {
		serv = ( *this )[m_sortedServers[i]];
		if( !IsFiltered( serv ) ) {
			GUIAdd( m_sortedServers[i], serv );
		}
	}
	GUIUpdateSelected();
	listGUI->SetStateChanges( true );
}