Exemplo n.º 1
0
    /// <remarks>
    /// Affected by frame-rate of app, as this Coroutine checks the socket for a result once per frame.
    /// </remarks>
    public IEnumerator PingSocket(Region region)
    {
        region.Ping = Attempts * MaxMilliseconsPerPing;

        this.PingsRunning++;
        PhotonPing ping;

        if (PhotonHandler.PingImplementation == typeof(PingNativeDynamic))
        {
            Debug.Log("Using constructor for new PingNativeDynamic()"); // it seems on android, the Activator can't find the default Constructor
            ping = new PingNativeDynamic();
        }
        else if (PhotonHandler.PingImplementation == typeof(PingMono))
        {
            ping = new PingMono(); // using this type explicitly saves it from IL2CPP bytecode stripping
        }
        #if UNITY_WEBGL
        else if (PhotonHandler.PingImplementation == typeof(PingHttp))
        {
            ping = new PingHttp();
        }
        #endif
        else
        {
            ping = (PhotonPing)Activator.CreateInstance(PhotonHandler.PingImplementation);
        }

        //Debug.Log(region);

        float rttSum     = 0.0f;
        int   replyCount = 0;

        // all addresses for Photon region servers will contain a :port ending. this needs to be removed first.
        // PhotonPing.StartPing() requires a plain (IP) address without port or protocol-prefix (on all but Windows 8.1 and WebGL platforms).

        string regionAddress = region.HostAndPort;
        int    indexOfColon  = regionAddress.LastIndexOf(':');
        if (indexOfColon > 1)
        {
            regionAddress = regionAddress.Substring(0, indexOfColon);
        }

        regionAddress = ResolveHost(regionAddress);

        for (int i = 0; i < Attempts; i++)
        {
            bool      overtime = false;
            Stopwatch sw       = new Stopwatch();
            sw.Start();

            try
            {
                ping.StartPing(regionAddress);
            }
            catch (Exception e)
            {
                Debug.Log("catched: " + e);
                this.PingsRunning--;
                break;
            }


            while (!ping.Done())
            {
                if (sw.ElapsedMilliseconds >= MaxMilliseconsPerPing)
                {
                    overtime = true;
                    break;
                }
                yield return(0); // keep this loop tight, to avoid adding local lag to rtt.
            }
            int rtt = (int)sw.ElapsedMilliseconds;


            if (IgnoreInitialAttempt && i == 0)
            {
                // do nothing.
            }
            else if (ping.Successful && !overtime)
            {
                rttSum += rtt;
                replyCount++;
                region.Ping = (int)((rttSum) / replyCount);
                //Debug.Log("region " + region.Code + " RTT " + region.Ping + " success: " + ping.Successful + " over: " + overtime);
            }

            yield return(new WaitForSeconds(0.1f));
        }

        this.PingsRunning--;

        //Debug.Log("this.PingsRunning: " + this.PingsRunning + " this debug: " + ping.DebugString);
        yield return(null);
    }
Exemplo n.º 2
0
    /// <remarks>
    /// Affected by frame-rate of app, as this Coroutine checks the socket for a result once per frame.
    /// </remarks>
    public IEnumerator PingSocket(Region region)
    {
        region.Ping = Attempts * MaxMilliseconsPerPing;

        this.PingsRunning++;        // TODO: Add try-catch to make sure the PingsRunning are reduced at the end and that the lib does not crash the app
        PhotonPing ping;

        //Debug.Log("PhotonHandler.PingImplementation " + PhotonHandler.PingImplementation);
        if (PhotonHandler.PingImplementation == typeof(PingNativeDynamic))
        {
            Debug.Log("Using constructor for new PingNativeDynamic()"); // it seems on android, the Activator can't find the default Constructor
            ping = new PingNativeDynamic();
        }
        else if (PhotonHandler.PingImplementation == typeof(PingMono))
        {
            ping = new PingMono();  // using this type explicitly saves it from IL2CPP bytecode stripping
        }
        else
        {
            ping = (PhotonPing)Activator.CreateInstance(PhotonHandler.PingImplementation);
        }

        //Debug.Log("Ping is: " + ping + " type " + ping.GetType());

        float rttSum     = 0.0f;
        int   replyCount = 0;


        // PhotonPing.StartPing() requires a plain IP address without port (on all but Windows 8 platforms).
        // So: remove port and do the DNS-resolving if needed
        string cleanIpOfRegion = region.HostAndPort;
        int    indexOfColon    = cleanIpOfRegion.LastIndexOf(':');

        if (indexOfColon > 1)
        {
            cleanIpOfRegion = cleanIpOfRegion.Substring(0, indexOfColon);
        }
        cleanIpOfRegion = ResolveHost(cleanIpOfRegion);
        //Debug.Log("Resolved and port-less IP is: " + cleanIpOfRegion);


        for (int i = 0; i < Attempts; i++)
        {
            bool      overtime = false;
            Stopwatch sw       = new Stopwatch();
            sw.Start();

            try
            {
                ping.StartPing(cleanIpOfRegion);
            }
            catch (Exception e)
            {
                Debug.Log("catched: " + e);
                this.PingsRunning--;
                break;
            }


            while (!ping.Done())
            {
                if (sw.ElapsedMilliseconds >= MaxMilliseconsPerPing)
                {
                    overtime = true;
                    break;
                }
                yield return(0); // keep this loop tight, to avoid adding local lag to rtt.
            }
            int rtt = (int)sw.ElapsedMilliseconds;


            if (IgnoreInitialAttempt && i == 0)
            {
                // do nothing.
            }
            else if (ping.Successful && !overtime)
            {
                rttSum += rtt;
                replyCount++;
                region.Ping = (int)((rttSum) / replyCount);
                //Debug.Log("region " + region.Code + " RTT " + region.Ping + " success: " + ping.Successful + " over: " + overtime);
            }

            yield return(new WaitForSeconds(0.1f));
        }

        this.PingsRunning--;

        //Debug.Log("this.PingsRunning: " + this.PingsRunning + " this debug: " + ping.DebugString);
        yield return(null);
    }
Exemplo n.º 3
0
    // Token: 0x06003DFA RID: 15866 RVA: 0x00138614 File Offset: 0x00136A14
    public IEnumerator PingSocket(Region region)
    {
        region.Ping = PhotonPingManager.Attempts * PhotonPingManager.MaxMilliseconsPerPing;
        this.PingsRunning++;
        PhotonPing ping;

        if (PhotonHandler.PingImplementation == typeof(PingNativeDynamic))
        {
            UnityEngine.Debug.Log("Using constructor for new PingNativeDynamic()");
            ping = new PingNativeDynamic();
        }
        else if (PhotonHandler.PingImplementation == typeof(PingMono))
        {
            ping = new PingMono();
        }
        else
        {
            ping = (PhotonPing)Activator.CreateInstance(PhotonHandler.PingImplementation);
        }
        float  rttSum        = 0f;
        int    replyCount    = 0;
        string regionAddress = region.HostAndPort;
        int    indexOfColon  = regionAddress.LastIndexOf(':');

        if (indexOfColon > 1)
        {
            regionAddress = regionAddress.Substring(0, indexOfColon);
        }
        regionAddress = PhotonPingManager.ResolveHost(regionAddress);
        for (int i = 0; i < PhotonPingManager.Attempts; i++)
        {
            bool      overtime = false;
            Stopwatch sw       = new Stopwatch();
            sw.Start();
            try
            {
                ping.StartPing(regionAddress);
            }
            catch (Exception arg)
            {
                UnityEngine.Debug.Log("catched: " + arg);
                this.PingsRunning--;
                break;
            }
            while (!ping.Done())
            {
                if (sw.ElapsedMilliseconds >= (long)PhotonPingManager.MaxMilliseconsPerPing)
                {
                    overtime = true;
                    break;
                }
                yield return(0);
            }
            int rtt = (int)sw.ElapsedMilliseconds;
            if (!PhotonPingManager.IgnoreInitialAttempt || i != 0)
            {
                if (ping.Successful && !overtime)
                {
                    rttSum += (float)rtt;
                    replyCount++;
                    region.Ping = (int)(rttSum / (float)replyCount);
                }
            }
            yield return(new WaitForSeconds(0.1f));
        }
        this.PingsRunning--;
        yield return(null);

        yield break;
    }
    /// <remarks>
    /// Affected by frame-rate of app, as this Coroutine checks the socket for a result once per frame.
    /// </remarks>
    public IEnumerator PingSocket(Region region)
    {
        region.Ping = Attempts*MaxMilliseconsPerPing;

        this.PingsRunning++;        // TODO: Add try-catch to make sure the PingsRunning are reduced at the end and that the lib does not crash the app
        PhotonPing ping;
        //Debug.Log("PhotonHandler.PingImplementation " + PhotonHandler.PingImplementation);
        if (PhotonHandler.PingImplementation == typeof(PingNativeDynamic))
        {
            Debug.Log("Using constructor for new PingNativeDynamic()"); // it seems on android, the Activator can't find the default Constructor
            ping = new PingNativeDynamic();
        }
        else if (PhotonHandler.PingImplementation == typeof(PingMono))
        {
            ping = new PingMono();  // using this type explicitly saves it from IL2CPP bytecode stripping
        }
        else
        {
            ping = (PhotonPing) Activator.CreateInstance(PhotonHandler.PingImplementation);
        }

        //Debug.Log("Ping is: " + ping + " type " + ping.GetType());

        float rttSum = 0.0f;
        int replyCount = 0;


        // PhotonPing.StartPing() requires a plain IP address without port (on all but Windows 8 platforms).
        // So: remove port and do the DNS-resolving if needed
        string cleanIpOfRegion = region.HostAndPort;
        int indexOfColon = cleanIpOfRegion.LastIndexOf(':');
        if (indexOfColon > 1)
        {
            cleanIpOfRegion = cleanIpOfRegion.Substring(0, indexOfColon);
        }
        cleanIpOfRegion = ResolveHost(cleanIpOfRegion);
        //Debug.Log("Resolved and port-less IP is: " + cleanIpOfRegion);


        for (int i = 0; i < Attempts; i++)
        {
            bool overtime = false;
            Stopwatch sw = new Stopwatch();
            sw.Start();

            try
            {
                ping.StartPing(cleanIpOfRegion);
            }
            catch (Exception e)
            {
                Debug.Log("catched: " + e);
                this.PingsRunning--;
                break;
            }


            while (!ping.Done())
            {
                if (sw.ElapsedMilliseconds >= MaxMilliseconsPerPing)
                {
                    overtime = true;
                    break;
                }
                yield return 0; // keep this loop tight, to avoid adding local lag to rtt.
            }
            int rtt = (int)sw.ElapsedMilliseconds;


            if (IgnoreInitialAttempt && i == 0)
            {
                // do nothing.
            }
            else if (ping.Successful && !overtime)
            {
                rttSum += rtt;
                replyCount++;
                region.Ping = (int)((rttSum) / replyCount);
                //Debug.Log("region " + region.Code + " RTT " + region.Ping + " success: " + ping.Successful + " over: " + overtime);
            }

            yield return new WaitForSeconds(0.1f);
        }

        this.PingsRunning--;

        //Debug.Log("this.PingsRunning: " + this.PingsRunning + " this debug: " + ping.DebugString);
        yield return null;
    }
    /// <remarks>
    /// Affected by frame-rate of app, as this Coroutine checks the socket for a result once per frame.
    /// </remarks>
    public IEnumerator PingSocket(Region region)
    {
        region.Ping = Attempts * MaxMilliseconsPerPing;

        this.PingsRunning++; // TODO: Add try-catch to make sure the PingsRunning are reduced at the end and that the lib does not crash the app
        PhotonPing ping = null;

        #if NATIVE_SOCKETS && NATIVE_SOCKETS_STATIC
        if (PhotonHandler.PingImplementation == typeof(PingNativeStatic))
        {
            Debug.Log("Using constructor for new PingNativeStatic()"); // it seems on Switch, the Activator can't find the default Constructor
            ping = new PingNativeStatic();
        }
        #elif NATIVE_SOCKETS
        if (PhotonHandler.PingImplementation == typeof(PingNativeDynamic))
        {
            Debug.Log("Using constructor for new PingNativeDynamic()"); // it seems on Android, the Activator can't find the default Constructor
            ping = new PingNativeDynamic();
        }
        #elif UNITY_WEBGL
        if (PhotonHandler.PingImplementation == typeof(PingHttp))
        {
            ping = new PingHttp();
        }
        #elif NETFX_CORE
        ping = new PingWindowsStore();
        #else
        if (PhotonHandler.PingImplementation == typeof(PingMono))
        {
            ping = new PingMono(); // using this type explicitly saves it from IL2CPP bytecode stripping
        }
        #endif

        if (ping == null)
        {
            ping = (PhotonPing)Activator.CreateInstance(PhotonHandler.PingImplementation);
        }

        //Debug.Log(region);

        float rttSum     = 0.0f;
        int   replyCount = 0;

        // all addresses for Photon region servers will contain a :port ending. this needs to be removed first.
        // PhotonPing.StartPing() requires a plain (IP) address without port or protocol-prefix (on all but Windows 8.1 and WebGL platforms).

        string regionAddress = region.HostAndPort;
        int    indexOfColon  = regionAddress.LastIndexOf(':');
        if (indexOfColon > 1)
        {
            regionAddress = regionAddress.Substring(0, indexOfColon);
        }

        // we also need to remove the protocol or Dns.GetHostAddresses(hostName) will throw an exception
        // This is for xBox One for example.
        int indexOfProtocol = regionAddress.IndexOf(PhotonPingManager.wssProtocolString);
        if (indexOfProtocol > -1)
        {
            regionAddress = regionAddress.Substring(indexOfProtocol + PhotonPingManager.wssProtocolString.Length);
        }
        regionAddress = ResolveHost(regionAddress);

        //Debug.Log("Ping Debug - PhotonHandler.PingImplementation: " + PhotonHandler.PingImplementation + " ping.GetType():" + ping.GetType() + " regionAddress:" + regionAddress);
        for (int i = 0; i < Attempts; i++)
        {
            bool      overtime = false;
            Stopwatch sw       = new Stopwatch();
            sw.Start();

            try
            {
                ping.StartPing(regionAddress);
            }
            catch (Exception e)
            {
                Debug.Log("catched: " + e);
                this.PingsRunning--;
                break;
            }


            while (!ping.Done())
            {
                if (sw.ElapsedMilliseconds >= MaxMilliseconsPerPing)
                {
                    overtime = true;
                    break;
                }
                yield return(0); // keep this loop tight, to avoid adding local lag to rtt.
            }
            int rtt = (int)sw.ElapsedMilliseconds;


            if (IgnoreInitialAttempt && i == 0)
            {
                // do nothing.
            }
            else if (ping.Successful && !overtime)
            {
                rttSum += rtt;
                replyCount++;
                region.Ping = (int)((rttSum) / replyCount);
                //Debug.Log("region " + region.Code + " RTT " + region.Ping + " success: " + ping.Successful + " over: " + overtime);
            }

            yield return(new WaitForSeconds(0.1f));
        }
        ping.Dispose();

        this.PingsRunning--;

        //Debug.Log("this.PingsRunning: " + this.PingsRunning + " this debug: " + ping.DebugString);
        yield return(null);
    }
Exemplo n.º 6
0
    // Token: 0x0600050B RID: 1291 RVA: 0x0001DC5F File Offset: 0x0001BE5F
    public IEnumerator PingSocket(Region region)
    {
        region.Ping = PhotonPingManager.Attempts * PhotonPingManager.MaxMilliseconsPerPing;
        this.PingsRunning++;
        PhotonPing ping = null;

        if (PhotonHandler.PingImplementation == typeof(PingMono))
        {
            ping = new PingMono();
        }
        if (ping == null)
        {
            ping = (PhotonPing)Activator.CreateInstance(PhotonHandler.PingImplementation);
        }
        float  rttSum        = 0f;
        int    replyCount    = 0;
        string regionAddress = region.HostAndPort;
        int    num           = regionAddress.LastIndexOf(':');

        if (num > 1)
        {
            regionAddress = regionAddress.Substring(0, num);
        }
        int num2 = regionAddress.IndexOf("wss://");

        if (num2 > -1)
        {
            regionAddress = regionAddress.Substring(num2 + "wss://".Length);
        }
        regionAddress = PhotonPingManager.ResolveHost(regionAddress);
        int i = 0;

        while (i < PhotonPingManager.Attempts)
        {
            bool      overtime = false;
            Stopwatch sw       = new Stopwatch();
            sw.Start();
            try
            {
                ping.StartPing(regionAddress);
                goto IL_1BC;
            }
            catch (Exception arg)
            {
                Debug.Log("catched: " + arg);
                this.PingsRunning--;
                break;
            }
            goto IL_184;
IL_1C9:
            int num3 = (int)sw.ElapsedMilliseconds;
            int num4;
            if ((!PhotonPingManager.IgnoreInitialAttempt || i != 0) && ping.Successful && !overtime)
            {
                rttSum     += (float)num3;
                num4        = replyCount;
                replyCount  = num4 + 1;
                region.Ping = (int)(rttSum / (float)replyCount);
            }
            yield return(new WaitForSeconds(0.1f));

            sw   = null;
            num4 = i;
            i    = num4 + 1;
            continue;
IL_184:
            if (sw.ElapsedMilliseconds >= (long)PhotonPingManager.MaxMilliseconsPerPing)
            {
                overtime = true;
                goto IL_1C9;
            }
            yield return(0);

IL_1BC:
            if (ping.Done())
            {
                goto IL_1C9;
            }
            goto IL_184;
        }
        ping.Dispose();
        this.PingsRunning--;
        yield return(null);

        yield break;
    }