public bool TryGetRandomServer(out ServerInfoRaw serverInfo)
        {
            // Dumb de dumb. Is there a better way to do this in C# if I want to
            // be able to use 'out' without getting compile errors?
            serverInfo = new ServerInfoRaw();
            if (MasterListRaw == null)
            {
                return(false);
            }
            if (!(MasterListRaw.active_servers.Length > 0))
            {
                return(false);
            }
            int i = UnityEngine.Random.Range(0, MasterListRaw.active_servers.Length);

            serverInfo = MasterListRaw.active_servers[i];
            return(true);
        }
Esempio n. 2
0
    private void ConnectToExternalListedServer(ServerInfoRaw serverInfo)
    {
        TryingToConnect = true;
        // If it looks like it's coming from local LAN, try to connect to
		// localhost. It seems some routers (like mine) will not respect UPnP
		// port mappings if the origin is from within the local network, which
		// obviously makes playtesting locally kind of hard! Obviously this is
		// not a great solution, since you can't play a local LAN game on a
		// separate machine, but our current setup of using WAN/external IPs
		// only doesn't support that anyway.
        if (serverInfo.address == AddressFinder.ExternalAddress)
        {
            uLink.Network.Connect("127.0.0.1", Port);
            MessageLog.AddMessage("Connecting to 127.0.0.1");
        }
        else
        {
            uLink.Network.Connect( serverInfo.address, Port );
            MessageLog.AddMessage( "Connecting to " + serverInfo.address );
        }
    }
 public bool TryGetRandomServer( out ServerInfoRaw serverInfo )
 {
     // Dumb de dumb. Is there a better way to do this in C# if I want to
     // be able to use 'out' without getting compile errors?
     serverInfo = new ServerInfoRaw();
     if( MasterListRaw == null ) return false;
     if( !( MasterListRaw.active_servers.Length > 0 ) ) return false;
     int i = UnityEngine.Random.Range( 0, MasterListRaw.active_servers.Length );
     serverInfo = MasterListRaw.active_servers[i];
     return true;
 }