Beispiel #1
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 );
}