2018-11-27 19:31:48 -05:00
|
|
|
|
using IW4MAdmin.Plugins.Stats.Config;
|
|
|
|
|
using IW4MAdmin.Plugins.Stats.Helpers;
|
|
|
|
|
using IW4MAdmin.Plugins.Stats.Models;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2018-04-08 17:50:58 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Configuration;
|
2018-11-27 19:31:48 -05:00
|
|
|
|
using SharedLibraryCore.Database;
|
2019-04-25 14:00:54 -04:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-04-08 17:50:58 -04:00
|
|
|
|
using SharedLibraryCore.Dtos;
|
|
|
|
|
using SharedLibraryCore.Helpers;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using SharedLibraryCore.Services;
|
2018-11-27 19:31:48 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-11-25 20:29:58 -05:00
|
|
|
|
|
2018-04-08 17:50:58 -04:00
|
|
|
|
namespace IW4MAdmin.Plugins.Stats
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2018-05-28 21:30:31 -04:00
|
|
|
|
public class Plugin : IPlugin
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2018-02-07 00:19:06 -05:00
|
|
|
|
public string Name => "Simple Stats";
|
2017-06-01 13:42:28 -04:00
|
|
|
|
|
2018-04-08 17:50:58 -04:00
|
|
|
|
public float Version => Assembly.GetExecutingAssembly().GetName().Version.Major + Assembly.GetExecutingAssembly().GetName().Version.Minor / 10.0f;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-11-15 16:04:13 -05:00
|
|
|
|
public string Author => "RaidMax";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2018-03-06 02:22:19 -05:00
|
|
|
|
public static StatManager Manager { get; private set; }
|
2019-02-26 22:25:27 -05:00
|
|
|
|
public static IManager ServerManager;
|
2018-03-18 22:25:11 -04:00
|
|
|
|
public static BaseConfigurationHandler<StatsConfiguration> Config { get; private set; }
|
2019-09-09 18:40:04 -04:00
|
|
|
|
#if DEBUG
|
|
|
|
|
int scriptDamageCount;
|
|
|
|
|
int scriptKillCount;
|
|
|
|
|
#endif
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
public async Task OnEventAsync(GameEvent E, Server S)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2018-02-07 00:19:06 -05:00
|
|
|
|
switch (E.Type)
|
2015-08-23 17:58:48 -04:00
|
|
|
|
{
|
2018-04-13 02:32:30 -04:00
|
|
|
|
case GameEvent.EventType.Start:
|
2018-02-07 00:19:06 -05:00
|
|
|
|
Manager.AddServer(S);
|
2015-08-23 17:58:48 -04:00
|
|
|
|
break;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
case GameEvent.EventType.Stop:
|
2015-08-23 17:58:48 -04:00
|
|
|
|
break;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
case GameEvent.EventType.Connect:
|
2018-03-06 02:22:19 -05:00
|
|
|
|
await Manager.AddPlayer(E.Origin);
|
2015-08-23 17:58:48 -04:00
|
|
|
|
break;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
case GameEvent.EventType.Disconnect:
|
2018-02-07 00:19:06 -05:00
|
|
|
|
await Manager.RemovePlayer(E.Origin);
|
|
|
|
|
break;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
case GameEvent.EventType.Say:
|
2018-08-03 20:06:47 -04:00
|
|
|
|
if (!string.IsNullOrEmpty(E.Data) &&
|
2018-05-10 01:34:29 -04:00
|
|
|
|
E.Origin.ClientId > 1)
|
2018-11-27 19:31:48 -05:00
|
|
|
|
{
|
2019-08-23 19:34:31 -04:00
|
|
|
|
await Manager.AddMessageAsync(E.Origin.ClientId, StatManager.GetIdForServer(E.Owner), E.Data);
|
2018-11-27 19:31:48 -05:00
|
|
|
|
}
|
2018-02-07 00:19:06 -05:00
|
|
|
|
break;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
case GameEvent.EventType.MapChange:
|
2019-08-23 19:34:31 -04:00
|
|
|
|
Manager.SetTeamBased(StatManager.GetIdForServer(E.Owner), E.Owner.Gametype != "dm");
|
|
|
|
|
Manager.ResetKillstreaks(StatManager.GetIdForServer(E.Owner));
|
2019-09-09 18:40:04 -04:00
|
|
|
|
await Manager.Sync(E.Owner);
|
2018-02-07 00:19:06 -05:00
|
|
|
|
break;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
case GameEvent.EventType.MapEnd:
|
2019-09-09 18:40:04 -04:00
|
|
|
|
await Manager.Sync(E.Owner);
|
2018-02-07 00:19:06 -05:00
|
|
|
|
break;
|
2018-06-05 17:31:36 -04:00
|
|
|
|
case GameEvent.EventType.JoinTeam:
|
|
|
|
|
break;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
case GameEvent.EventType.Broadcast:
|
2018-02-07 00:19:06 -05:00
|
|
|
|
break;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
case GameEvent.EventType.Tell:
|
2018-02-07 00:19:06 -05:00
|
|
|
|
break;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
case GameEvent.EventType.Kick:
|
2018-02-07 00:19:06 -05:00
|
|
|
|
break;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
case GameEvent.EventType.Ban:
|
2018-02-07 00:19:06 -05:00
|
|
|
|
break;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
case GameEvent.EventType.Unknown:
|
2018-02-07 00:19:06 -05:00
|
|
|
|
break;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
case GameEvent.EventType.Report:
|
2018-02-07 00:19:06 -05:00
|
|
|
|
break;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
case GameEvent.EventType.Flag:
|
2018-02-07 00:19:06 -05:00
|
|
|
|
break;
|
2018-05-10 01:34:29 -04:00
|
|
|
|
case GameEvent.EventType.ScriptKill:
|
2018-02-07 00:19:06 -05:00
|
|
|
|
string[] killInfo = (E.Data != null) ? E.Data.Split(';') : new string[0];
|
2019-08-23 19:34:31 -04:00
|
|
|
|
if (E.Owner.CustomCallback && killInfo.Length >= 14 && !ShouldIgnoreEvent(E.Origin, E.Target))
|
2018-08-30 21:53:00 -04:00
|
|
|
|
{
|
2019-04-05 22:15:17 -04:00
|
|
|
|
// this treats "world" damage as self damage
|
2019-05-29 17:55:35 -04:00
|
|
|
|
if (IsWorldDamage(E.Origin))
|
2019-04-05 22:15:17 -04:00
|
|
|
|
{
|
|
|
|
|
E.Origin = E.Target;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 18:40:04 -04:00
|
|
|
|
#if DEBUG
|
|
|
|
|
scriptKillCount++;
|
|
|
|
|
S.Logger.WriteInfo($"Start ScriptKill {scriptKillCount}");
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-08-23 19:34:31 -04:00
|
|
|
|
await Manager.AddScriptHit(false, E.Time, E.Origin, E.Target, StatManager.GetIdForServer(E.Owner), S.CurrentMap.Name, killInfo[7], killInfo[8],
|
2018-09-04 13:40:29 -04:00
|
|
|
|
killInfo[5], killInfo[6], killInfo[3], killInfo[4], killInfo[9], killInfo[10], killInfo[11], killInfo[12], killInfo[13], killInfo[14], killInfo[15]);
|
2019-09-09 18:40:04 -04:00
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
S.Logger.WriteInfo($"End ScriptKill {scriptKillCount}");
|
|
|
|
|
#endif
|
2018-08-30 21:53:00 -04:00
|
|
|
|
}
|
2018-05-10 01:34:29 -04:00
|
|
|
|
break;
|
|
|
|
|
case GameEvent.EventType.Kill:
|
2019-04-25 14:00:54 -04:00
|
|
|
|
if (!E.Owner.CustomCallback && !ShouldIgnoreEvent(E.Origin, E.Target))
|
2018-09-29 15:52:22 -04:00
|
|
|
|
{
|
2019-04-02 21:20:37 -04:00
|
|
|
|
// this treats "world" damage as self damage
|
2019-05-29 17:55:35 -04:00
|
|
|
|
if (IsWorldDamage(E.Origin))
|
2019-04-02 21:20:37 -04:00
|
|
|
|
{
|
|
|
|
|
E.Origin = E.Target;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-10 23:33:42 -05:00
|
|
|
|
await Manager.AddStandardKill(E.Origin, E.Target);
|
2018-09-29 15:52:22 -04:00
|
|
|
|
}
|
2018-02-07 00:19:06 -05:00
|
|
|
|
break;
|
2018-05-10 01:34:29 -04:00
|
|
|
|
case GameEvent.EventType.Damage:
|
2019-04-25 14:00:54 -04:00
|
|
|
|
if (!E.Owner.CustomCallback && !ShouldIgnoreEvent(E.Origin, E.Target))
|
2018-09-29 15:52:22 -04:00
|
|
|
|
{
|
2019-04-02 21:20:37 -04:00
|
|
|
|
// this treats "world" damage as self damage
|
2019-05-29 17:55:35 -04:00
|
|
|
|
if (IsWorldDamage(E.Origin))
|
2019-04-02 21:20:37 -04:00
|
|
|
|
{
|
|
|
|
|
E.Origin = E.Target;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-23 19:34:31 -04:00
|
|
|
|
Manager.AddDamageEvent(E.Data, E.Origin.ClientId, E.Target.ClientId, StatManager.GetIdForServer(E.Owner));
|
2018-09-29 15:52:22 -04:00
|
|
|
|
}
|
2018-05-10 01:34:29 -04:00
|
|
|
|
break;
|
2018-05-08 00:58:46 -04:00
|
|
|
|
case GameEvent.EventType.ScriptDamage:
|
|
|
|
|
killInfo = (E.Data != null) ? E.Data.Split(';') : new string[0];
|
2019-08-23 19:34:31 -04:00
|
|
|
|
if (E.Owner.CustomCallback && killInfo.Length >= 14 && !ShouldIgnoreEvent(E.Origin, E.Target))
|
2018-08-30 21:53:00 -04:00
|
|
|
|
{
|
2019-04-05 22:15:17 -04:00
|
|
|
|
// this treats "world" damage as self damage
|
2019-05-29 17:55:35 -04:00
|
|
|
|
if (IsWorldDamage(E.Origin))
|
2019-04-05 22:15:17 -04:00
|
|
|
|
{
|
|
|
|
|
E.Origin = E.Target;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-09 18:40:04 -04:00
|
|
|
|
#if DEBUG
|
|
|
|
|
scriptDamageCount++;
|
|
|
|
|
S.Logger.WriteInfo($"Start ScriptDamage {scriptDamageCount}");
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-08-23 19:34:31 -04:00
|
|
|
|
await Manager.AddScriptHit(true, E.Time, E.Origin, E.Target, StatManager.GetIdForServer(E.Owner), S.CurrentMap.Name, killInfo[7], killInfo[8],
|
2018-09-04 13:40:29 -04:00
|
|
|
|
killInfo[5], killInfo[6], killInfo[3], killInfo[4], killInfo[9], killInfo[10], killInfo[11], killInfo[12], killInfo[13], killInfo[14], killInfo[15]);
|
2019-09-09 18:40:04 -04:00
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
S.Logger.WriteInfo($"End ScriptDamage {scriptDamageCount}");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
2018-08-30 21:53:00 -04:00
|
|
|
|
}
|
2018-05-03 01:25:49 -04:00
|
|
|
|
break;
|
2015-08-20 17:54:38 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-18 22:25:11 -04:00
|
|
|
|
public async Task OnLoadAsync(IManager manager)
|
2015-08-20 17:54:38 -04:00
|
|
|
|
{
|
2018-03-18 22:25:11 -04:00
|
|
|
|
// load custom configuration
|
|
|
|
|
Config = new BaseConfigurationHandler<StatsConfiguration>("StatsPluginSettings");
|
2018-03-22 14:50:09 -04:00
|
|
|
|
if (Config.Configuration() == null)
|
2018-03-18 22:25:11 -04:00
|
|
|
|
{
|
|
|
|
|
Config.Set((StatsConfiguration)new StatsConfiguration().Generate());
|
|
|
|
|
await Config.Save();
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-03 18:10:20 -04:00
|
|
|
|
// register the topstats page
|
|
|
|
|
// todo:generate the URL/Location instead of hardcoding
|
|
|
|
|
manager.GetPageList()
|
|
|
|
|
.Pages.Add(
|
|
|
|
|
Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_TOP_TEXT"],
|
|
|
|
|
"/Stats/TopPlayersAsync");
|
|
|
|
|
|
2018-02-14 14:01:26 -05:00
|
|
|
|
// meta data info
|
2019-03-29 22:56:56 -04:00
|
|
|
|
async Task<List<ProfileMeta>> getStats(int clientId, int offset, int count, DateTime? startAt)
|
2018-02-14 14:01:26 -05:00
|
|
|
|
{
|
2019-03-27 20:40:26 -04:00
|
|
|
|
if (count > 1)
|
|
|
|
|
{
|
|
|
|
|
return new List<ProfileMeta>();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-07 22:34:30 -04:00
|
|
|
|
IList<EFClientStatistics> clientStats;
|
|
|
|
|
using (var ctx = new DatabaseContext(disableTracking: true))
|
|
|
|
|
{
|
|
|
|
|
clientStats = await ctx.Set<EFClientStatistics>().Where(c => c.ClientId == clientId).ToListAsync();
|
|
|
|
|
}
|
2018-02-14 14:01:26 -05:00
|
|
|
|
|
|
|
|
|
int kills = clientStats.Sum(c => c.Kills);
|
|
|
|
|
int deaths = clientStats.Sum(c => c.Deaths);
|
2018-02-16 23:24:03 -05:00
|
|
|
|
double kdr = Math.Round(kills / (double)deaths, 2);
|
2018-05-17 19:31:58 -04:00
|
|
|
|
var validPerformanceValues = clientStats.Where(c => c.Performance > 0);
|
|
|
|
|
int performancePlayTime = validPerformanceValues.Sum(s => s.TimePlayed);
|
|
|
|
|
double performance = Math.Round(validPerformanceValues.Sum(c => c.Performance * c.TimePlayed / performancePlayTime), 2);
|
2018-04-28 17:39:45 -04:00
|
|
|
|
double spm = Math.Round(clientStats.Sum(c => c.SPM) / clientStats.Where(c => c.SPM > 0).Count(), 1);
|
2018-02-14 14:01:26 -05:00
|
|
|
|
|
2018-04-05 00:38:45 -04:00
|
|
|
|
return new List<ProfileMeta>()
|
|
|
|
|
{
|
2018-09-04 22:07:34 -04:00
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_RANKING"],
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Value = "#" + (await StatManager.GetClientOverallRanking(clientId)).ToString("#,##0", new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)),
|
|
|
|
|
Column = 0,
|
|
|
|
|
Order = 0,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information
|
2018-09-04 22:07:34 -04:00
|
|
|
|
},
|
2018-04-05 00:38:45 -04:00
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
2018-05-08 00:58:46 -04:00
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_TEXT_KILLS"],
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Value = kills.ToString("#,##0", new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)),
|
|
|
|
|
Column = 0,
|
|
|
|
|
Order = 1,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information
|
2018-04-05 00:38:45 -04:00
|
|
|
|
},
|
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
2018-05-08 00:58:46 -04:00
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_TEXT_DEATHS"],
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Value = deaths.ToString("#,##0", new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)),
|
|
|
|
|
Column = 0,
|
|
|
|
|
Order = 2,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information
|
2018-04-05 00:38:45 -04:00
|
|
|
|
},
|
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
2018-05-08 00:58:46 -04:00
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_TEXT_KDR"],
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Value = kdr.ToString(new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)),
|
|
|
|
|
Column = 0,
|
|
|
|
|
Order = 3,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information
|
2018-04-05 00:38:45 -04:00
|
|
|
|
},
|
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
2018-05-17 19:31:58 -04:00
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_PERFORMANCE"],
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Value = performance.ToString("#,##0", new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)),
|
|
|
|
|
Column = 0,
|
|
|
|
|
Order = 4,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information
|
2018-04-05 00:38:45 -04:00
|
|
|
|
},
|
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
2018-05-08 00:58:46 -04:00
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_META_SPM"],
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Value = spm.ToString(new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)),
|
|
|
|
|
Column = 0,
|
|
|
|
|
Order = 5,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information
|
2018-04-05 00:38:45 -04:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 22:56:56 -04:00
|
|
|
|
async Task<List<ProfileMeta>> getAnticheatInfo(int clientId, int offset, int count, DateTime? startAt)
|
2018-04-05 00:38:45 -04:00
|
|
|
|
{
|
2019-03-27 20:40:26 -04:00
|
|
|
|
if (count > 1)
|
|
|
|
|
{
|
|
|
|
|
return new List<ProfileMeta>();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-07 22:34:30 -04:00
|
|
|
|
IList<EFClientStatistics> clientStats;
|
2019-03-27 20:40:26 -04:00
|
|
|
|
|
2018-10-07 22:34:30 -04:00
|
|
|
|
using (var ctx = new DatabaseContext(disableTracking: true))
|
|
|
|
|
{
|
|
|
|
|
clientStats = await ctx.Set<EFClientStatistics>()
|
|
|
|
|
.Include(c => c.HitLocations)
|
|
|
|
|
.Where(c => c.ClientId == clientId)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
2018-04-05 00:38:45 -04:00
|
|
|
|
|
2018-03-22 14:50:09 -04:00
|
|
|
|
double headRatio = 0;
|
2018-03-06 02:22:19 -05:00
|
|
|
|
double chestRatio = 0;
|
|
|
|
|
double abdomenRatio = 0;
|
|
|
|
|
double chestAbdomenRatio = 0;
|
2018-03-27 20:27:01 -04:00
|
|
|
|
double hitOffsetAverage = 0;
|
2019-06-15 18:37:43 -04:00
|
|
|
|
double averageRecoilAmount = 0;
|
2019-09-09 18:40:04 -04:00
|
|
|
|
double averageSnapValue = 0;
|
2018-05-10 01:34:29 -04:00
|
|
|
|
double maxStrain = clientStats.Count(c => c.MaxStrain > 0) == 0 ? 0 : clientStats.Max(cs => cs.MaxStrain);
|
2018-03-06 02:22:19 -05:00
|
|
|
|
|
2018-03-09 03:01:12 -05:00
|
|
|
|
if (clientStats.Where(cs => cs.HitLocations.Count > 0).FirstOrDefault() != null)
|
2018-03-06 02:22:19 -05:00
|
|
|
|
{
|
2019-04-21 17:28:13 -04:00
|
|
|
|
chestRatio = Math.Round((clientStats.Where(c => c.HitLocations.Count > 0).Sum(c =>
|
2018-03-06 02:22:19 -05:00
|
|
|
|
c.HitLocations.First(hl => hl.Location == IW4Info.HitLocation.torso_upper).HitCount) /
|
|
|
|
|
(double)clientStats.Where(c => c.HitLocations.Count > 0)
|
2019-04-21 17:28:13 -04:00
|
|
|
|
.Sum(c => c.HitLocations.Where(hl => hl.Location != IW4Info.HitLocation.none).Sum(f => f.HitCount))) * 100.0, 0);
|
2018-03-06 02:22:19 -05:00
|
|
|
|
|
2019-04-21 17:28:13 -04:00
|
|
|
|
abdomenRatio = Math.Round((clientStats.Where(c => c.HitLocations.Count > 0).Sum(c =>
|
2018-03-06 02:22:19 -05:00
|
|
|
|
c.HitLocations.First(hl => hl.Location == IW4Info.HitLocation.torso_lower).HitCount) /
|
2019-04-21 17:28:13 -04:00
|
|
|
|
(double)clientStats.Where(c => c.HitLocations.Count > 0).Sum(c => c.HitLocations.Where(hl => hl.Location != IW4Info.HitLocation.none).Sum(f => f.HitCount))) * 100.0, 0);
|
2018-03-06 02:22:19 -05:00
|
|
|
|
|
2019-04-21 17:28:13 -04:00
|
|
|
|
chestAbdomenRatio = Math.Round((clientStats.Where(c => c.HitLocations.Count > 0).Sum(cs => cs.HitLocations.First(hl => hl.Location == IW4Info.HitLocation.torso_upper).HitCount) /
|
|
|
|
|
(double)clientStats.Where(c => c.HitLocations.Count > 0).Sum(cs => cs.HitLocations.First(hl => hl.Location == IW4Info.HitLocation.torso_lower).HitCount)) * 100.0, 0);
|
2018-03-22 14:50:09 -04:00
|
|
|
|
|
2019-04-21 17:28:13 -04:00
|
|
|
|
headRatio = Math.Round((clientStats.Where(c => c.HitLocations.Count > 0).Sum(cs => cs.HitLocations.First(hl => hl.Location == IW4Info.HitLocation.head).HitCount) /
|
2018-03-22 14:50:09 -04:00
|
|
|
|
(double)clientStats.Where(c => c.HitLocations.Count > 0)
|
2019-04-21 17:28:13 -04:00
|
|
|
|
.Sum(c => c.HitLocations.Where(hl => hl.Location != IW4Info.HitLocation.none).Sum(f => f.HitCount))) * 100.0, 0);
|
2018-03-27 20:27:01 -04:00
|
|
|
|
|
2018-05-05 16:36:26 -04:00
|
|
|
|
var validOffsets = clientStats.Where(c => c.HitLocations.Count(hl => hl.HitCount > 0) > 0).SelectMany(hl => hl.HitLocations);
|
|
|
|
|
hitOffsetAverage = validOffsets.Sum(o => o.HitCount * o.HitOffsetAverage) / (double)validOffsets.Sum(o => o.HitCount);
|
2019-06-15 18:37:43 -04:00
|
|
|
|
averageRecoilAmount = clientStats.Average(_stat => _stat.AverageRecoilOffset);
|
2019-09-09 18:40:04 -04:00
|
|
|
|
averageSnapValue = clientStats.Any(_stats => _stats.AverageSnapValue > 0) ? clientStats.Where(_stats => _stats.AverageSnapValue > 0).Average(_stat => _stat.AverageSnapValue) : 0;
|
2018-03-06 02:22:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-14 14:01:26 -05:00
|
|
|
|
return new List<ProfileMeta>()
|
|
|
|
|
{
|
2018-04-05 00:38:45 -04:00
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Key = $"{Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_AC_METRIC"]} 1",
|
2019-04-21 17:28:13 -04:00
|
|
|
|
Value = chestRatio.ToString(new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)) + '%',
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information,
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Column = 2,
|
|
|
|
|
Order = 0,
|
2019-04-21 17:28:13 -04:00
|
|
|
|
Extra = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_TITLE_ACM1"],
|
2018-05-03 01:25:49 -04:00
|
|
|
|
Sensitive = true
|
2018-04-05 00:38:45 -04:00
|
|
|
|
},
|
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Key = $"{Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_AC_METRIC"]} 2",
|
2019-04-21 17:28:13 -04:00
|
|
|
|
Value = abdomenRatio.ToString(new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)) + '%',
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information,
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Column = 2,
|
|
|
|
|
Order = 1,
|
2019-04-21 17:28:13 -04:00
|
|
|
|
Extra = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_TITLE_ACM2"],
|
2018-04-05 00:38:45 -04:00
|
|
|
|
Sensitive = true
|
|
|
|
|
},
|
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Key = $"{Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_AC_METRIC"]} 3",
|
2019-04-21 17:28:13 -04:00
|
|
|
|
Value = chestAbdomenRatio.ToString(new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)) + '%',
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information,
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Column = 2,
|
|
|
|
|
Order = 2,
|
2019-04-21 17:28:13 -04:00
|
|
|
|
Extra = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_TITLE_ACM3"],
|
2018-04-05 00:38:45 -04:00
|
|
|
|
Sensitive = true
|
|
|
|
|
},
|
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Key = $"{Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_AC_METRIC"]} 4",
|
2019-04-21 17:28:13 -04:00
|
|
|
|
Value = headRatio.ToString(new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)) + '%',
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information,
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Column = 2,
|
|
|
|
|
Order = 3,
|
2019-04-21 17:28:13 -04:00
|
|
|
|
Extra = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_TITLE_ACM4"],
|
2018-04-05 00:38:45 -04:00
|
|
|
|
Sensitive = true
|
|
|
|
|
},
|
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Key = $"{Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_AC_METRIC"]} 5",
|
2018-10-05 23:10:39 -04:00
|
|
|
|
// todo: make sure this is wrapped somewhere else
|
|
|
|
|
Value = $"{Math.Round(((float)hitOffsetAverage), 4).ToString(new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName))}°",
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information,
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Column = 2,
|
|
|
|
|
Order = 4,
|
2019-04-21 17:28:13 -04:00
|
|
|
|
Extra = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_TITLE_ACM5"],
|
2018-04-05 00:38:45 -04:00
|
|
|
|
Sensitive = true
|
2018-05-03 01:25:49 -04:00
|
|
|
|
},
|
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Key = $"{Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_AC_METRIC"]} 6",
|
|
|
|
|
Value = Math.Round(maxStrain, 3).ToString(new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)),
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information,
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Column = 2,
|
|
|
|
|
Order = 5,
|
2019-04-21 17:28:13 -04:00
|
|
|
|
Extra = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_TITLE_ACM6"],
|
2018-05-03 01:25:49 -04:00
|
|
|
|
Sensitive = true
|
|
|
|
|
},
|
2019-06-15 18:37:43 -04:00
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Key = $"{Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_AC_METRIC"]} 7",
|
|
|
|
|
Value = Math.Round(averageRecoilAmount, 3).ToString(new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)),
|
|
|
|
|
Type = ProfileMeta.MetaType.Information,
|
|
|
|
|
Column = 2,
|
|
|
|
|
Order = 5,
|
|
|
|
|
Extra = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_TITLE_ACM7"],
|
|
|
|
|
Sensitive = true
|
|
|
|
|
},
|
2019-09-09 18:40:04 -04:00
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Key = $"{Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_AC_METRIC"]} 8",
|
|
|
|
|
Value = Math.Round(averageSnapValue, 3).ToString(new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)),
|
|
|
|
|
Type = ProfileMeta.MetaType.Information,
|
|
|
|
|
Column = 2,
|
|
|
|
|
Order = 6,
|
|
|
|
|
Extra = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_TITLE_ACM8"],
|
|
|
|
|
Sensitive = true
|
|
|
|
|
}
|
2018-02-14 14:01:26 -05:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 22:56:56 -04:00
|
|
|
|
async Task<List<ProfileMeta>> getMessages(int clientId, int offset, int count, DateTime? startAt)
|
2018-02-14 14:01:26 -05:00
|
|
|
|
{
|
2019-03-27 20:40:26 -04:00
|
|
|
|
if (count <= 1)
|
|
|
|
|
{
|
|
|
|
|
using (var ctx = new DatabaseContext(true))
|
|
|
|
|
{
|
|
|
|
|
return new List<ProfileMeta>
|
|
|
|
|
{
|
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_MESSAGES"],
|
2019-03-30 18:21:01 -04:00
|
|
|
|
Value = (await ctx.Set<EFClientMessage>()
|
|
|
|
|
.CountAsync(_message => _message.ClientId == clientId))
|
|
|
|
|
.ToString("#,##0", new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)),
|
|
|
|
|
Column = 1,
|
|
|
|
|
Order= 4,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Type = ProfileMeta.MetaType.Information
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-07 22:34:30 -04:00
|
|
|
|
List<ProfileMeta> messageMeta;
|
|
|
|
|
using (var ctx = new DatabaseContext(disableTracking: true))
|
2018-02-14 14:01:26 -05:00
|
|
|
|
{
|
2019-03-29 22:56:56 -04:00
|
|
|
|
var messages = ctx.Set<EFClientMessage>()
|
|
|
|
|
.Where(m => m.ClientId == clientId)
|
|
|
|
|
.Where(_message => _message.TimeSent < startAt)
|
2019-03-27 20:40:26 -04:00
|
|
|
|
.OrderByDescending(_message => _message.TimeSent)
|
|
|
|
|
.Skip(offset)
|
|
|
|
|
.Take(count);
|
2018-10-07 22:34:30 -04:00
|
|
|
|
|
|
|
|
|
messageMeta = await messages.Select(m => new ProfileMeta()
|
|
|
|
|
{
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Key = null,
|
2019-04-23 18:27:20 -04:00
|
|
|
|
Value = new { m.Message, m.Server.GameName },
|
2018-10-07 22:34:30 -04:00
|
|
|
|
When = m.TimeSent,
|
2019-03-27 20:40:26 -04:00
|
|
|
|
Extra = m.ServerId.ToString(),
|
|
|
|
|
Type = ProfileMeta.MetaType.ChatMessage
|
2018-10-07 22:34:30 -04:00
|
|
|
|
}).ToListAsync();
|
2019-04-23 18:27:20 -04:00
|
|
|
|
|
|
|
|
|
foreach (var message in messageMeta)
|
|
|
|
|
{
|
|
|
|
|
if ((message.Value.Message as string).IsQuickMessage())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var quickMessages = ServerManager.GetApplicationSettings().Configuration()
|
|
|
|
|
.QuickMessages
|
|
|
|
|
.First(_qm => _qm.Game == message.Value.GameName);
|
|
|
|
|
message.Value = quickMessages.Messages[(message.Value.Message as string).Substring(1)];
|
|
|
|
|
message.Type = ProfileMeta.MetaType.QuickMessage;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
message.Value = message.Value.Message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
message.Value = message.Value.Message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-07 22:34:30 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-14 14:01:26 -05:00
|
|
|
|
return messageMeta;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-22 14:50:09 -04:00
|
|
|
|
if (Config.Configuration().EnableAntiCheat)
|
|
|
|
|
{
|
2019-02-22 20:06:51 -05:00
|
|
|
|
MetaService.AddRuntimeMeta(getAnticheatInfo);
|
2018-03-22 14:50:09 -04:00
|
|
|
|
}
|
2018-04-05 00:38:45 -04:00
|
|
|
|
|
2019-03-27 20:40:26 -04:00
|
|
|
|
MetaService.AddRuntimeMeta(getStats);
|
2019-02-22 20:06:51 -05:00
|
|
|
|
MetaService.AddRuntimeMeta(getMessages);
|
2018-02-14 14:01:26 -05:00
|
|
|
|
|
2019-02-19 20:39:09 -05:00
|
|
|
|
async Task<string> totalKills(Server server)
|
2018-02-09 02:21:25 -05:00
|
|
|
|
{
|
2018-10-07 22:34:30 -04:00
|
|
|
|
using (var ctx = new DatabaseContext(disableTracking: true))
|
|
|
|
|
{
|
2019-02-18 20:30:38 -05:00
|
|
|
|
long kills = await ctx.Set<EFServerStatistics>().Where(s => s.Active).SumAsync(s => s.TotalKills);
|
2019-03-30 18:21:01 -04:00
|
|
|
|
return kills.ToString("#,##0", new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName));
|
2018-10-07 22:34:30 -04:00
|
|
|
|
}
|
2018-02-09 02:21:25 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-19 20:39:09 -05:00
|
|
|
|
async Task<string> totalPlayTime(Server server)
|
2018-02-09 02:21:25 -05:00
|
|
|
|
{
|
2018-10-07 22:34:30 -04:00
|
|
|
|
using (var ctx = new DatabaseContext(disableTracking: true))
|
|
|
|
|
{
|
2019-02-18 20:30:38 -05:00
|
|
|
|
long playTime = await ctx.Set<EFServerStatistics>().Where(s => s.Active).SumAsync(s => s.TotalPlayTime);
|
2019-03-30 18:21:01 -04:00
|
|
|
|
return (playTime / 3600.0).ToString("#,##0", new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName));
|
2018-10-07 22:34:30 -04:00
|
|
|
|
}
|
2018-02-09 02:21:25 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-19 20:39:09 -05:00
|
|
|
|
async Task<string> topStats(Server s)
|
2018-05-05 16:36:26 -04:00
|
|
|
|
{
|
2019-02-19 20:39:09 -05:00
|
|
|
|
return string.Join(Environment.NewLine, await Commands.TopStats.GetTopStats(s));
|
2018-05-05 16:36:26 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-19 20:39:09 -05:00
|
|
|
|
async Task<string> mostPlayed(Server s)
|
2018-05-21 17:09:27 -04:00
|
|
|
|
{
|
2019-02-19 20:39:09 -05:00
|
|
|
|
return string.Join(Environment.NewLine, await Commands.MostPlayed.GetMostPlayed(s));
|
2018-05-21 17:09:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 02:21:25 -05:00
|
|
|
|
manager.GetMessageTokens().Add(new MessageToken("TOTALKILLS", totalKills));
|
|
|
|
|
manager.GetMessageTokens().Add(new MessageToken("TOTALPLAYTIME", totalPlayTime));
|
2018-05-05 16:36:26 -04:00
|
|
|
|
manager.GetMessageTokens().Add(new MessageToken("TOPSTATS", topStats));
|
2018-05-21 17:09:27 -04:00
|
|
|
|
manager.GetMessageTokens().Add(new MessageToken("MOSTPLAYED", mostPlayed));
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
|
|
|
|
ServerManager = manager;
|
2018-03-18 22:25:11 -04:00
|
|
|
|
Manager = new StatManager(manager);
|
2017-05-31 01:31:56 -04:00
|
|
|
|
}
|
2015-08-20 17:54:38 -04:00
|
|
|
|
|
2018-11-27 19:31:48 -05:00
|
|
|
|
public Task OnTickAsync(Server S)
|
|
|
|
|
{
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
2015-08-20 17:54:38 -04:00
|
|
|
|
|
2018-02-10 01:26:38 -05:00
|
|
|
|
public async Task OnUnloadAsync()
|
2015-08-20 17:54:38 -04:00
|
|
|
|
{
|
2018-02-10 01:26:38 -05:00
|
|
|
|
foreach (var sv in ServerManager.GetServers())
|
2018-11-27 19:31:48 -05:00
|
|
|
|
{
|
2018-02-10 01:26:38 -05:00
|
|
|
|
await Manager.Sync(sv);
|
2018-11-27 19:31:48 -05:00
|
|
|
|
}
|
2015-08-20 17:54:38 -04:00
|
|
|
|
}
|
2019-04-25 14:00:54 -04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if the event should be ignored
|
|
|
|
|
/// (If the client id or target id is not a real client or the target/origin is a bot and ignore bots is turned on)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="origin"></param>
|
|
|
|
|
/// <param name="target"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private bool ShouldIgnoreEvent(EFClient origin, EFClient target)
|
|
|
|
|
{
|
2019-09-09 18:40:04 -04:00
|
|
|
|
return ((origin?.NetworkId <= 1 && target?.NetworkId <= 1) || (origin?.ClientId <= 1 && target?.ClientId <= 1));
|
2019-04-25 14:00:54 -04:00
|
|
|
|
}
|
2019-05-29 17:55:35 -04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if the damage occurs from world (fall damage/certain killstreaks)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="origin"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private bool IsWorldDamage(EFClient origin) => origin?.NetworkId == 1;
|
2015-08-20 17:54:38 -04:00
|
|
|
|
}
|
2018-02-07 00:19:06 -05:00
|
|
|
|
}
|