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.Services;
|
|
|
|
|
using IW4MAdmin.Plugins.Stats.Models;
|
|
|
|
|
using SharedLibraryCore.Database;
|
2018-05-05 16:36:26 -04:00
|
|
|
|
using System.Collections.Generic;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-11-27 19:31:48 -05:00
|
|
|
|
using IW4MAdmin.Plugins.Stats.Helpers;
|
2018-05-05 16:36:26 -04:00
|
|
|
|
|
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-11-27 19:31:48 -05:00
|
|
|
|
long serverId = await StatManager.GetIdForServer(s);
|
2018-05-05 16:36:26 -04:00
|
|
|
|
List<string> topStatsText = new List<string>()
|
|
|
|
|
{
|
|
|
|
|
$"^5--{Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_TOP_TEXT"]}--"
|
|
|
|
|
};
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
2018-09-23 20:45:54 -04:00
|
|
|
|
using (var db = new DatabaseContext(true))
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
2018-09-23 20:45:54 -04:00
|
|
|
|
var fifteenDaysAgo = DateTime.UtcNow.AddDays(-15);
|
2018-04-10 02:38:18 -04:00
|
|
|
|
|
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
|
2018-09-23 20:45:54 -04:00
|
|
|
|
where stats.TimePlayed >= Plugin.Config.Configuration().TopPlayersMinPlayTime
|
2018-11-05 22:01:29 -05:00
|
|
|
|
where client.Level != EFClient.Permission.Banned
|
2018-09-23 20:45:54 -04:00
|
|
|
|
where client.LastConnection >= fifteenDaysAgo
|
2018-05-17 19:31:58 -04:00
|
|
|
|
orderby stats.Performance descending
|
2018-05-16 00:57:37 -04:00
|
|
|
|
select new
|
|
|
|
|
{
|
|
|
|
|
stats.KDR,
|
2018-05-17 19:31:58 -04:00
|
|
|
|
stats.Performance,
|
2018-05-16 00:57:37 -04:00
|
|
|
|
alias.Name
|
|
|
|
|
})
|
2018-05-05 16:36:26 -04:00
|
|
|
|
.Take(5);
|
|
|
|
|
|
2018-09-23 20:45:54 -04:00
|
|
|
|
#if DEBUG == true
|
|
|
|
|
var statsSql = iqStats.ToSql();
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-05-16 00:57:37 -04:00
|
|
|
|
var statsList = (await iqStats.ToListAsync())
|
2018-05-17 19:31:58 -04:00
|
|
|
|
.Select(stats => $"^3{stats.Name}^7 - ^5{stats.KDR} ^7{Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_TEXT_KDR"]} | ^5{stats.Performance} ^7{Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_PERFORMANCE"]}");
|
2018-05-16 00:57:37 -04:00
|
|
|
|
|
|
|
|
|
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-11-05 22:01:29 -05:00
|
|
|
|
public TopStats() : base("topstats", Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_TOP_DESC"], "ts", EFClient.Permission.User, false) { }
|
2018-05-05 16:36:26 -04:00
|
|
|
|
|
|
|
|
|
public override async Task ExecuteAsync(GameEvent E)
|
|
|
|
|
{
|
|
|
|
|
var topStats = await GetTopStats(E.Owner);
|
|
|
|
|
if (!E.Message.IsBroadcastCommand())
|
|
|
|
|
{
|
|
|
|
|
foreach (var stat in topStats)
|
2018-09-23 20:45:54 -04:00
|
|
|
|
{
|
2018-09-29 15:52:22 -04:00
|
|
|
|
E.Origin.Tell(stat);
|
|
|
|
|
|
2018-09-23 20:45:54 -04:00
|
|
|
|
}
|
2018-05-05 16:36:26 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var stat in topStats)
|
2018-09-23 20:45:54 -04:00
|
|
|
|
{
|
2018-09-29 15:52:22 -04:00
|
|
|
|
E.Owner.Broadcast(stat);
|
2018-09-23 20:45:54 -04:00
|
|
|
|
}
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|