1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

refactor some event handling

add concept of blocking events
This commit is contained in:
RaidMax
2019-10-18 13:39:21 -05:00
parent 812dd078f6
commit ca62c0aba2
15 changed files with 199 additions and 333 deletions

View File

@ -1,5 +1,7 @@
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;
@ -7,33 +9,36 @@ using System.Linq;
namespace IW4MAdmin.Plugins.Stats.Helpers
{
class ServerStats {
public ConcurrentDictionary<int, EFClientStatistics> PlayerStats { get; set; }
public ConcurrentDictionary<int, Detection> PlayerDetections { get; set; }
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 ServerStats(EFServer sv, EFServerStatistics st)
public ServerStats(EFServer sv, EFServerStatistics st, Server server)
{
PlayerStats = new ConcurrentDictionary<int, EFClientStatistics>();
PlayerDetections = new ConcurrentDictionary<int, Detection>();
HitCache = new List<EFClientKill>();
ServerStatistics = st;
Server = sv;
_server = server;
}
public int TeamCount(IW4Info.Team teamName)
{
if (PlayerStats.Count(p => p.Value.Team == IW4Info.Team.None) / (double)PlayerStats.Count <= 0.25)
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.Value.Team == teamName), 1) : Math.Max(PlayerStats.Count - 1, 1);
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);
return IsTeamBased ? (int)Math.Max(Math.Floor(PlayerStats.Count() / 2.0), 1) : Math.Max(PlayerStats.Count() - 1, 1);
}
}
}