NBloodServerSupervisor/Supervisor/Program.cs
2020-01-27 13:48:53 +00:00

40 lines
1013 B
C#

using System;
using System.Linq;
using System.Threading;
using Model;
namespace Supervisor
{
class Program
{
public static readonly State State = new State();
public static void Main()
{
NBloodServerListener.StartListening();
WebApiListener.StartListening();
PublicServerManager.Start();
PrivateServerManager.Start();
StatisticsManager.Start();
while (true)
{
RemoveCrashedServers();
Thread.Sleep(TimeSpan.FromSeconds(3));
}
}
private static void RemoveCrashedServers()
{
var crashedServers = State.Servers.Values
.Where(s => s.IsStarted && DateTime.UtcNow - s.LastHeartBeatUtc < TimeSpan.FromMinutes(15))
.Select(s => s.Port);
foreach (var port in crashedServers)
{
State.Servers.TryRemove(port, out _);
}
}
}
}