2018-04-10 02:38:18 -04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2018-02-10 01:26:38 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2018-04-10 02:38:18 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Objects;
|
|
|
|
|
using SharedLibraryCore.Services;
|
|
|
|
|
using IW4MAdmin.Plugins.Stats.Models;
|
|
|
|
|
using SharedLibraryCore.Database;
|
2018-04-08 17:50:58 -04:00
|
|
|
|
namespace IW4MAdmin.Plugins.Stats.Commands
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
|
|
|
|
class TopStats : Command
|
|
|
|
|
{
|
|
|
|
|
public TopStats() : base("topstats", "view the top 5 players on this server", "ts", Player.Permission.User, false) { }
|
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
public override async Task ExecuteAsync(GameEvent E)
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
|
|
|
|
var statsSvc = new GenericRepository<EFClientStatistics>();
|
2018-03-25 00:32:54 -04:00
|
|
|
|
int serverId = E.Owner.GetHashCode();
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
2018-04-10 02:38:18 -04:00
|
|
|
|
using (var db = new DatabaseContext())
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
2018-04-10 02:38:18 -04:00
|
|
|
|
var thirtyDaysAgo = DateTime.UtcNow.AddMonths(-1);
|
|
|
|
|
var topStats = await (from stats in db.Set<EFClientStatistics>()
|
|
|
|
|
join client in db.Clients
|
|
|
|
|
on stats.ClientId equals client.ClientId
|
|
|
|
|
join alias in db.Aliases
|
|
|
|
|
on client.CurrentAliasId equals alias.AliasId
|
|
|
|
|
where stats.TimePlayed >= 3600
|
|
|
|
|
where client.Level != Player.Permission.Banned
|
|
|
|
|
where client.LastConnection >= thirtyDaysAgo
|
|
|
|
|
orderby stats.Skill descending
|
|
|
|
|
select new
|
|
|
|
|
{
|
|
|
|
|
alias.Name,
|
|
|
|
|
stats.KDR,
|
|
|
|
|
stats.Skill
|
|
|
|
|
})
|
|
|
|
|
.Take(5)
|
|
|
|
|
.ToListAsync();
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
|
|
|
|
|
2018-04-10 02:38:18 -04:00
|
|
|
|
if (!E.Message.IsBroadcastCommand())
|
|
|
|
|
{
|
|
|
|
|
await E.Origin.Tell("^5--Top Players--");
|
|
|
|
|
|
|
|
|
|
foreach (var stat in topStats)
|
|
|
|
|
await E.Origin.Tell($"^3{stat.Name}^7 - ^5{stat.KDR} ^7KDR | ^5{stat.Skill} ^7SKILL");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await E.Owner.Broadcast("^5--Top Players--");
|
|
|
|
|
|
|
|
|
|
foreach (var stat in topStats)
|
|
|
|
|
await E.Owner.Broadcast($"^3{stat.Name}^7 - ^5{stat.KDR} ^7KDR | ^5{stat.Skill} ^7SKILL");
|
|
|
|
|
}
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|