Ejemplo n.º 1
0
    IEnumerator PingConnect()
    {
        m_PingResServerState = PingState.PingIng;
        //ResServer IP
        string ResServerIP = GetCurrentNormalIP();

        if (ResServerIP != null)
        { //Ping網站
            Ping ping = new Ping(ResServerIP);

            int nTime = 0;

            while (!ping.isDone)
            {
                yield return(new WaitForSeconds(0.1f));

                if (nTime > 50) // time 2 sec, OverTime
                {
                    nTime = 0;
                    ShowTips();
                    m_PingResServerState = PingState.CanNotConnectServer;
                    yield break;
                }
                nTime++;
            }
            if (ping.isDone)
            {
                yield return(ping.time);

                m_PingResServerState = PingState.PingOK;
                HideTips();
            }
        }
    }
Ejemplo n.º 2
0
    private Color GetPingColor(int i_Ping)
    {
        PingState pingState = GetPingState(i_Ping);
        Color     pingColor = GetPingColor(pingState);

        return(pingColor);
    }
Ejemplo n.º 3
0
    private Sprite GetPingSprite(int i_Ping)
    {
        PingState pingState  = GetPingState(i_Ping);
        Sprite    pingSprite = GetPingSprite(pingState);

        return(pingSprite);
    }
Ejemplo n.º 4
0
        private IEnumerator PingConnect(string ip, NetPingCallBack callback)
        {
            if (Config.Detail_Debug_Log())
            {
                Debug.Log("----------net ping 1->" + ip);
            }
            state = PingState.PingNotConnect;
            if (ip == null)
            {
                if (callback != null)
                {
                    callback(false, -1);
                }
                yield break;
            }

            state = PingState.PingIng;
            Ping ping = new Ping(ip);

            int nTime = 0;

            if (Config.Detail_Debug_Log())
            {
                Debug.Log("----------net ping 2->" + ip);
            }
            while (!ping.isDone)
            {
                yield return(new WaitForSeconds(0.1f));

                if (nTime > 20) //2秒
                {
                    nTime = 0;
                    state = PingState.PingNotConnect;
                    if (callback != null)
                    {
                        callback(false, -1);
                    }
                    yield break;
                }
                nTime++;
            }

            if (Config.Detail_Debug_Log())
            {
                Debug.Log("----------net ping 3->" + ip + "^" + ping.isDone + "^" + ping.time);
            }

            if (ping.isDone)
            {
                state = PingState.PingOK;
                if (callback != null)
                {
                    callback(true, ping.time);
                }
                yield break;
            }
        }
            /// <summary>
            /// Deserialize the state from a string.
            /// </summary>
            /// <param name="Arguments">Supplies the state string that was
            /// constructed by a call to ToString().</param>
            /// <returns>A new PingState object containing the deserialized
            /// contents, else null on failure.  An exception may also be
            /// raised on a failure that is the result of an unexpected
            /// protocol violation.</returns>
            public static PingState FromString(string Arguments)
            {
                string[] Tokens = Arguments.Split(new char[] { ':' });

                if (Tokens == null || Tokens.Length < 2)
                    return null;

                PingState State = new PingState(Convert.ToUInt32(Tokens[0]),
                    Convert.ToInt32(Tokens[1]));

                return State;
            }
Ejemplo n.º 6
0
        /// <summary>
        /// This method is called to request an IPC channel latency measurement
        /// to a target server.
        /// </summary>
        /// <param name="PCObjectId">Supplies the PC object id of the
        /// requesting player.</param>
        /// <param name="ServerId">Supplies the server id to send the ping
        /// request to.</param>
        /// <param name="Script">Supplies the script object.</param>
        public static void SendPingToServer(uint PCObjectId, int ServerId, ACR_ServerCommunicator Script)
        {
            //
            // Package and serialize the ping state for transmission to the
            // remote server.  The remote server will echo the ping back, and
            // HandleServerPingResponse will then be invoked via a reply
            // run script request for acr_ping_server_response.
            //

            PingState State = new PingState(PCObjectId, Environment.TickCount);

            Script.RunScriptOnServer(ServerId, "acr_server_ping_request", State.ToString());
        }
Ejemplo n.º 7
0
            /// <summary>
            /// Deserialize the state from a string.
            /// </summary>
            /// <param name="Arguments">Supplies the state string that was
            /// constructed by a call to ToString().</param>
            /// <returns>A new PingState object containing the deserialized
            /// contents, else null on failure.  An exception may also be
            /// raised on a failure that is the result of an unexpected
            /// protocol violation.</returns>
            public static PingState FromString(string Arguments)
            {
                string[] Tokens = Arguments.Split(new char[] { ':' });

                if (Tokens == null || Tokens.Length < 2)
                {
                    return(null);
                }

                PingState State = new PingState(Convert.ToUInt32(Tokens[0]),
                                                Convert.ToInt32(Tokens[1]));

                return(State);
            }
Ejemplo n.º 8
0
        /// <summary>
        /// This when a cross-server ping response is received.  Its purpose is
        /// to compute the channel latency and send a message to that effect to
        /// the requesting player.
        /// </summary>
        /// <param name="SourceServerId">Supplies the server id of the server
        /// that completed the ping request.</param>
        /// <param name="Arguments">Supplies the serialized state arguments
        /// string.</param>
        /// <param name="Script">Supplies the current script object.</param>
        /// <returns>TRUE on success, else FALSE on failure.</returns>
        public static int HandleServerPingResponse(int SourceServerId, string Arguments, ACR_ServerCommunicator Script)
        {
            int Tick = Environment.TickCount;

            try
            {
                PingState RemoteState;

                //
                // Deserialize the remote ping state.  If null, a protocol
                // violation has occurred.
                //

                if ((RemoteState = PingState.FromString(Arguments)) == null)
                {
                    Script.WriteTimestampedLogEntry(String.Format(
                                                        "ACR_ServerCommunicator.ServerLatencyMeasurer.HandleServerPingResponse({0}, {1}): Invalid request.",
                                                        SourceServerId,
                                                        Arguments));
                    return(ACR_ServerCommunicator.FALSE);
                }

                string ServerName = Script.GetServerName(SourceServerId);

                if (ServerName == null)
                {
                    return(ACR_ServerCommunicator.FALSE);
                }

                Script.SendMessageToPC(RemoteState.PCObjectId, String.Format(
                                           "IPC channel latency to {0}: {1}ms", ServerName, Tick - RemoteState.TickCount));
            }
            catch (Exception e)
            {
                Script.WriteTimestampedLogEntry(String.Format(
                                                    "ACR_ServerCommunicator.ServerLatencyMeasurer.HandleServerPingResponse({0}, {1}): Exception: {0}",
                                                    SourceServerId,
                                                    Arguments,
                                                    e));
                return(ACR_ServerCommunicator.FALSE);
            }

            return(ACR_ServerCommunicator.TRUE);
        }
Ejemplo n.º 9
0
        private void ping_Completed(object sender, MyPing.CompletedEventArgs e)
        {
            PingState          pingState = (PingState)e.UserState;
            UpdateRecordsState state     = pingState.state;
            Server             server    = e.Server;
            StatisticsRecord   record    = pingState.record;

            record.SetResponse(e.RoundtripTime);
            if (!record.IsEmptyData())
            {
                AppendRecord(server.Identifier(), record);
            }
            Logging.Debug($"Ping {server.FriendlyName()} {e.RoundtripTime.Count} times, {(100 - record.PackageLoss * 100)}% packages loss, min {record.MinResponse} ms, max {record.MaxResponse} ms, avg {record.AverageResponse} ms");
            if (Interlocked.Decrement(ref state.counter) == 0)
            {
                Save();
                FilterRawStatistics();
            }
        }
Ejemplo n.º 10
0
        IEnumerator CleanUpObsticlesTiles()
        {
            //Debug.Log("NM:    Cleaning Up obsticle Tiles");
            int        CurrentTerrainRemovalCount = 0;
            Vector2Int TempV2I = new Vector2Int();

            for (int ObTiles = 0; ObTiles < TerrainOccupiedNodes.Count; ++ObTiles)
            {
                TempV2I = TerrainOccupiedNodes[ObTiles].GridPosition;
                NodeGrid[TempV2I.X, TempV2I.Y] = null;
                ++CurrentTerrainRemovalCount;

                if (CurrentTerrainRemovalCount % RemovalInterval == 0)
                {
                    yield return(null);
                }
            }
            TerrainOccupiedNodes = null;
            CurrentPingState     = PingState.Complete;
            //Debug.Log("NM:    Cleaning Up obsticle Tiles Compleate!");
        }
Ejemplo n.º 11
0
    private Color GetPingColor(PingState i_PingState)
    {
        Color pingColor = Color.white;

        switch (i_PingState)
        {
        case PingState.High:
            pingColor = m_HighPingColor;
            break;

        case PingState.Medium:
            pingColor = m_MediumPingColor;
            break;

        case PingState.Low:
            pingColor = m_LowPingColor;
            break;
        }

        return(pingColor);
    }
Ejemplo n.º 12
0
    private Sprite GetPingSprite(PingState i_PingState)
    {
        Sprite pingSprite = null;

        switch (i_PingState)
        {
        case PingState.High:
            pingSprite = m_HighPingSprite;
            break;

        case PingState.Medium:
            pingSprite = m_MediumPingSprite;
            break;

        case PingState.Low:
            pingSprite = m_LowPingSprite;
            break;
        }

        return(pingSprite);
    }
Ejemplo n.º 13
0
        IEnumerator SweepTerrain()
        {
            Collider FloorCollider = FindFloor();

            //Debug.Log("NM:    Sorting Terrain from AI");
            int CurrentNodeCount = 0;

            for (int XIndex = 0; XIndex < GridXLength; ++XIndex)
            {
                for (int YIndex = 0; YIndex < GridYLength; ++YIndex)
                {
                    ++CurrentNodeCount;

                    switch (NodeGrid[XIndex, YIndex].ColliderOverlapCheck(NodeGrid[XIndex, YIndex], FloorCollider))
                    {
                    case Node.ColliderOwnerType.Null:

                        break;

                    case Node.ColliderOwnerType.AI:
                        ActiveAICB.Add(NodeGrid[XIndex, YIndex].Occupant);
                        AIOccupiedNodes.Add(NodeGrid[XIndex, YIndex]);
                        break;

                    case Node.ColliderOwnerType.Object:
                        TerrainOccupiedNodes.Add(NodeGrid[XIndex, YIndex]);
                        break;
                    }

                    if (CurrentNodeCount % SweepInterval == 0)
                    {
                        yield return(null);
                    }
                }
            }
            CurrentPingState = PingState.Inactive;
            //Debug.Log("NM:    Sorting Terrain from AI Complete!");
        }
Ejemplo n.º 14
0
 //
 void CallCleanUpObsticleTiles()
 {
     CurrentPingState = PingState.Culling;
     StartCoroutine(CleanUpObsticlesTiles());
     SetupQuardrents();
 }
Ejemplo n.º 15
0
        private async Task RunReaderAsync()
        {
            try
            {
                if (IsServer)
                {
                    EnsureBuffer(ClientPreface.Length);
                    await ClientPreface.ReadAsync(inputStream, config.ClientPrefaceTimeout);
                }

                var continueRead = true;

                if (serverUpgradeRequest != null)
                {
                    var upgrade = serverUpgradeRequest;
                    serverUpgradeRequest = null;

                    var headers = new CompleteHeadersFrameData
                    {
                        StreamId    = 1u,
                        Priority    = null,
                        Headers     = upgrade.Headers,
                        EndOfStream = upgrade.Payload == null,
                    };

                    var err = await HandleHeaders(headers);

                    if (err != null)
                    {
                        if (err.Value.StreamId == 0)
                        {
                            continueRead = false;
                        }
                        await HandleFrameProcessingError(err.Value);
                    }
                    else if (upgrade.Payload != null)
                    {
                        var buf = config.BufferPool.Rent(upgrade.Payload.Length);
                        Array.Copy(
                            upgrade.Payload, 0, buf, 0, upgrade.Payload.Length);

                        StreamImpl stream = null;
                        lock (shared.Mutex)
                        {
                            shared.streamMap.TryGetValue(1u, out stream);
                        }

                        bool tookBufferOwnership;
                        err = stream.PushBuffer(
                            new ArraySegment <byte>(buf, 0, upgrade.Payload.Length),
                            true,
                            out tookBufferOwnership);
                        if (!tookBufferOwnership)
                        {
                            config.BufferPool.Return(buf);
                        }
                        if (err != null)
                        {
                            if (err.Value.StreamId == 0)
                            {
                                continueRead = false;
                            }
                            await HandleFrameProcessingError(err.Value);
                        }
                    }
                }

                while (continueRead)
                {
                    EnsureBuffer(PersistentBufferSize);
                    var err = await ReadOneFrame();

                    ReleaseBuffer(PersistentBufferSize);
                    if (err != null)
                    {
                        if (err.Value.StreamId == 0)
                        {
                            continueRead = false;
                        }
                        await HandleFrameProcessingError(err.Value);
                    }
                }
            }
            catch (Exception e)
            {
            }

            await writer.CloseNow();

            await writer.Done;

            Dictionary <uint, StreamImpl> activeStreams = null;

            lock (shared.Mutex)
            {
                activeStreams    = shared.streamMap;
                shared.streamMap = null;


                shared.Closed = true;
            }
            foreach (var kvp in activeStreams)
            {
                await kvp.Value.Reset(ErrorCode.ConnectError, fromRemote : true);
            }

            PingState pingState = null;

            lock (shared.Mutex)
            {
                if (shared.PingState != null)
                {
                    pingState        = shared.PingState;
                    shared.PingState = null;
                }
            }
            if (pingState != null)
            {
                var ex = new ConnectionClosedException();
                foreach (var kvp in pingState.PingMap)
                {
                    kvp.Value.SetException(ex);
                }
            }
            if (!remoteGoAwayTcs.Task.IsCompleted)
            {
                remoteGoAwayTcs.TrySetException(new EndOfStreamException());
            }

            if (receiveBuffer != null)
            {
                config.BufferPool.Return(receiveBuffer);
                receiveBuffer = null;
            }

            headerReader.Dispose();
        }
Ejemplo n.º 16
0
 //
 void CallTerrainSweep()
 {
     CurrentPingState = PingState.Sweeping;
     StartCoroutine(SweepTerrain());
 }
Ejemplo n.º 17
0
 public void AddPing(PingState ping)
 {
     _activePings.Add(ping);
 }
        /// <summary>
        /// This method is called to request an IPC channel latency measurement
        /// to a target server.
        /// </summary>
        /// <param name="PCObjectId">Supplies the PC object id of the
        /// requesting player.</param>
        /// <param name="ServerId">Supplies the server id to send the ping
        /// request to.</param>
        /// <param name="Script">Supplies the script object.</param>
        public static void SendPingToServer(uint PCObjectId, int ServerId, ACR_ServerCommunicator Script)
        {
            //
            // Package and serialize the ping state for transmission to the
            // remote server.  The remote server will echo the ping back, and
            // HandleServerPingResponse will then be invoked via a reply
            // run script request for acr_ping_server_response.
            //

            PingState State = new PingState(PCObjectId, Environment.TickCount);

            Script.RunScriptOnServer(ServerId, "acr_server_ping_request", State.ToString());
        }