2018-02-07 00:19:06 -05:00
|
|
|
|
using System;
|
2015-08-20 17:54:38 -04:00
|
|
|
|
using System.Collections.Generic;
|
2018-02-07 00:19:06 -05:00
|
|
|
|
using System.Linq;
|
2017-10-03 19:17:35 -04:00
|
|
|
|
using System.Text;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2018-02-07 00:19:06 -05:00
|
|
|
|
using SharedLibrary;
|
2018-02-14 14:01:26 -05:00
|
|
|
|
using SharedLibrary.Dtos;
|
2018-02-09 02:21:25 -05:00
|
|
|
|
using SharedLibrary.Helpers;
|
2018-02-07 00:19:06 -05:00
|
|
|
|
using SharedLibrary.Interfaces;
|
2018-02-09 02:21:25 -05:00
|
|
|
|
using SharedLibrary.Services;
|
2018-02-07 00:19:06 -05:00
|
|
|
|
using StatsPlugin.Helpers;
|
2018-02-09 02:21:25 -05:00
|
|
|
|
using StatsPlugin.Models;
|
2018-02-10 01:26:38 -05:00
|
|
|
|
using StatsPlugin.Pages;
|
2017-11-25 20:29:58 -05:00
|
|
|
|
|
2015-08-28 00:39:36 -04:00
|
|
|
|
namespace StatsPlugin
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2018-02-07 00:19:06 -05:00
|
|
|
|
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-02-07 00:19:06 -05:00
|
|
|
|
public float Version => 1.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-02-07 00:19:06 -05:00
|
|
|
|
private StatManager Manager;
|
2018-02-10 01:26:38 -05:00
|
|
|
|
private IManager ServerManager;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-05-27 18:08:04 -04:00
|
|
|
|
public async Task OnEventAsync(Event 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-02-07 00:19:06 -05:00
|
|
|
|
case Event.GType.Start:
|
|
|
|
|
Manager.AddServer(S);
|
2015-08-23 17:58:48 -04:00
|
|
|
|
break;
|
2018-02-07 00:19:06 -05:00
|
|
|
|
case Event.GType.Stop:
|
2015-08-23 17:58:48 -04:00
|
|
|
|
break;
|
2018-02-07 00:19:06 -05:00
|
|
|
|
case Event.GType.Connect:
|
|
|
|
|
Manager.AddPlayer(E.Origin);
|
2015-08-23 17:58:48 -04:00
|
|
|
|
break;
|
2018-02-07 00:19:06 -05:00
|
|
|
|
case Event.GType.Disconnect:
|
|
|
|
|
await Manager.RemovePlayer(E.Origin);
|
|
|
|
|
break;
|
|
|
|
|
case Event.GType.Say:
|
2018-02-10 01:26:38 -05:00
|
|
|
|
if (E.Data != string.Empty)
|
|
|
|
|
await Manager.AddMessageAsync(E.Origin.ClientId, E.Owner.GetHashCode(), E.Data);
|
2018-02-07 00:19:06 -05:00
|
|
|
|
break;
|
|
|
|
|
case Event.GType.MapChange:
|
|
|
|
|
break;
|
|
|
|
|
case Event.GType.MapEnd:
|
2018-02-10 01:26:38 -05:00
|
|
|
|
await Manager.Sync(S);
|
2018-02-07 00:19:06 -05:00
|
|
|
|
break;
|
|
|
|
|
case Event.GType.Broadcast:
|
|
|
|
|
break;
|
|
|
|
|
case Event.GType.Tell:
|
|
|
|
|
break;
|
|
|
|
|
case Event.GType.Kick:
|
|
|
|
|
break;
|
|
|
|
|
case Event.GType.Ban:
|
|
|
|
|
break;
|
|
|
|
|
case Event.GType.Remote:
|
|
|
|
|
break;
|
|
|
|
|
case Event.GType.Unknown:
|
|
|
|
|
break;
|
|
|
|
|
case Event.GType.Report:
|
|
|
|
|
break;
|
|
|
|
|
case Event.GType.Flag:
|
|
|
|
|
break;
|
|
|
|
|
case Event.GType.Script:
|
|
|
|
|
break;
|
|
|
|
|
case Event.GType.Kill:
|
|
|
|
|
string[] killInfo = (E.Data != null) ? E.Data.Split(';') : new string[0];
|
|
|
|
|
if (killInfo.Length >= 9 && killInfo[0].Contains("ScriptKill"))
|
2018-02-10 01:26:38 -05:00
|
|
|
|
await Manager.AddScriptKill(E.Origin, E.Target, S.GetHashCode(), S.CurrentMap.Name, killInfo[7], killInfo[8], killInfo[5], killInfo[6], killInfo[3], killInfo[4]);
|
2018-02-10 23:33:42 -05:00
|
|
|
|
else
|
|
|
|
|
await Manager.AddStandardKill(E.Origin, E.Target);
|
2018-02-07 00:19:06 -05:00
|
|
|
|
break;
|
|
|
|
|
case Event.GType.Death:
|
2015-08-23 17:58:48 -04:00
|
|
|
|
break;
|
2015-08-20 17:54:38 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 00:19:06 -05:00
|
|
|
|
public Task OnLoadAsync(IManager manager)
|
2015-08-20 17:54:38 -04:00
|
|
|
|
{
|
2018-02-14 14:01:26 -05:00
|
|
|
|
// meta data info
|
|
|
|
|
async Task<List<ProfileMeta>> getStats(int clientId)
|
|
|
|
|
{
|
|
|
|
|
var statsSvc = new GenericRepository<EFClientStatistics>();
|
|
|
|
|
var clientStats = await statsSvc.FindAsync(c => c.ClientId == clientId);
|
|
|
|
|
|
|
|
|
|
int kills = clientStats.Sum(c => c.Kills);
|
|
|
|
|
int deaths = clientStats.Sum(c => c.Deaths);
|
|
|
|
|
double kdr = Math.Round(clientStats.Sum(c => c.KDR) / clientStats.Count, 2);
|
|
|
|
|
double skill = Math.Round(clientStats.Sum(c => c.Skill) / clientStats.Count, 2);
|
|
|
|
|
|
|
|
|
|
return new List<ProfileMeta>()
|
|
|
|
|
{
|
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Key = "Kills",
|
|
|
|
|
Value = kills
|
|
|
|
|
},
|
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Key = "Deaths",
|
|
|
|
|
Value = deaths
|
|
|
|
|
},
|
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Key = "KDR",
|
|
|
|
|
Value = kdr
|
|
|
|
|
},
|
|
|
|
|
new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Key = "Skill",
|
|
|
|
|
Value = skill
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task<List<ProfileMeta>> getMessages(int clientId)
|
|
|
|
|
{
|
|
|
|
|
var messageSvc = new GenericRepository<EFClientMessage>();
|
|
|
|
|
var messages = await messageSvc.FindAsync(m => m.ClientId == clientId);
|
|
|
|
|
var messageMeta = messages.Select(m => new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Key = "EventMessage",
|
|
|
|
|
Value = m.Message,
|
|
|
|
|
When = m.TimeSent
|
|
|
|
|
}).ToList();
|
|
|
|
|
messageMeta.Add(new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Key = "Messages",
|
|
|
|
|
Value = messages.Count
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return messageMeta;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MetaService.AddMeta(getStats);
|
|
|
|
|
MetaService.AddMeta(getMessages);
|
|
|
|
|
|
|
|
|
|
// todo: is this fast? make async?
|
2018-02-09 02:21:25 -05:00
|
|
|
|
string totalKills()
|
|
|
|
|
{
|
|
|
|
|
var serverStats = new GenericRepository<EFServerStatistics>();
|
2018-02-10 01:26:38 -05:00
|
|
|
|
return serverStats.Find(s => s.Active)
|
2018-02-10 23:33:42 -05:00
|
|
|
|
.Sum(c => c.TotalKills).ToString("#,##0");
|
2018-02-09 02:21:25 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string totalPlayTime()
|
|
|
|
|
{
|
|
|
|
|
var serverStats = new GenericRepository<EFServerStatistics>();
|
2018-02-10 23:33:42 -05:00
|
|
|
|
return Math.Ceiling((serverStats.GetQuery(s => s.Active)
|
|
|
|
|
.Sum(c => c.TotalPlayTime) / 3600.0)).ToString("#,##0");
|
2018-02-09 02:21:25 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
manager.GetMessageTokens().Add(new MessageToken("TOTALKILLS", totalKills));
|
|
|
|
|
manager.GetMessageTokens().Add(new MessageToken("TOTALPLAYTIME", totalPlayTime));
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
|
|
|
|
WebService.PageList.Add(new ClientMessageJson());
|
|
|
|
|
WebService.PageList.Add(new ClientMessages());
|
|
|
|
|
WebService.PageList.Add(new LiveStats());
|
|
|
|
|
|
|
|
|
|
ServerManager = manager;
|
|
|
|
|
|
2018-02-07 00:19:06 -05:00
|
|
|
|
return Task.FromResult(
|
|
|
|
|
Manager = new StatManager(manager)
|
|
|
|
|
);
|
2017-05-31 01:31:56 -04:00
|
|
|
|
}
|
2015-08-20 17:54:38 -04:00
|
|
|
|
|
2018-02-07 00:19:06 -05:00
|
|
|
|
public async Task OnTickAsync(Server S)
|
2015-08-28 00:39:36 -04:00
|
|
|
|
{
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
2015-08-28 00:39:36 -04:00
|
|
|
|
}
|
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())
|
|
|
|
|
await Manager.Sync(sv);
|
2015-08-20 17:54:38 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-07 00:19:06 -05:00
|
|
|
|
}
|