Exemplo n.º 1
0
        public void Update(TimeSpan delta)
        {
            if (LatencyMonitor.HasFlag(LatencyMonitorMethod.Ping) && !_awaitingPingResponse && !_awaitingEchoResponse &&
                _now >= _pingSent + PingEveryMillis * TimeSpan.TicksPerMillisecond)
            {
                _awaitingPingResponse = true;
                _pingSent             = _now;
                SendMessage(new[] { PingDenoter }, _server.Connections);
            }

            if (_awaitingEchoResponse && _now >= _toEchoSent + 5 * TimeSpan.TicksPerSecond ||
                _awaitingPingResponse && _now >= _pingSent + 5 * TimeSpan.TicksPerSecond)
            {
                Latency = NO_RESPONSE;
                NoResponseCallback();
            }

            for (var i = 0; i < _lastConnections.Count(); i++)
            {
                if (!Connections.Any((c) => c == _lastConnections[i]))
                {
                    OnDisconnect(_lastConnections[i]);
                }
            }
            for (var i = 0; i < Connections.Count(); i++)
            {
                if (!_lastConnections.Any((c) => c == Connections[i]))
                {
                    OnConnect(Connections[i]);
                }
            }
        }
Exemplo n.º 2
0
 public void Send(byte[] bytes)
 {
     if (LatencyMonitor.HasFlag(LatencyMonitorMethod.Echo))
     {
         _awaitingEchoResponse = true;
         _toEchoSent           = DateTimeOffset.UtcNow.Ticks;
     }
     SendMessage((LatencyMonitor.HasFlag(LatencyMonitorMethod.Echo) ? new[] { ToEchoDenoter } : new[] { NormalDenoter })
                 .Concat(bytes).ToArray());
 }
Exemplo n.º 3
0
        public void Send(byte[] bytes)
        {
            List <NetConnection> all = _server.Connections;

            if (LatencyMonitor.HasFlag(LatencyMonitorMethod.Echo))
            {
                var randomConnection = all.Random();
                all.RemoveAll((c) => c.RemoteUniqueIdentifier == randomConnection.RemoteUniqueIdentifier);
                _awaitingEchoResponse = true;
                _toEchoSent           = _now;
                SendMessage(new[] { ToEchoDenoter }.Concat(bytes), new List <NetConnection>()
                {
                    randomConnection
                });
            }
            SendMessage(new[] { NormalDenoter }.Concat(bytes), all);
        }
Exemplo n.º 4
0
        public void Update(TimeSpan delta)
        {
            if (LatencyMonitor.HasFlag(LatencyMonitorMethod.Ping) && !_awaitingPingResponse && !_awaitingEchoResponse &&
                _now >= _pingSent + PingEveryMillis * TimeSpan.TicksPerMillisecond)
            {
                _awaitingPingResponse = true;
                _pingSent             = _now;
                SendMessage(new[] { PingDenoter });
            }

            if (_awaitingEchoResponse && _now >= _toEchoSent + 5 * TimeSpan.TicksPerSecond ||
                _awaitingPingResponse && _now >= _pingSent + 5 * TimeSpan.TicksPerSecond)
            {
                Latency = NO_RESPONSE;
                NoResponseCallback();
            }

            if (!_hasFinishedTryingToConnect && ConnectionSuccessful.HasValue)
            {
                (ConnectionSuccessful.Value ? OnConnectionSuccess : OnConnectionFail)();
            }
        }