mirror of
https://github.com/CommonLoon102/NBloodServerSupervisor.git
synced 2024-12-23 03:02:51 +01:00
47 lines
1.1 KiB
C#
47 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Diagnostics;
|
|
|
|
namespace Supervisor
|
|
{
|
|
static class PrivateServerManager
|
|
{
|
|
public static void Start()
|
|
{
|
|
Task.Factory.StartNew(() =>
|
|
{
|
|
while (true)
|
|
{
|
|
Thread.Sleep(TimeSpan.FromSeconds(2));
|
|
KillUnusedServers();
|
|
}
|
|
});
|
|
}
|
|
|
|
private static void KillUnusedServers()
|
|
{
|
|
try
|
|
{
|
|
var killables = Program.State.Servers.Values.Where(s =>
|
|
s.IsPrivate
|
|
&& !s.IsStarted
|
|
&& s.CurrentPlayers < 2
|
|
&& (DateTime.UtcNow - s.SpawnedAtUtc) > TimeSpan.FromMinutes(10));
|
|
|
|
foreach (var server in killables)
|
|
{
|
|
Process.GetProcessById(server.ProcessId).Kill();
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
//Log...
|
|
}
|
|
}
|
|
}
|
|
}
|