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-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-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-10 01:26:38 -05:00
|
|
|
|
// todo: is this fast?
|
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-09 02:21:25 -05:00
|
|
|
|
.Sum(c => c.TotalKills).ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string totalPlayTime()
|
|
|
|
|
{
|
|
|
|
|
var serverStats = new GenericRepository<EFServerStatistics>();
|
|
|
|
|
return serverStats.GetQuery(s => s.Active)
|
|
|
|
|
.Sum(c => c.TotalPlayTime).ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|