// HANDLERS

    /**
     * <summary> Quand on reçoit la liste des IPs des Match Server. </summary>
     */
    void OnMatchServersListReceived(BloodAndBileEngine.Networking.NetworkMessageInfo info, BloodAndBileEngine.Networking.NetworkMessages.IPListMessage message)
    {
        BloodAndBileEngine.Debugger.Log("Liste des Match Servers reçue !");
        MatchServerIPs = message.IPList;

        if (MatchServerIPs.Length > 0)
        {
            foreach (string IP in MatchServerIPs)
            {
                BloodAndBileEngine.Debugger.Log("--- " + IP);
            }

            IPsReceived      = true;
            MatchServerPings = new UnityEngine.Ping[MatchServerIPs.Length];
            for (int i = 0; i < MatchServerPings.Length; i++)
            {
                MatchServerPings[i] = new UnityEngine.Ping(MatchServerIPs[i]);
            }
        }
        else
        {
            BloodAndBileEngine.Debugger.Log("Pas de Match Servers !", UnityEngine.Color.red);
            // Retour au MainMenuState
            Client.ChangeState(new MainMenuState());
        }
    }
Exemplo n.º 2
0
    IEnumerator DoTestNetwork(Globals.TestNetDelegate del)
    {
        float testNetTimeout = 1;         // second
        float connectingTime = 0;

        // [220.181.111.85] is www.baidu.com ip address
        UnityEngine.Ping ping = new UnityEngine.Ping("220.181.111.85");
        while (!ping.isDone && connectingTime < testNetTimeout)
        {
            connectingTime += Time.deltaTime;
            yield return(0);
        }

        Debug.Log(ping.ip);
        Debug.Log(ping.time);

        bool isSuccessed = ping.isDone;

        ping.DestroyPing();
        if (null != del)
        {
            del(isSuccessed);
        }

        yield return(0);
    }
Exemplo n.º 3
0
    // Update is called once per frame
    public void Update()
    {
        timer += Time.deltaTime;

        if (east1.isDone)
        {
            pingEast1 = east1.time;
        }
        if (east2.isDone)
        {
            pingEast2 = east2.time;
        }
        if (timer >= pingInterval)
        {
            if (RealTimeClient.Instance.IsConnected())
            {
                BLEDebug.LogInfo("Connected");
                float[] playerPos        = { 1, 2, 3 };
                float   progressDistance = 10;
                RealTimeClient.Instance.UpdateStats(0, 0, playerPos, progressDistance);
            }
            //BLEDebug.LogInfo("East1 Ping" + pingEast1);
            //BLEDebug.LogInfo("East2 Ping" + pingEast2);
            east1 = new UnityEngine.Ping("3.208.0.0");
            east2 = new UnityEngine.Ping("3.14.0.0");
            timer = 0.0f;
        }
    }
Exemplo n.º 4
0
        /// <summary>
        /// Pings specific IP using <see cref="UnityEngine.Ping"/>.
        /// </summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        private IEnumerator UnityPing(string ip)
        {
            pingsCount++;

            var ping = new UnityEngine.Ping(ip);
            var time = 0.0f;

            //wait for response loop
            while (!ping.isDone)
            {
                time += Time.unscaledDeltaTime;
                //check timeout
                if (time > pingTimeout / 1000)
                {
                    break;
                }
                yield return(null);
            }

            pongsCount++;
            if (ping.time >= 0)
            {
                //saves correct IP
                availableIps.Add(ip);
                yield break;
            }
        }
Exemplo n.º 5
0
 // Start is called before the first frame update
 public void Start()
 {
     client = new HttpClient();
     ConnectClient();
     east1 = new UnityEngine.Ping("3.208.0.0");
     east2 = new UnityEngine.Ping("3.14.0.0");
 }
        private IEnumerator MonitorNetworkConnectivity(NetworkConnectivitySettings _settings)
        {
            NetworkConnectivitySettings.AndroidSettings _androidSettings = _settings.Android;

            string _pingAddress		= _settings.IPAddress;
            int _maxRetryCount		= _androidSettings.MaxRetryCount;
            float _dt				= _androidSettings.TimeGapBetweenPolling;
            float _timeOutPeriod	= _androidSettings.TimeOutPeriod;
            bool _connectedToNw		= IsConnected;

            while (true)
            {
                bool _nowConnected	= false;

                for (int _rIter = 0; _rIter < _maxRetryCount; _rIter++)
                {
                    Ping _ping			= new Ping(_pingAddress);
                    float  _elapsedTime	= 0f;

                    // Ping test
                    while (!_ping.isDone && _elapsedTime < _timeOutPeriod)
                    {
                        _elapsedTime	+= Time.deltaTime;

                        // Wait until next frame
                        yield return null;
                    }

                    // Ping request complted within timeout period, so we are connected to network
                    if (_ping.isDone && (_ping.time != -1) && _elapsedTime < _timeOutPeriod)
                    {
                        _nowConnected	= true;
                        break;
                    }
                }

                // Notify Manager about state change
                if (!_connectedToNw)
                {
                    if (_nowConnected)
                    {
                        _connectedToNw	= true;
                        URLReachabilityChange(_connectedToNw);
                    }
                }
                else
                {
                    if (!_nowConnected)
                    {
                        _connectedToNw	= false;
                        URLReachabilityChange(_connectedToNw);
                    }
                }

                // Wait
                yield return new WaitForSeconds(_dt);
            }
        }
Exemplo n.º 7
0
 static public int constructor(IntPtr l)
 {
     UnityEngine.Ping o;
     System.String    a1;
     checkType(l, 2, out a1);
     o = new UnityEngine.Ping(a1);
     pushObject(l, o);
     return(1);
 }
Exemplo n.º 8
0
 private void Ping()
 {
     try {
         ping = new UnityEngine.Ping(pingAddress);
     } catch (Exception e) {
         Debug.LogError("Exception pinging");
         InternetAvailable.internetAvailableStatic = false;
     }
 }
Exemplo n.º 9
0
        public void Shutdown()
        {
            if (m_Ping == null)
            {
                return;
            }

            m_Ping.DestroyPing();
            m_Ping = null;
        }
Exemplo n.º 10
0
    private System.Collections.IEnumerator createPinger(string ip, float timeout)
    {
#if !UNITY_WEBGL
        if (ip != myip)
        {
            UnityEngine.Ping ping  = new UnityEngine.Ping(ip);
            float            timer = 0;
            while (!ping.isDone && timer < timeout)
            {
                timer += Time.deltaTime;
                yield return(null);
            }
            if (ping.time != -1)
            {
                upCount++;
                string mac = null;
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
                mac = getMacByIp(ip);
#elif UNITY_ANDROID
                mac = AndroidUSBUtils.CurrentInstance.GetMacAddressQ(ip);
#endif
                string addit = "Unknown";
                if (idents != null && mac != null)
                {
                    string macLookup = getFirst3MacValues(mac.ToUpper());
                    if (hexToManufacturerHash.ContainsKey(macLookup))
                    {
                        addit = hexToManufacturerHash[macLookup];
                    }
                    if (addit.StartsWith("Nintendo", StringComparison.OrdinalIgnoreCase))
                    {
                        addit = "<color=red>" + addit + "</color>";
                    }
                    activeIP.Add(string.Format("IP: {0} Mfr: {1}", ip, addit));
                }
                else
                {
                    activeIP.Add(string.Format("IP: {0}", ip));
                }
            }
            ping.DestroyPing();
        }
        else
        {
            activeIP.Add(string.Format("IP: {0} (This device)", ip));
        }

        pingCount++;
        percentageDone.UpdateValue(pingCount / 255f);
#else
        yield return(null);
#endif
    }
Exemplo n.º 11
0
 static public int DestroyPing(IntPtr l)
 {
     try{
         UnityEngine.Ping self = (UnityEngine.Ping)checkSelf(l);
         self.DestroyPing();
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Exemplo n.º 12
0
 static public int DestroyPing(IntPtr l)
 {
     try {
         UnityEngine.Ping self = (UnityEngine.Ping)checkSelf(l);
         self.DestroyPing();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 13
0
 static public int get_ip(IntPtr l)
 {
     try {
         UnityEngine.Ping self = (UnityEngine.Ping)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.ip);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 14
0
        public IEnumerator TestGetCurrentPingViaUnityPing()
        {
            var ip          = "8.8.8.8";
            var timeoutInMs = 1000;
            var ping        = new UnityEngine.Ping(ip);
            var timer       = Stopwatch.StartNew();

            while (!ping.isDone && timer.ElapsedMilliseconds < timeoutInMs)
            {
                yield return(new WaitForSeconds(0.01f));
            }
            Assert.IsTrue(ping.isDone);
            Assert.IsTrue(ping.time >= 0);
        }
Exemplo n.º 15
0
 static int DestroyPing(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.Ping obj = (UnityEngine.Ping)ToLua.CheckObject(L, 1, typeof(UnityEngine.Ping));
         obj.DestroyPing();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 16
0
 static public int constructor(IntPtr l)
 {
     LuaDLL.lua_remove(l, 1);
     UnityEngine.Ping o;
     if (matchType(l, 1, typeof(string)))
     {
         System.String a1;
         checkType(l, 1, out a1);
         o = new UnityEngine.Ping(a1);
         pushObject(l, o);
         return(1);
     }
     LuaDLL.luaL_error(l, "New object failed.");
     return(0);
 }
Exemplo n.º 17
0
        }                                      // Unity Trip Time

        public int SyncPing()
        {
            UnityEngine.Ping p = new UnityEngine.Ping(rawClient.serverEndPoint.Address.ToString());
            while (!p.isDone)
            {
            }
            UTT = p.time;

            System.Net.NetworkInformation.Ping      p2 = new System.Net.NetworkInformation.Ping();
            System.Net.NetworkInformation.PingReply r  = p2.Send(rawClient.serverEndPoint.Address);

            RTT = r.RoundtripTime;

            return((int)r.RoundtripTime);
        }
Exemplo n.º 18
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.Ping o;
         System.String    a1;
         checkType(l, 2, out a1);
         o = new UnityEngine.Ping(a1);
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 19
0
    static int get_ip(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.Ping obj = (UnityEngine.Ping)o;
            string           ret = obj.ip;
            LuaDLL.lua_pushstring(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index ip on a nil value"));
        }
    }
Exemplo n.º 20
0
    static int get_time(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.Ping obj = (UnityEngine.Ping)o;
            int ret = obj.time;
            LuaDLL.lua_pushinteger(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index time on a nil value"));
        }
    }
Exemplo n.º 21
0
        private static IEnumerator PingUpdate(string endpoint)
        {
            var host = endpoint.Substring(0, endpoint.LastIndexOf(":"));
            var ping = new UnityEngine.Ping(host);

            var elapsedSecs = 0;

            do
            {
                elapsedSecs++;
                yield return(new WaitForSeconds(1f));
            } while (!ping.isDone && elapsedSecs < PingTimeoutinSec);

            if (NetworkServerList.Servers.TryGetValue(endpoint, out var server))
            {
                server.Ping = ping.isDone ? ping.time.ToString() : "∞";
            }
        }
Exemplo n.º 22
0
        // PRIVATE

        private IEnumerator RequestPingForAddressRoutine(string address, int timeout)
        {
            var  ping         = new UnityEngine.Ping(address);
            var  startingTime = Time.time;
            bool timeExceeded = false;

            while (!ping.isDone && !timeExceeded)
            {
                timeExceeded = (Time.time < startingTime + timeout);
                yield return(new WaitForEndOfFrame());
            }

            if (ping.isDone && OnPingUpdated != null)
            {
                Debug.LogFormat("Ping found for {0} : {1}", address, ping.time);
                OnPingUpdated.Invoke(address, ping.time);
            }
            else if (timeExceeded && OnPingFailed != null)
            {
                Debug.LogFormat("Ping failed for {0} !", address);
                OnPingFailed.Invoke(address);
            }
        }
Exemplo n.º 23
0
    static int _CreateUnityEngine_Ping(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1)
            {
                string           arg0 = ToLua.CheckString(L, 1);
                UnityEngine.Ping obj  = new UnityEngine.Ping(arg0);
                ToLua.PushSealed(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: UnityEngine.Ping.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    void LookForBestMatchServer()
    {
        CurrentSearchTime += UnityEngine.Time.deltaTime;
        if (CurrentSearchTime >= SearchTime)
        {
            UnityEngine.Ping bestPing = null;
            foreach (UnityEngine.Ping ping in MatchServerPings)
            {
                if (ping.isDone && (bestPing == null || ping.time > bestPing.time))
                {
                    bestPing = ping;
                }
            }

            if (bestPing != null)
            {
                BloodAndBileEngine.Debugger.Log("Match server trouvé ! Connexion à l'IP : " + bestPing.ip + " ping : " + bestPing.time);
                Client.ChangeState(new MatchmakingState(bestPing.ip));
            }

            CurrentSearchTime = 0f;
        }
    }
Exemplo n.º 25
0
 public void Update(float elapseSeconds, float realElapseSeconds)
 {
     if (m_Ping == null || Application.internetReachability != NetworkReachability.NotReachable)
     {
         if (Time.unscaledTime >= m_NextPingTime)
         {
             m_Ping = new UnityEngine.Ping(m_IPString);
         }
     }
     else if (Application.internetReachability == NetworkReachability.NotReachable)
     {
         m_PingValue    = 0f;
         m_NextPingTime = Time.unscaledTime;
         m_Ping.DestroyPing();
         m_Ping = null;
     }
     else if (m_Ping.isDone)
     {
         m_PingValue    = m_Ping.time;
         m_NextPingTime = Time.unscaledTime + m_PingInterval;
         m_Ping.DestroyPing();
         m_Ping = null;
     }
 }
Exemplo n.º 26
0
 public Ping(string address)
 {
     this.m_Ptr = Ping.Internal_Create(address);
 }
 // This coroutine is only run in Edit Mode.
 IEnumerator PingCoroutine()
 {
     while( true )
     {
         Ping ping = new Ping( oscOut.ipAddress );
         yield return new WaitForSeconds( pingInterval );
         //Debug.Log( "Ping time " + ping.time );
         statusInEditMode = ( ping.isDone && ping.time >= 0 ) ? OscRemoteStatus.Connected : OscRemoteStatus.Disconnected;
     }
 }
Exemplo n.º 28
0
 public void DestroyPing()
 {
     this.m_Ptr = IntPtr.Zero;
     Ping.Internal_Destroy(this.m_Ptr);
 }
Exemplo n.º 29
0
 static public int get_ip(IntPtr l)
 {
     UnityEngine.Ping o = (UnityEngine.Ping)checkSelf(l);
     pushValue(l, o.ip);
     return(1);
 }
 public pingData()
 {
     ping = null;
     lastPing = -1;
     IP = null;
     host = String.Empty;
     done = true;
 }