예제 #1
0
        public void PingCheck()
        {
            lock (clientsByName)
            {
                foreach (var kvp in clientsByName)
                {
                    var client = kvp.Value;
                    if (!client.Authenticated)
                    {
                        continue; //they don't have ping shit, since they don't even send a response.
                    }
                    if (client.HasPong)
                    {
                        Handler2.SendPing(client);
                        client.HasPong = false;
                    }
                    else
                    {
                        pingTimeouts.Add(kvp.Key);
                        Log.WriteLine(LogLevel.Debug, "Ping timeout from {0} ({1})", client.Username, client.Host);
                    }
                }

                foreach (var client in pingTimeouts)
                {
                    ZoneClient derp = null;
                    clientsByName.TryRemove(client, out derp);
                    derp.Disconnect();
                }

                pingTimeouts.Clear();
            }
        }
예제 #2
0
        public void PingCheck(DateTime now)
        {
            lock (_clients)
            {
                foreach (var client in _clients)
                {
                    if (!client.Authenticated)
                    {
                        continue; //they don't have ping shit, since they don't even send a response.
                    }
                    if (client.Pong)
                    {
                        Handler2.SendPing(client);
                        client.Pong     = false;
                        client.LastPing = now;
                    }
                    else
                    {
                        if (now.Subtract(client.LastPing).TotalSeconds >= 300)
                        {
                            _pingTimeouts.Add(client);
                            Log.WriteLine(LogLevel.Debug, "Ping timeout from {0} ({1})", client.Username, client.Host);
                        }
                    }
                }

                foreach (var client in _pingTimeouts)
                {
                    _clients.Remove(client);
                    client.Disconnect();
                }

                _pingTimeouts.Clear();
            }
        }