2020-01-27 14:48:53 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Supervisor
|
|
|
|
|
{
|
2020-02-12 17:19:15 +01:00
|
|
|
|
static class StatisticsManager
|
2020-01-27 14:48:53 +01:00
|
|
|
|
{
|
|
|
|
|
public static void Start()
|
|
|
|
|
{
|
|
|
|
|
Task.Factory.StartNew(() =>
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(TimeSpan.FromSeconds(5));
|
|
|
|
|
UpdatePlaytime();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void UpdatePlaytime()
|
|
|
|
|
{
|
|
|
|
|
TimeSpan timeToAdd = new TimeSpan(0);
|
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
foreach (var server in Program.State.Servers.Values.Where(s => s.IsStarted))
|
|
|
|
|
{
|
|
|
|
|
if (server.LastCollectionUtc.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var elapsedTime = now - server.LastCollectionUtc.Value;
|
|
|
|
|
timeToAdd += elapsedTime * (server.CurrentPlayers - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
server.LastCollectionUtc = now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Program.State.IncreasePlaytime(timeToAdd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|