NBloodServerSupervisor/Supervisor/Program.cs
2020-01-27 16:25:45 +00:00

47 lines
1.1 KiB
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()
{
try
{
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 _);
}
}
catch
{
// Log...
}
}
}
}