예제 #1
0
        public bool MoveNext()
        {
            uint num = (uint)this.SPC;

            this.SPC = -1;
            switch (num)
            {
            case 0:
                this.region.Ping = PhotonPingManager.Attempts * PhotonPingManager.MaxMilliseconsPerPing;
                this.f__this.PingsRunning++;
                if (PhotonHandler.PingImplementation != typeof(PingNativeDynamic))
                {
                    this.ping__0 = (PhotonPing)Activator.CreateInstance(PhotonHandler.PingImplementation);
                    break;
                }
                UnityEngine.Debug.Log("Using constructor for new PingNativeDynamic()");
                this.ping__0 = new PingNativeDynamic();
                break;

            case 1:
                return(GotoOne());   //goto Label_01B9;

            //break;

            case 2:
                GotoTwo();    //goto Label_0268;
                break;

            case 3:
                this.SPC = -1;
                goto Label_02B3;

            default:
                goto Label_02B3;
            }
            this.rttSum__1          = 0f;
            this.replyCount__2      = 0;
            this.cleanIpOfRegion__3 = this.region.HostAndPort;
            this.indexOfColon__4    = this.cleanIpOfRegion__3.LastIndexOf(':');
            if (this.indexOfColon__4 > 1)
            {
                this.cleanIpOfRegion__3 = this.cleanIpOfRegion__3.Substring(0, this.indexOfColon__4);
            }
            this.cleanIpOfRegion__3 = PhotonPingManager.ResolveHost(this.cleanIpOfRegion__3);
            this.i__5 = 0;
            while (this.i__5 < PhotonPingManager.Attempts)
            {
                this.overtime__6 = false;
                this.sw__7       = new Stopwatch();
                this.sw__7.Start();
                try
                {
                    this.ping__0.StartPing(this.cleanIpOfRegion__3);
                }
                catch (Exception exception)
                {
                    this.e__8 = exception;
                    UnityEngine.Debug.Log("catched: " + this.e__8);
                    this.f__this.PingsRunning--;
                    break;
                }

                /*Label_01B9:
                 *  while (!this.ping__0.Done())
                 *  {
                 *      if (this.sw__7.ElapsedMilliseconds >= PhotonPingManager.MaxMilliseconsPerPing)
                 *      {
                 *          this.overtime__6 = true;
                 *          break;
                 *      }
                 *      this.Scurrent = 0;
                 *      this.SPC = 1;
                 *      goto Label_02B5;
                 *  }
                 *  this.rtt__9 = (int) this.sw__7.ElapsedMilliseconds;
                 *  if ((!PhotonPingManager.IgnoreInitialAttempt || (this.i__5 != 0)) && (this.ping__0.Successful && !this.overtime__6))
                 *  {
                 *      this.rttSum__1 += this.rtt__9;
                 *      this.replyCount__2++;
                 *      this.region.Ping = (int) (this.rttSum__1 / ((float) this.replyCount__2));
                 *  }
                 *  this.Scurrent = new WaitForSeconds(0.1f);
                 *  this.SPC = 2;*/
                //goto Label_02B5;
                //Label_0268:
                //this.i__5++;
            }
            this.f__this.PingsRunning--;
            this.Scurrent = null;
            this.SPC      = 3;
            goto Label_02B5;
Label_02B3:
            return(false);

Label_02B5:
            return(true);
        }
예제 #2
0
        public bool MoveNext()
        {
            uint num = (uint)SPC;

            SPC = -1;
            switch (num)
            {
            case 0:
                region.Ping = Attempts * MaxMilliseconsPerPing;
                f__this.PingsRunning++;
                if (PhotonHandler.PingImplementation != typeof(PingNativeDynamic))
                {
                    ping__0 = (PhotonPing)Activator.CreateInstance(PhotonHandler.PingImplementation);
                    break;
                }
                Debug.Log("Using constructor for new PingNativeDynamic()");
                ping__0 = new PingNativeDynamic();
                break;

            case 1:
            //goto Label_01B9;

            case 2:
            //goto Label_0265;

            case 3:
                SPC = -1;
                goto Label_02B0;

            default:
                goto Label_02B0;
            }
            rttSum__1          = 0f;
            replyCount__2      = 0;
            cleanIpOfRegion__3 = region.HostAndPort;
            indexOfColon__4    = cleanIpOfRegion__3.LastIndexOf(':');
            if (indexOfColon__4 > 1)
            {
                cleanIpOfRegion__3 = cleanIpOfRegion__3.Substring(0, indexOfColon__4);
            }
            cleanIpOfRegion__3 = ResolveHost(cleanIpOfRegion__3);
            i__5 = 0;
            while (i__5 < Attempts)
            {
                overtime__6 = false;
                sw__7       = new Stopwatch();
                sw__7.Start();
                try
                {
                    ping__0.StartPing(cleanIpOfRegion__3);
                }
                catch (Exception exception)
                {
                    e__8 = exception;
                    Debug.Log("catched: " + e__8);
                    f__this.PingsRunning--;
                    break;
                }
                while (!ping__0.Done())
                {
                    if (sw__7.ElapsedMilliseconds >= MaxMilliseconsPerPing)
                    {
                        overtime__6 = true;
                        break;
                    }
                    Scurrent = 0;
                    SPC      = 1;
                    goto Label_02B2;
                }
                rtt__9 = (int)sw__7.ElapsedMilliseconds;
                if ((!IgnoreInitialAttempt || (i__5 != 0)) && (ping__0.Successful && !overtime__6))
                {
                    rttSum__1 += rtt__9;
                    replyCount__2++;
                    region.Ping = (int)(rttSum__1 / replyCount__2);
                }
                Scurrent = new WaitForSeconds(0.1f);
                SPC      = 2;
                goto Label_02B2;
                //i__5++;
            }
            f__this.PingsRunning--;
            Scurrent = null;
            SPC      = 3;
            goto Label_02B2;
Label_02B0:
            return(false);

Label_02B2:
            return(true);
        }
    /// <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);
    }
예제 #4
0
        public bool MoveNext()
        {
            uint num = (uint)this.SPC;

            this.SPC = -1;
            switch (num)
            {
            case 0:
                this.region.Ping = PhotonPingManager.Attempts * PhotonPingManager.MaxMilliseconsPerPing;
                this.fthis.PingsRunning++;
                if (PhotonHandler.PingImplementation != typeof(PingNativeDynamic))
                {
                    this.ping0 = (PhotonPing)Activator.CreateInstance(PhotonHandler.PingImplementation);
                    break;
                }
                UnityEngine.Debug.Log("Using constructor for new PingNativeDynamic()");
                this.ping0 = new PingNativeDynamic();
                break;

            case 1:
            //goto Label_01B9;

            case 2:
            //goto Label_0265;

            case 3:
                this.SPC = -1;
                goto Label_02B0;

            default:
                goto Label_02B0;
            }
            this.rttSum1          = 0f;
            this.replyCount2      = 0;
            this.cleanIpOfRegion3 = this.region.HostAndPort;
            this.indexOfColon4    = this.cleanIpOfRegion3.LastIndexOf(':');
            if (this.indexOfColon4 > 1)
            {
                this.cleanIpOfRegion3 = this.cleanIpOfRegion3.Substring(0, this.indexOfColon4);
            }
            this.cleanIpOfRegion3 = PhotonPingManager.ResolveHost(this.cleanIpOfRegion3);
            this.i5 = 0;
            while (this.i5 < PhotonPingManager.Attempts)
            {
                this.overtime6 = false;
                this.sw7       = new Stopwatch();
                this.sw7.Start();
                try
                {
                    this.ping0.StartPing(this.cleanIpOfRegion3);
                }
                catch (Exception exception)
                {
                    this.e8 = exception;
                    UnityEngine.Debug.Log("catched: " + this.e8);
                    this.fthis.PingsRunning--;
                    break;
                }
Label_01B9:
                while (!this.ping0.Done())
                {
                    if (this.sw7.ElapsedMilliseconds >= PhotonPingManager.MaxMilliseconsPerPing)
                    {
                        this.overtime6 = true;
                        break;
                    }
                    this.Scurrent = 0;
                    this.SPC      = 1;
                    goto Label_02B2;
                }
                this.rtt9 = (int)this.sw7.ElapsedMilliseconds;
                if ((!PhotonPingManager.IgnoreInitialAttempt || (this.i5 != 0)) && (this.ping0.Successful && !this.overtime6))
                {
                    this.rttSum1 += this.rtt9;
                    this.replyCount2++;
                    this.region.Ping = (int)(this.rttSum1 / ((float)this.replyCount2));
                }
                this.Scurrent = new WaitForSeconds(0.1f);
                this.SPC      = 2;
                goto Label_02B2;
Label_0265:
                this.i5++;
            }
            this.fthis.PingsRunning--;
            this.Scurrent = null;
            this.SPC      = 3;
            goto Label_02B2;
Label_02B0:
            return(false);

Label_02B2:
            return(true);
        }
예제 #5
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;
    }