mirror of
https://github.com/CommonLoon102/NBloodServerSupervisor.git
synced 2024-12-23 03:02:51 +01:00
43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace Supervisor
|
|||
|
{
|
|||
|
class StatisticsManager
|
|||
|
{
|
|||
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|