Пример #1
0
    bool IsLocalHost(uLink.HostData hostData)
    {
        if (null != hostData)
        {
            try
            {
                IPAddress[] hostIPs  = Dns.GetHostAddresses(hostData.ipAddress);
                IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());

                foreach (IPAddress hostIP in hostIPs)
                {
                    if (IPAddress.IsLoopback(hostIP))
                    {
                        return(true);
                    }

                    foreach (IPAddress localIP in localIPs)
                    {
                        if (hostIP.Equals(localIP))
                        {
                            return(true);
                        }
                    }
                }
            }
            catch
            {
            }
        }

        return(false);
    }
Пример #2
0
 public static void Connect(uLink.HostData host, string password, params object[] objs)
 {
     if (uLink.Network.status == uLink.NetworkStatus.Disconnected)
     {
         uLink.Network.Connect(host, password, objs);
     }
 }
Пример #3
0
    void ConnectToServer(uLink.HostData hostData, int joinRequestId = 0)
    {
        Game.Instance.StartNewMultiplayerGame(hostData, joinRequestId);

        isConnectingToServer    = true;
        selectedServerEndpoint  = hostData.internalEndpoint;
        failedToConnectToServer = false;
    }
Пример #4
0
    void UpdateHostLine(int index, uLink.HostData data)
    {
        if (PlayerControlsDrone.Enabled)
        {
            if (!isConnectingToServer || failedToConnectToServer)
            {
                if (uLink.Network.status != uLink.NetworkStatus.Connected && uLink.Network.status != uLink.NetworkStatus.Connecting)
                {
                    if (data.externalIP == PlayerControlsDrone.DesiredIP)
                    {
                        ConnectToServer(data);
                    }
                }
            }
        }

        if (index < 0 || index >= linesGui.Length)
        {
            return;
        }

        //Debug.Log("UpdateServerLine " + index);
        ServerLineGui line = linesGui[index];

        if (line != null)
        {
            if (!line.button.Widget.IsVisible())
            {
                ShowServerLine(index);
            }

            //We have no server name but ip:port is a good identifier and a very usefull information
            line.labelServerName.SetNewText(data.ipAddress + ":" + data.port);

            //IP
            line.labelMapName.SetNewText(data.gameName);
            line.labelMode.SetNewText(data.gameMode);

            //Show ping times only for game server hosts found via the master server, not LAN servers. LAN server ping times might have a bug in uLink.
            if (m_ServerListType == E_ServerListType.Lobby)
            {
                //Prints the ping to the master server, not the actual game server. This is OK as long as the
                //game servers and the master server is hosted in the same datacenter.
                //TODO: remove this GUI column from the list of game servers and put the ping value on top of the screen
                //becuse the ping value will be identiacal for all game servers in the same data center
                line.labelPing.SetNewText(((int)(uLink.MasterServer.ping * 1000)).ToString());
            }
            else
            {
                line.labelPing.Clear();
            }
            line.labelPlayers.SetNewText(data.connectedPlayers.ToString());

            line.hostData = data;
        }
    }
Пример #5
0
    public void StartNewMultiplayerGame(uLink.HostData hostData,
                                        int joinRequestId,
                                        Client.ConnectToServerFailedDelegate onConnectToServerFailed = null)
    {
        _GameType = E_GameType.Multiplayer;

        Instantiate(Client);

        Client.Instance.ConnectToServer(hostData, joinRequestId, onConnectToServerFailed);
    }
Пример #6
0
    public void Connect(uLink.HostData hostData, string playerName)
    {
        isRedirected = false;

        uLink.NetworkConnectionError error = uLink.Network.Connect(hostData, "", playerName);

        if (error != uLink.NetworkConnectionError.NoError)
        {
            SendMessage("uLink_OnFailedToConnect", error);
        }
    }
        public HostData[] ReadHostDatas()
        {
            uint length = _buffer.ReadVariableUInt32();
            var  values = new HostData[length];

            for (int i = 0; i < length; ++i)
            {
                values[i] = ReadHostData();
            }

            return(values);
        }
    void Connect(uLink.HostData host)
    {
        isRedirected = false;

        if (inputName)
        {
            uLink.Network.Connect(host, "", playerName);
        }
        else
        {
            uLink.Network.Connect(host);
        }
    }
        internal void _UnconnectedRPCKnownHostResponse(LocalHostData localData, double localTime, NetworkEndPoint endpoint)
        {
            if (!_knownHosts.ContainsKey(endpoint))
            {
                return;
            }

            var ping = (int)NetworkTime._GetElapsedTimeInMillis(localTime);
            var data = new HostData(localData, endpoint, ping);

            _knownHosts[endpoint] = data;

            _MasterNotifyEvent(MasterServerEvent.KnownHostDataReceived);
        }
Пример #10
0
    public void ConnectToServer(uLink.HostData hostData, int joinRequestId, ConnectToServerFailedDelegate onConnectToServerFailed)
    {
        Printf("Connecting to lan server");

        PrepareNetworkConnection(onConnectToServerFailed);

        uLink.Network.Connect(hostData.internalEndpoint,
                              "",
                              NetUtils.CurrentVersion.ToString(),
                              CloudUser.instance.primaryKey,
                              CloudUser.instance.nickName,
                              (int)Application.platform,
                              joinRequestId);

        uLinkStatisticsGUI.HACK_ConnectedServerEndpoint = hostData.internalEndpoint;
    }
        internal void _UnconnectedRPCDiscoverHostResponse(LocalHostData localData, double localTime, NetworkEndPoint endpoint)
        {
            var ping = (int)NetworkTime._GetElapsedTimeInMillis(localTime);
            var data = new HostData(localData, endpoint, ping);

            if (_discoveredHosts.ContainsKey(endpoint))
            {
                _discoveredHosts[endpoint] = data;
            }
            else
            {
                _discoveredHosts.Add(endpoint, data);
            }

            _MasterNotifyEvent(MasterServerEvent.LocalHostDiscovered);
        }
Пример #12
0
    public virtual void AnalyseServer(uLink.HostData data, bool isLan)
    {
        try
        {
            IPAddress   = data.ipAddress;
            Port        = data.port;
            LimitedConn = data.playerLimit;
            CurConn     = data.connectedPlayers;
            Ping        = data.ping;
            ServerName  = data.gameName;
            UseProxy    = data.useProxy;
            IsLan       = isLan;

            string[] args = data.comment.Split(new char[] { ',' });

            int.TryParse(args[0], out ServerStatus);
            int.TryParse(args[1], out GameMode);
            int.TryParse(args[2], out GameType);
            ServerMasterName = MyServer.RecoverStr(args[3]);
            ServerVersion    = args[4];
            int.TryParse(args[5], out PasswordStatus);
            int.TryParse(args[6], out ServerID);
            long.TryParse(args[7], out ServerUID);

            if (GameMode == (int)Pathea.PeGameMgr.ESceneMode.Custom)
            {
                UID     = args[8];
                MapName = args[9];
            }
        }
        catch (Exception e)
        {
            if (LogFilter.logError)
            {
                Debug.LogWarningFormat("{0}\r\n{1}", e.Message, e.StackTrace);
            }
        }
    }
Пример #13
0
 /// <summary>
 /// Store location info for a favorite server (Known Host) in the client.
 /// </summary>
 /// <param name="data">The <see cref="uLink.HostData"/> of favorite server</param>
 /// <remarks>
 /// It is possible to store a separate list of known hosts (favorite servers) in the local uLink client.
 /// Use the API for Known Host Data in this class to build a feature for your users to
 /// store their favorite servers and access them easily
 /// when they try to reconnect to play the game again on the same server as before.
 /// </remarks>
 /// <seealso cref="PollKnownHostData"/>
 /// <seealso cref="RequestKnownHostData"/>
 /// <seealso cref="RemoveKnownHostData"/>
 /// <seealso cref="ClearKnownHosts"/>
 public static void AddKnownHostData(HostData data)
 {
     Network._singleton.AddKnownHostData(data);
 }
 public HostData(HostData data)
     : base(data)
 {
     externalEndpoint = data.externalEndpoint;
     ping             = data.ping;
 }
 public bool Equals(HostData other)
 {
     return(other != null && externalEndpoint.Equals(other.externalEndpoint));
 }
Пример #16
0
 public override void AnalyseServer(uLink.HostData data, bool isLan)
 {
     base.AnalyseServer(data, isLan);
     ProxyServer = data;
     UseProxy    = true;
 }
 public void AddKnownHostData(HostData data)
 {
     _knownHosts[data.externalEndpoint] = data;
 }
 public void WriteHostData(HostData value)
 {
     value._Write(_buffer);
 }