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-05-05 16:36:26 -04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
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-05-05 16:36:26 -04:00
|
|
|
|
public static async Task<List<string>> GetTopStats(Server s)
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
2018-05-05 16:36:26 -04:00
|
|
|
|
int serverId = s.GetHashCode();
|
|
|
|
|
List<string> topStatsText = new List<string>()
|
|
|
|
|
{
|
|
|
|
|
$"^5--{Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_TOP_TEXT"]}--"
|
|
|
|
|
};
|
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-05-05 16:36:26 -04:00
|
|
|
|
db.ChangeTracker.AutoDetectChangesEnabled = false;
|
|
|
|
|
db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
|
|
|
|
|
2018-04-10 02:38:18 -04:00
|
|
|
|
var thirtyDaysAgo = DateTime.UtcNow.AddMonths(-1);
|
|
|
|
|
|
2018-05-05 16:36:26 -04:00
|
|
|
|
var iqStats = (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.ServerId == serverId
|
|
|
|
|
where stats.TimePlayed >= 3600
|
|
|
|
|
where client.Level != Player.Permission.Banned
|
|
|
|
|
where client.LastConnection >= thirtyDaysAgo
|
|
|
|
|
orderby stats.Skill descending
|
2018-05-16 00:57:37 -04:00
|
|
|
|
select new
|
|
|
|
|
{
|
|
|
|
|
stats.KDR,
|
|
|
|
|
stats.Skill,
|
|
|
|
|
stats.EloRating,
|
|
|
|
|
alias.Name
|
|
|
|
|
})
|
2018-05-05 16:36:26 -04:00
|
|
|
|
.Take(5);
|
|
|
|
|
|
2018-05-16 00:57:37 -04:00
|
|
|
|
var statsList = (await iqStats.ToListAsync())
|
|
|
|
|
.Select(stats => $"^3{stats.Name}^7 - ^5{stats.KDR} ^7{Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_TEXT_KDR"]} | ^5{stats.Skill} ^7{Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_TEXT_SKILL"]} | ^5{stats.EloRating} ^7{Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_TOPSTATS_RATING"]}");
|
|
|
|
|
|
|
|
|
|
topStatsText.AddRange(statsList);
|
2018-05-05 16:36:26 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// no one qualified
|
2018-05-08 00:58:46 -04:00
|
|
|
|
if (topStatsText.Count == 1)
|
2018-05-05 16:36:26 -04:00
|
|
|
|
{
|
|
|
|
|
topStatsText = new List<string>()
|
2018-04-10 02:38:18 -04:00
|
|
|
|
{
|
2018-05-05 16:36:26 -04:00
|
|
|
|
Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_TEXT_NOQUALIFY"]
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return topStatsText;
|
|
|
|
|
}
|
2018-04-10 02:38:18 -04:00
|
|
|
|
|
2018-05-05 16:36:26 -04:00
|
|
|
|
public TopStats() : base("topstats", Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_TOP_DESC"], "ts", Player.Permission.User, false) { }
|
|
|
|
|
|
|
|
|
|
public override async Task ExecuteAsync(GameEvent E)
|
|
|
|
|
{
|
|
|
|
|
var topStats = await GetTopStats(E.Owner);
|
|
|
|
|
if (!E.Message.IsBroadcastCommand())
|
|
|
|
|
{
|
|
|
|
|
foreach (var stat in topStats)
|
|
|
|
|
await E.Origin.Tell(stat);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var stat in topStats)
|
|
|
|
|
await E.Owner.Broadcast(stat);
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|