NBloodServerSupervisor/Supervisor/Program.cs
2020-01-25 15:59:28 +00:00

39 lines
986 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();
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 _);
}
}
}
}