IW4M-Admin/Plugins/Stats/Helpers/ServerStats.cs
RaidMax 161b27e2f2 fix alias command sending message to origin instead of target
(hopefully) fix an issue with banned players causing exception if they create events before they are kicked out
fix issues with sometimes wrong error message for timeout
show most recent IP address at top of alias list
optimization to some sql queries
2019-11-15 14:50:20 -06:00

54 lines
1.7 KiB
C#

using IW4MAdmin.Plugins.Stats.Cheat;
using IW4MAdmin.Plugins.Stats.Models;
using SharedLibraryCore;
using SharedLibraryCore.Database.Models;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace IW4MAdmin.Plugins.Stats.Helpers
{
class ServerStats
{
public IList<EFClientKill> HitCache { get; private set; }
public EFServerStatistics ServerStatistics { get; private set; }
public EFServer Server { get; private set; }
private readonly Server _server;
public bool IsTeamBased { get; set; }
public SemaphoreSlim OnSaving { get; private set; }
public ServerStats(EFServer sv, EFServerStatistics st, Server server)
{
HitCache = new List<EFClientKill>();
ServerStatistics = st;
Server = sv;
_server = server;
OnSaving = new SemaphoreSlim(1, 1);
}
~ServerStats()
{
OnSaving.Dispose();
}
public int TeamCount(IW4Info.Team teamName)
{
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)
{
return IsTeamBased ? Math.Max(PlayerStats.Count(p => p.Team == teamName), 1) : Math.Max(PlayerStats.Count() - 1, 1);
}
else
{
return IsTeamBased ? (int)Math.Max(Math.Floor(PlayerStats.Count() / 2.0), 1) : Math.Max(PlayerStats.Count() - 1, 1);
}
}
}
}