2018-05-16 00:57:37 -04:00
|
|
|
|
using IW4MAdmin.Plugins.Stats.Cheat;
|
2018-04-08 17:50:58 -04:00
|
|
|
|
using IW4MAdmin.Plugins.Stats.Models;
|
2019-10-18 14:39:21 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-05-24 15:48:57 -04:00
|
|
|
|
using System;
|
2018-03-06 02:22:19 -05:00
|
|
|
|
using System.Collections.Concurrent;
|
2019-09-09 18:40:04 -04:00
|
|
|
|
using System.Collections.Generic;
|
2018-05-24 15:48:57 -04:00
|
|
|
|
using System.Linq;
|
2019-11-15 15:50:20 -05:00
|
|
|
|
using System.Threading;
|
2018-02-07 00:19:06 -05:00
|
|
|
|
|
2018-04-08 17:50:58 -04:00
|
|
|
|
namespace IW4MAdmin.Plugins.Stats.Helpers
|
2018-02-07 00:19:06 -05:00
|
|
|
|
{
|
2019-10-18 14:39:21 -04:00
|
|
|
|
class ServerStats
|
|
|
|
|
{
|
2019-09-09 18:40:04 -04:00
|
|
|
|
public IList<EFClientKill> HitCache { get; private set; }
|
2018-02-09 02:21:25 -05:00
|
|
|
|
public EFServerStatistics ServerStatistics { get; private set; }
|
2018-02-07 00:19:06 -05:00
|
|
|
|
public EFServer Server { get; private set; }
|
2019-10-18 14:39:21 -04:00
|
|
|
|
private readonly Server _server;
|
2018-05-24 15:48:57 -04:00
|
|
|
|
public bool IsTeamBased { get; set; }
|
2019-11-15 15:50:20 -05:00
|
|
|
|
public SemaphoreSlim OnSaving { get; private set; }
|
2018-02-07 00:19:06 -05:00
|
|
|
|
|
2019-10-18 14:39:21 -04:00
|
|
|
|
public ServerStats(EFServer sv, EFServerStatistics st, Server server)
|
2018-02-07 00:19:06 -05:00
|
|
|
|
{
|
2019-09-09 18:40:04 -04:00
|
|
|
|
HitCache = new List<EFClientKill>();
|
2018-02-09 02:21:25 -05:00
|
|
|
|
ServerStatistics = st;
|
2018-02-07 00:19:06 -05:00
|
|
|
|
Server = sv;
|
2019-10-18 14:39:21 -04:00
|
|
|
|
_server = server;
|
2019-11-15 15:50:20 -05:00
|
|
|
|
OnSaving = new SemaphoreSlim(1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~ServerStats()
|
|
|
|
|
{
|
|
|
|
|
OnSaving.Dispose();
|
2018-02-07 00:19:06 -05:00
|
|
|
|
}
|
2018-05-24 15:48:57 -04:00
|
|
|
|
|
|
|
|
|
public int TeamCount(IW4Info.Team teamName)
|
|
|
|
|
{
|
2019-10-18 14:39:21 -04:00
|
|
|
|
var PlayerStats = _server.GetClientsAsList()
|
|
|
|
|
.Select(_c => _c.GetAdditionalProperty<EFClientStatistics>(StatManager.CLIENT_STATS_KEY))
|
|
|
|
|
.Where(_c => _c != null);
|
|
|
|
|
|
|
|
|
|
if (PlayerStats.Count(p => p.Team == IW4Info.Team.None) / (double)PlayerStats.Count() <= 0.25)
|
2018-05-24 15:48:57 -04:00
|
|
|
|
{
|
2019-10-18 14:39:21 -04:00
|
|
|
|
return IsTeamBased ? Math.Max(PlayerStats.Count(p => p.Team == teamName), 1) : Math.Max(PlayerStats.Count() - 1, 1);
|
2018-05-24 15:48:57 -04:00
|
|
|
|
}
|
2019-10-18 14:39:21 -04:00
|
|
|
|
|
2018-05-24 15:48:57 -04:00
|
|
|
|
else
|
|
|
|
|
{
|
2019-10-18 14:39:21 -04:00
|
|
|
|
return IsTeamBased ? (int)Math.Max(Math.Floor(PlayerStats.Count() / 2.0), 1) : Math.Max(PlayerStats.Count() - 1, 1);
|
2018-05-24 15:48:57 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-07 00:19:06 -05:00
|
|
|
|
}
|
|
|
|
|
}
|