Exemple #1
0
        private static void RemoveExpiredServers()
        {
            while (RunServer)
            {
                if (DateTime.UtcNow.Ticks - LastServerExpireCheck > TimeSpan.FromMilliseconds(ServerRemoveMsCheckInterval).Ticks)
                {
                    LastServerExpireCheck = DateTime.UtcNow.Ticks;

                    var serversIdsToRemove = ServerDictionary
                                             .Where(s => DateTime.UtcNow.Ticks - s.Value.LastRegisterTime >
                                                    TimeSpan.FromMilliseconds(ServerMsTimeout).Ticks)
                                             .Select(s => s.Key)
                                             .ToArray();

                    foreach (var serverId in serversIdsToRemove)
                    {
                        Server outSrv;
                        ServerDictionary.TryRemove(serverId, out outSrv);
                    }

                    if (serversIdsToRemove.Any())
                    {
                        Form.UpdateServerList(ServerDictionary.Values);
                    }
                }
            }
        }
        private static void RemoveExpiredServers()
        {
            Task.Run(async() =>
            {
                while (RunServer)
                {
                    var serversIdsToRemove = ServerDictionary
                                             .Where(s => LunaTime.UtcNow.Ticks - s.Value.LastRegisterTime >
                                                    TimeSpan.FromMilliseconds(ServerMsTimeout).Ticks)
                                             .ToArray();

                    foreach (var serverId in serversIdsToRemove)
                    {
                        ConsoleLogger.Log(LogLevels.Normal, $"REMOVING SERVER: {serverId.Value.ExternalEndpoint}");
                        ServerDictionary.TryRemove(serverId.Key, out var _);
                    }

                    await Task.Delay(ServerRemoveMsCheckInterval);
                }
            });
        }
Exemple #3
0
        private static void RemoveExpiredServers()
        {
            Task.Run(async() =>
            {
                while (RunServer)
                {
                    var serversIdsToRemove = ServerDictionary
                                             .Where(s => LunaNetworkTime.UtcNow.Ticks - s.Value.LastRegisterTime >
                                                    TimeSpan.FromMilliseconds(ServerMsTimeout).Ticks ||
                                                    BannedIpsRetriever.IsBanned(s.Value.ExternalEndpoint))
                                             .ToArray();

                    foreach (var serverId in serversIdsToRemove)
                    {
                        LunaLog.Normal($"REMOVING SERVER: {serverId.Value.ExternalEndpoint}");
                        ServerDictionary.TryRemove(serverId.Key, out _);
                    }

                    await Task.Delay(ServerRemoveMsCheckInterval);
                }
            });
        }