コード例 #1
0
        IEnumerator DoPingAsync()
        {
            // How long to run the ping
            var pingSeconds = m_HeadlessRunTimeMs / 1000f;

            Debug.Log($"Pinging remote server for {pingSeconds} seconds...");

            // Start new ping client
            var udpPinger = new UdpPingWrapper();
            var timer     = Stopwatch.StartNew();

            try
            {
                udpPinger.Start(m_CustomIp);

                while (timer.ElapsedMilliseconds < m_HeadlessRunTimeMs)
                {
                    udpPinger.Update();
                    yield return(null);
                }

                // Dump ping stats before we dispose of the client
                Debug.Log(udpPinger.GetStats());
            }
            finally
            {
                udpPinger.Dispose();
            }
        }
コード例 #2
0
        IEnumerator HeadlessClientLifecycle()
        {
            if (m_HeadlessShouldQos)
            {
                yield return(DoQosAsync());
            }

            if (m_HeadlessShouldMatchmake)
            {
                yield return(DoMatchmakingAsync());
            }

            if (m_HeadlessShouldPingServer)
            {
                yield return(DoPingAsync());
            }

            if (m_HeadlessShouldTerminateServer)
            {
                UdpPingWrapper.TryTerminateRemoteServer(m_CustomIp);
            }

            Debug.Log("Finished headless mode tasks, shutting down...");
            ShutDown(ExitCode.Ok);
        }
コード例 #3
0
        // Start is called before the first frame update
        void StartNewPingClient()
        {
            if (string.IsNullOrEmpty(m_PingServerEndpoint))
            {
                Debug.LogWarning("Cannot start pinging - No ping server endpoint was entered");
                return;
            }

            if (m_UdpPing != null)
            {
                Debug.LogWarning("Cannot start pinging - Pinging already in progress");
                return;
            }

            Debug.Log("Starting pinging...");

            try
            {
                m_UdpPing = new UdpPingWrapper();
                m_UdpPing.Start(m_PingServerEndpoint);
                m_State = MatchmakingState.ServerPing;
            }
            catch (Exception e)
            {
                Debug.LogError("Cannot start pinging due to exception - " + e.Message);
                m_UdpPing?.Dispose();
                m_UdpPing = null;
            }
        }
コード例 #4
0
        void ShutdownPingClient()
        {
            if (m_UdpPing == null)
            {
                Debug.LogWarning("Cannot shut down ping client - no pinging in progress");
                return;
            }

            Debug.Log("Shutting down ping client...");
            m_UdpPing.Dispose();
            m_UdpPing = null;
            m_State   = MatchmakingState.Idle;
        }
コード例 #5
0
        void TerminateRemoteServer()
        {
            if (m_UdpPing != null)
            {
                m_UdpPing.TryTerminateRemoteServer();
                m_UdpPing.Dispose();
                m_UdpPing = null;
            }
            else
            {
                UdpPingWrapper.TryTerminateRemoteServer(m_PingServerEndpoint);
            }

            m_State = MatchmakingState.Idle;
        }