mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
re-added the kill server command (can only be used if run as admin)
less warns when using a disposed socket topstats added to tokens as {{TOPSTATS}} fixed topstats reporting for only a single server added fix to iw4 regex for negative score tokens now support multiple lines (using Environment.NewLine to separate) localization includes culture again
This commit is contained in:
@ -8,53 +8,70 @@ using SharedLibraryCore.Objects;
|
||||
using SharedLibraryCore.Services;
|
||||
using IW4MAdmin.Plugins.Stats.Models;
|
||||
using SharedLibraryCore.Database;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace IW4MAdmin.Plugins.Stats.Commands
|
||||
{
|
||||
class TopStats : Command
|
||||
{
|
||||
public TopStats() : base("topstats", Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_COMMANDS_TOP_DESC"], "ts", Player.Permission.User, false) { }
|
||||
|
||||
public override async Task ExecuteAsync(GameEvent E)
|
||||
public static async Task<List<string>> GetTopStats(Server s)
|
||||
{
|
||||
var statsSvc = new GenericRepository<EFClientStatistics>();
|
||||
int serverId = E.Owner.GetHashCode();
|
||||
int serverId = s.GetHashCode();
|
||||
List<string> topStatsText = new List<string>()
|
||||
{
|
||||
$"^5--{Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_TOP_TEXT"]}--"
|
||||
};
|
||||
|
||||
using (var db = new DatabaseContext())
|
||||
{
|
||||
db.ChangeTracker.AutoDetectChangesEnabled = false;
|
||||
db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
|
||||
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();
|
||||
|
||||
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
|
||||
select $"^3{client.Name}^7 - ^5{stats.KDR} ^7KDR | ^5{stats.Skill} ^7{Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_TEXT_SKILL"]}")
|
||||
.Take(5);
|
||||
|
||||
if (!E.Message.IsBroadcastCommand())
|
||||
topStatsText.AddRange(await iqStats.ToListAsync());
|
||||
}
|
||||
|
||||
// no one qualified
|
||||
if (topStatsText.Count == 0)
|
||||
{
|
||||
topStatsText = new List<string>()
|
||||
{
|
||||
await E.Origin.Tell($"^5--{Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_COMMANDS_TOP_TEXT"]}--");
|
||||
Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_TEXT_NOQUALIFY"]
|
||||
};
|
||||
}
|
||||
|
||||
foreach (var stat in topStats)
|
||||
await E.Origin.Tell($"^3{stat.Name}^7 - ^5{stat.KDR} ^7KDR | ^5{stat.Skill} ^7{Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_TEXT_SKILL"]}");
|
||||
}
|
||||
else
|
||||
{
|
||||
await E.Owner.Broadcast($"^5--{Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_COMMANDS_TOP_TEXT"]}--");
|
||||
return topStatsText;
|
||||
}
|
||||
|
||||
foreach (var stat in topStats)
|
||||
await E.Owner.Broadcast($"^3{stat.Name}^7 - ^5{stat.KDR} ^7KDR | ^5{stat.Skill} ^7{Utilities.CurrentLocalization.LocalizationSet["PLUGINS_STATS_TEXT_SKILL"]}");
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user