2020-01-23 21:03:54 +01:00
|
|
|
|
using System;
|
2020-01-25 16:59:28 +01:00
|
|
|
|
using System.Linq;
|
2020-01-23 21:03:54 +01:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using Model;
|
|
|
|
|
|
|
|
|
|
namespace Supervisor
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
public static readonly State State = new State();
|
|
|
|
|
|
2020-01-24 12:23:40 +01:00
|
|
|
|
public static void Main()
|
2020-01-23 21:03:54 +01:00
|
|
|
|
{
|
|
|
|
|
NBloodServerListener.StartListening();
|
|
|
|
|
WebApiListener.StartListening();
|
2020-01-24 12:23:40 +01:00
|
|
|
|
PublicServerManager.Start();
|
2020-01-23 21:03:54 +01:00
|
|
|
|
PrivateServerManager.Start();
|
2020-01-27 14:48:53 +01:00
|
|
|
|
StatisticsManager.Start();
|
|
|
|
|
|
2020-01-23 21:03:54 +01:00
|
|
|
|
while (true)
|
|
|
|
|
{
|
2020-01-25 16:59:28 +01:00
|
|
|
|
RemoveCrashedServers();
|
|
|
|
|
Thread.Sleep(TimeSpan.FromSeconds(3));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void RemoveCrashedServers()
|
|
|
|
|
{
|
2020-01-27 17:25:45 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var crashedServers = State.Servers.Values
|
|
|
|
|
.Where(s => s.IsStarted && DateTime.UtcNow - s.LastHeartBeatUtc < TimeSpan.FromMinutes(15))
|
|
|
|
|
.Select(s => s.Port);
|
2020-01-25 16:59:28 +01:00
|
|
|
|
|
2020-01-27 17:25:45 +01:00
|
|
|
|
foreach (var port in crashedServers)
|
|
|
|
|
{
|
|
|
|
|
State.Servers.TryRemove(port, out _);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
2020-01-25 16:59:28 +01:00
|
|
|
|
{
|
2020-01-27 17:25:45 +01:00
|
|
|
|
// Log...
|
2020-01-23 21:03:54 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|