Пример #1
0
    void Awake()
    {
        hostFilter = new uLink.HostDataFilter();

        // currently the comment field is used to filter out non-compatible servers...
        hostFilter.comment = NetUtils.CurrentVersion.ToString();

        //TODO ::
        AwakeSelectDelegates();
    }
        public HostData[] PollAndDiscoverLocalHosts(HostDataFilter filter, int remoteStartPort, int remoteEndPort, float discoverInterval)
        {
            if (!Single.IsInfinity(discoverInterval))
            {
                var nextRequest = _timeOfDiscoveryRequest + discoverInterval;
                if (nextRequest <= NetworkTime.localTime)
                {
                    DiscoverLocalHosts(filter, remoteStartPort, remoteEndPort);
                }
            }

            return(PollDiscoveredHosts());
        }
        public HostData[] PollAndRequestHostList(HostDataFilter filter, float requestInterval)
        {
            if (!Single.IsInfinity(requestInterval))
            {
                var nextRequest = _timeOfHostListRequest + requestInterval;
                if (nextRequest <= NetworkTime.localTime)
                {
                    RequestHostList(filter);
                }
            }

            return(PollHostList());
        }
Пример #4
0
 public bool Equals(HostDataFilter other)
 {
     return(other != null &&
            String.IsNullOrEmpty(gameType) ? String.IsNullOrEmpty(other.gameType) : gameType == other.gameType &&
            String.IsNullOrEmpty(gameName) ? String.IsNullOrEmpty(other.gameName) : gameName == other.gameName &&
            String.IsNullOrEmpty(gameMode) ? String.IsNullOrEmpty(other.gameMode) : gameMode == other.gameMode &&
            String.IsNullOrEmpty(gameLevel) ? String.IsNullOrEmpty(other.gameLevel) : gameLevel == other.gameLevel &&
            connectedPlayers.Match(other.connectedPlayers.value) &&
            playerLimit.Match(other.playerLimit.value) &&
            passwordProtected == other.passwordProtected &&
            dedicatedServer == other.dedicatedServer &&
            useNat == other.useNat &&
            useProxy == other.useProxy &&
            String.IsNullOrEmpty(comment) ? String.IsNullOrEmpty(other.comment) : comment == other.comment &&
            String.IsNullOrEmpty(platform) ? String.IsNullOrEmpty(other.platform) : platform == other.platform);
 }
        public void DiscoverLocalHosts(HostDataFilter filter, int remoteStartPort, int remoteEndPort)
        {
            if (remoteEndPort - remoteStartPort >= 20)
            {
                Log.Warning(NetworkLogFlags.MasterServer, "Sending broadcast packets on more than 20 ports (with frequent interval) to discover local hosts, may cause some routers to block UDP traffic or behave undesirably.");
            }

            _timeOfDiscoveryRequest = NetworkTime.localTime;

            for (int port = remoteStartPort; port <= remoteEndPort; port++)
            {
                var msg = new UnconnectedMessage(UnconnectedMessage.InternalCode.DiscoverHostRequest);
                msg.stream.WriteHostDataFilter(filter);
                msg.stream.WriteDouble(NetworkTime.localTime);

                var broadcast = new NetworkEndPoint(IPAddress.Broadcast, port);
                _SendUnconnectedRPC(msg, broadcast);
            }
        }
        public void RequestHostList(HostDataFilter filter)
        {
            _timeOfHostListRequest = NetworkTime.localTime;

            _MasterConnect();

            var msg = new NetworkMasterMessage(NetworkMasterMessage.InternalCode.HostListRequest);

            msg.stream.WriteHostDataFilter(filter);

            if (_master.Status == NetConnectionStatus.Connected)
            {
                _master.SendMessage(msg.stream._buffer, NetChannel.ReliableInOrder1);
            }
            else
            {
                _pendingMessages[(int)NetworkMasterMessage.InternalCode.HostListRequest] = msg;
            }
        }
Пример #7
0
 /// <summary>
 /// Returns the latest host list discovered on the LAN and makes a new host list request
 /// if the last request is older than requestInterval.
 /// </summary>
 /// <param name="filter">The <see cref="uLink.HostDataFilter"/> for finding only specific game servers</param>
 /// <param name="remoteStartPort">The lowest port number of the game servers</param>
 /// <param name="remoteEndPort">The highest port number of the game servers</param>
 /// <param name="discoverInterval">The minimum time between message broadcastings</param>
 /// <remarks>
 /// This method is convenient to run in Update() in a client. This way you can write one code line to
 /// always get the latest host list and also make sure the list is refreshed with a specified interval.
 /// If you try to discover hosts sooner than specified interval, no message will be broadcasted.
 /// </remarks>
 public static HostData[] PollAndDiscoverLocalHosts(HostDataFilter filter, int remoteStartPort, int remoteEndPort, float discoverInterval)
 {
     return(Network._singleton.PollAndDiscoverLocalHosts(filter, remoteStartPort, remoteEndPort, discoverInterval));
 }
Пример #8
0
 /// <summary>
 /// Request a host list of all available game servers in the LAN using a filter.
 /// </summary>
 /// <param name="filter">The <see cref="uLink.HostDataFilter"/> for finding only specific game servers</param>
 /// <param name="remoteStartPort">The lowest port number of the game servers</param>
 /// <param name="remoteEndPort">The highest port number of the game servers</param>
 /// <remarks>
 /// This request is asynchronous and it is sent to the IPAdress <see cref="System.Net.IPAddress.Broadcast"/>.
 /// uLink collects all the answers from running game servers in the LAN and stores the result internally.
 /// The request will be sent to all UDP ports beginning with remoteStartPort and ending with remoteEndPort.
 /// The usage of several ports is necessary when there are several game servers hosted on a single machine,
 /// since the game servers on one machine need one unique port each.
 /// This method does not return the result. Instead, the result
 /// list is populated when results come in one by one, and the result is available through
 /// uLink.MasterServer.<see cref="PollDiscoveredHosts"/>.
 /// </remarks>
 /// <seealso cref="PollDiscoveredHosts"/>
 /// <seealso cref="PollAndDiscoverLocalHosts"/>
 public static void DiscoverLocalHosts(HostDataFilter filter, int remoteStartPort, int remoteEndPort)
 {
     Network._singleton.DiscoverLocalHosts(filter, remoteStartPort, remoteEndPort);
 }
Пример #9
0
 /// <summary>
 /// Returns the latest host list received from the MasterServer and makes a new host list request
 /// if the last request is older than requestInterval.
 /// </summary>
 /// <param name="filter">The <see cref="uLink.HostDataFilter"/> of game servers</param>
 /// <param name="requestInterval">The minimum time between host list request</param>
 /// <remarks>
 /// This method is convenient to run in Update() in a client. This way you can write one code line to
 /// always get the latest host list and also make sure the list is refreshed with a specified interval.
 /// If you request host list sooner than specified interval, no request will be sent.
 /// </remarks>
 public static HostData[] PollAndRequestHostList(HostDataFilter filter, float requestInterval)
 {
     return(Network._singleton.PollAndRequestHostList(filter, requestInterval));
 }
Пример #10
0
 /// <summary>
 /// Request a host list from the master server that matches a specific filter.
 /// </summary>
 /// <param name="filter">The <see cref="uLink.HostDataFilter"/> of game servers</param>
 /// <example>
 /// <code>
 /// void Awake()
 /// {
 ///    // Make sure list is empty and request a new list
 ///    MasterServer.ClearHostList();
 ///    HostDataFilter filter = new HostDataFilter("uLinkGame");
 ///    MasterServer.RequestHostList(filter);
 /// }
 ///
 /// void Update()
 /// {
 ///    // If any hosts were received, display game name, the clear host list again
 ///    if (MasterServer.PollHostList().length != 0) {
 ///       HostData[] hostData = MasterServer.PollHostList();
 ///       for (int i = 0; i < hostData.length; i++) {
 ///       Debug.Log("Game name: " + hostData[i].gameName);
 ///    }
 ///       MasterServer.ClearHostList();
 ///    }
 /// }
 /// </code>
 /// </example>
 public static void RequestHostList(HostDataFilter filter)
 {
     Network._singleton.RequestHostList(filter);
 }
 public void WriteHostDataFilter(HostDataFilter value)
 {
     value._Write(_buffer);
 }
 public void DiscoverLocalHosts(HostDataFilter filter, int remotePort)
 {
     DiscoverLocalHosts(filter, remotePort, remotePort);
 }