2018-05-16 00:57:37 -04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Objects;
|
|
|
|
|
using IW4MAdmin.Plugins.Stats.Models;
|
|
|
|
|
using SharedLibraryCore.Database;
|
|
|
|
|
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-16 00:57:37 -04:00
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Plugins.Stats.Commands
|
|
|
|
|
{
|
|
|
|
|
class MostPlayed : Command
|
|
|
|
|
{
|
|
|
|
|
public static async Task<List<string>> GetMostPlayed(Server s)
|
|
|
|
|
{
|
2018-11-27 19:31:48 -05:00
|
|
|
|
long serverId = await StatManager.GetIdForServer(s);
|
|
|
|
|
|
2018-05-16 00:57:37 -04:00
|
|
|
|
List<string> mostPlayed = new List<string>()
|
|
|
|
|
{
|
|
|
|
|
$"^5--{Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_MOSTPLAYED_TEXT"]}--"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using (var db = new DatabaseContext())
|
|
|
|
|
{
|
|
|
|
|
db.ChangeTracker.AutoDetectChangesEnabled = false;
|
|
|
|
|
db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
|
|
|
|
|
|
|
|
|
var thirtyDaysAgo = DateTime.UtcNow.AddMonths(-1);
|
|
|
|
|
|
|
|
|
|
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-11-05 22:01:29 -05:00
|
|
|
|
where client.Level != EFClient.Permission.Banned
|
2018-05-16 00:57:37 -04:00
|
|
|
|
where client.LastConnection >= thirtyDaysAgo
|
|
|
|
|
orderby stats.Kills descending
|
|
|
|
|
select new
|
|
|
|
|
{
|
|
|
|
|
alias.Name,
|
|
|
|
|
client.TotalConnectionTime,
|
|
|
|
|
stats.Kills
|
|
|
|
|
})
|
|
|
|
|
.Take(5);
|
|
|
|
|
|
|
|
|
|
var iqList = await iqStats.ToListAsync();
|
|
|
|
|
|
|
|
|
|
mostPlayed.AddRange(iqList.Select(stats =>
|
|
|
|
|
$"^3{stats.Name}^7 - ^5{stats.Kills} ^7{Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_TEXT_KILLS"]} | ^5{Utilities.GetTimePassed(DateTime.UtcNow.AddSeconds(-stats.TotalConnectionTime), false)} ^7{Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_PROFILE_PLAYER"].ToLower()}"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return mostPlayed;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 22:01:29 -05:00
|
|
|
|
public MostPlayed() : base("mostplayed", Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_MOSTPLAYED_DESC"], "mp", EFClient.Permission.User, false) { }
|
2018-05-16 00:57:37 -04:00
|
|
|
|
|
|
|
|
|
public override async Task ExecuteAsync(GameEvent E)
|
|
|
|
|
{
|
|
|
|
|
var topStats = await GetMostPlayed(E.Owner);
|
|
|
|
|
if (!E.Message.IsBroadcastCommand())
|
|
|
|
|
{
|
|
|
|
|
foreach (var stat in topStats)
|
2018-09-29 15:52:22 -04:00
|
|
|
|
{
|
|
|
|
|
E.Origin.Tell(stat);
|
|
|
|
|
}
|
2018-05-16 00:57:37 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var stat in topStats)
|
2018-09-29 15:52:22 -04:00
|
|
|
|
{
|
|
|
|
|
E.Owner.Broadcast(stat);
|
|
|
|
|
}
|
2018-05-16 00:57:37 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|