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
|
|
|
|
|
{
|
2018-04-24 18:01:27 -04:00
|
|
|
|
public TopStats() : base("topstats", Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_COMMANDS_TOP_DESC"], "ts", Player.Permission.User, false) { }
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
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())
|
|
|
|
|
{
|
2018-04-24 18:01:27 -04:00
|
|
|
|
await E.Origin.Tell($"^5--{Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_COMMANDS_TOP_TEXT"]}--");
|
2018-04-10 02:38:18 -04:00
|
|
|
|
|
|
|
|
|
foreach (var stat in topStats)
|
2018-04-24 18:01:27 -04:00
|
|
|
|
await E.Origin.Tell($"^3{stat.Name}^7 - ^5{stat.KDR} ^7KDR | ^5{stat.Skill} ^7{Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_TEXT_SKILL"]}");
|
2018-04-10 02:38:18 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-24 18:01:27 -04:00
|
|
|
|
await E.Owner.Broadcast($"^5--{Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_COMMANDS_TOP_TEXT"]}--");
|
2018-04-10 02:38:18 -04:00
|
|
|
|
|
|
|
|
|
foreach (var stat in topStats)
|
2018-04-24 18:01:27 -04:00
|
|
|
|
await E.Owner.Broadcast($"^3{stat.Name}^7 - ^5{stat.KDR} ^7KDR | ^5{stat.Skill} ^7{Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_TEXT_SKILL"]}");
|
2018-04-10 02:38:18 -04:00
|
|
|
|
}
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|