public void Pong(Guid clientId, ServerEventHandler callback)
        {
            Error error = new Error();

            error.Code = StatusCode.OK;

            m_job.Submit(() =>
            {
                Thread.Sleep(400);
                return(null);
            },
                         result =>
            {
                callback(error);

                RTTInfo rttInfo = m_pingTimer.Pong(clientId, () =>
                {
                    OnPong(error);
                });

                m_pingTimer.Ping(clientId);
                if (Ping != null)
                {
                    Ping(error, rttInfo);
                }
            });
        }
        public RTTInfo Pong(Guid clientId, Action initializedCallback)
        {
            PingInfo pingInfo = m_pingInfo.ContainsKey(clientId) ?
                                m_pingInfo[clientId] :
                                m_pingInfo[Guid.Empty]; //For debugging purposes. Should be removed later

            float interval = Time.realtimeSinceStartup - pingInfo.m_pingTime;

            pingInfo.m_intervals[pingInfo.m_index] = interval;
            pingInfo.m_index++;
            pingInfo.m_index %= pingInfo.m_intervals.Length;
            if (pingInfo.m_index == 0)
            {
                if (!pingInfo.m_isInitialized && m_pingInfo.Values.Where(pi => pi != pingInfo).All(pi => pi.m_isInitialized))
                {
                    initializedCallback();
                    pingInfo.m_isInitialized = true;
                }
            }


            RTTInfo rtt = new RTTInfo();

            rtt.RTT    = pingInfo.m_intervals.Average();
            rtt.RTTMax = m_pingInfo.Values.Select(pi => pi.m_intervals.Average()).Max();

            return(rtt);
        }
Exemplo n.º 3
0
        public void Pong(Guid clientId, ServerEventHandler callback)
        {
            Error error = new Error(StatusCode.OK);

            if (!m_clientIdToPlayers.ContainsKey(clientId))
            {
                error.Code = StatusCode.NotRegistered;
                callback(error);
                return;
            }

            callback(error);

            if (m_botControlManager != null)
            {
                m_botControlManager.Ping(clientId);
            }

            RTTInfo rttInfo = m_pingTimer.Pong(clientId, () => OnPingPongCompleted(error, clientId));

            m_pingTimer.Ping(clientId);
            if (Ping != null)
            {
                m_pingArgs.Arg     = rttInfo;
                m_pingArgs.Targets = new[] { clientId };
                Ping(error, m_pingArgs);
            }
        }
Exemplo n.º 4
0
        public RTTInfo Pong(Guid clientId, Action initializedCallback)
        {
            PingInfo pingInfo = m_pingInfo[clientId];

            float interval = m_time - pingInfo.m_pingTime;

            pingInfo.m_intervals[pingInfo.m_index] = interval;
            pingInfo.m_index++;
            pingInfo.m_index %= pingInfo.m_intervals.Length;
            if (pingInfo.m_index == 0)
            {
                if (!pingInfo.m_isInitialized && m_pingInfo.Values.Where(pi => pi != pingInfo).All(pi => pi.m_isInitialized))
                {
                    if (!m_initialized)
                    {
                        m_initialized = true;
                        initializedCallback();
                    }
                }
                pingInfo.m_isInitialized = true;
            }

            RTTInfo rtt = new RTTInfo();

            rtt.RTT    = pingInfo.m_intervals.Average();
            rtt.RTTMax = m_pingInfo.Values.Select(pi => pi.m_intervals.Average()).Max();

            return(rtt);
        }
Exemplo n.º 5
0
 private void OnPing(Error error, RTTInfo payload)
 {
     m_rtt.text = "RTT: " + Mathf.RoundToInt(payload.RTT / 1000.0f) + " ms";
     if (m_rttMax != null)
     {
         m_rttMax.text = "RTT MAX: " + Mathf.RoundToInt(payload.RTTMax / 1000.0f) + " ms";
     }
 }
Exemplo n.º 6
0
        private void OnEnginePing(Error error, RTTInfo payload)
        {
            if (m_engine.HasError(error))
            {
                m_notification.ShowError(error);
                return;
            }

            // Debug.Log("Engine Ping RTT " + payload.RTT + " RTT MAX " + payload.RTTMax);
        }
Exemplo n.º 7
0
        private void OnPing(Error error, RTTInfo payload)
        {
            m_rttInfo = payload;

            if (m_matchServer.HasError(error))
            {
                Error(error);
                m_matchServer.Disconnect();
                return;
            }

            if (Ping != null)
            {
                Ping(new Error(StatusCode.OK), payload);
            }

            m_matchServer.Pong(m_gSettings.ClientId, pongError =>
            {
                if (m_matchServer.HasError(pongError))
                {
                    Stopped(pongError);
                }
            });
        }