2018-04-08 16:50:58 -05:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Services;
|
|
|
|
|
using IW4MAdmin.Plugins.Stats.Models;
|
2018-02-10 00:26:38 -06:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-10-07 21:34:30 -05:00
|
|
|
|
using SharedLibraryCore.Database;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2018-10-15 19:51:04 -05:00
|
|
|
|
using IW4MAdmin.Plugins.Stats.Helpers;
|
2018-11-05 21:01:29 -06:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-02-10 00:26:38 -06:00
|
|
|
|
|
2018-04-08 16:50:58 -05:00
|
|
|
|
namespace IW4MAdmin.Plugins.Stats.Commands
|
2018-02-10 00:26:38 -06:00
|
|
|
|
{
|
|
|
|
|
public class CViewStats : Command
|
|
|
|
|
{
|
2018-11-05 21:01:29 -06:00
|
|
|
|
public CViewStats() : base("stats", Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_VIEW_DESC"], "xlrstats", EFClient.Permission.User, false, new CommandArgument[]
|
2018-02-10 00:26:38 -06:00
|
|
|
|
{
|
|
|
|
|
new CommandArgument()
|
|
|
|
|
{
|
|
|
|
|
Name = "player",
|
|
|
|
|
Required = false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
{ }
|
|
|
|
|
|
2018-04-13 01:32:30 -05:00
|
|
|
|
public override async Task ExecuteAsync(GameEvent E)
|
2018-02-10 00:26:38 -06:00
|
|
|
|
{
|
2018-05-05 15:36:26 -05:00
|
|
|
|
var loc = Utilities.CurrentLocalization.LocalizationIndex;
|
2018-04-24 17:01:27 -05:00
|
|
|
|
|
2018-02-10 00:26:38 -06:00
|
|
|
|
String statLine;
|
|
|
|
|
EFClientStatistics pStats;
|
|
|
|
|
|
|
|
|
|
if (E.Data.Length > 0 && E.Target == null)
|
|
|
|
|
{
|
2018-06-05 16:31:36 -05:00
|
|
|
|
E.Target = E.Owner.GetClientByName(E.Data).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (E.Target == null)
|
|
|
|
|
{
|
2018-09-29 14:52:22 -05:00
|
|
|
|
E.Origin.Tell(loc["PLUGINS_STATS_COMMANDS_VIEW_FAIL"]);
|
2018-06-05 16:31:36 -05:00
|
|
|
|
}
|
2018-02-10 00:26:38 -06:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-23 18:34:31 -05:00
|
|
|
|
long serverId = StatManager.GetIdForServer(E.Owner);
|
2018-02-10 00:26:38 -06:00
|
|
|
|
|
2019-09-09 17:40:04 -05:00
|
|
|
|
|
|
|
|
|
if (E.Target != null)
|
2018-02-10 00:26:38 -06:00
|
|
|
|
{
|
2019-09-09 17:40:04 -05:00
|
|
|
|
int performanceRanking = await StatManager.GetClientOverallRanking(E.Target.ClientId);
|
|
|
|
|
string performanceRankingString = performanceRanking == 0 ? loc["WEBFRONT_STATS_INDEX_UNRANKED"] : $"{loc["WEBFRONT_STATS_INDEX_RANKED"]} #{performanceRanking}";
|
2018-10-15 19:51:04 -05:00
|
|
|
|
|
2019-09-09 17:40:04 -05:00
|
|
|
|
if (E.Owner.GetClientsAsList().Any(_client => _client.Equals(E.Target)))
|
|
|
|
|
{
|
2019-10-18 13:39:21 -05:00
|
|
|
|
pStats = E.Target.GetAdditionalProperty<EFClientStatistics>(StatManager.CLIENT_STATS_KEY);
|
2018-10-07 21:34:30 -05:00
|
|
|
|
}
|
2018-02-10 00:26:38 -06:00
|
|
|
|
|
2018-10-07 21:34:30 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-09 17:40:04 -05:00
|
|
|
|
using (var ctx = new DatabaseContext(true))
|
|
|
|
|
{
|
|
|
|
|
pStats = (await ctx.Set<EFClientStatistics>().FirstAsync(c => c.ServerId == serverId && c.ClientId == E.Target.ClientId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
statLine = $"^5{pStats.Kills} ^7{loc["PLUGINS_STATS_TEXT_KILLS"]} | ^5{pStats.Deaths} ^7{loc["PLUGINS_STATS_TEXT_DEATHS"]} | ^5{pStats.KDR} ^7KDR | ^5{pStats.Performance} ^7{loc["PLUGINS_STATS_COMMANDS_PERFORMANCE"].ToUpper()} | {performanceRankingString}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int performanceRanking = await StatManager.GetClientOverallRanking(E.Origin.ClientId);
|
|
|
|
|
string performanceRankingString = performanceRanking == 0 ? loc["WEBFRONT_STATS_INDEX_UNRANKED"] : $"{loc["WEBFRONT_STATS_INDEX_RANKED"]} #{performanceRanking}";
|
|
|
|
|
|
|
|
|
|
if (E.Owner.GetClientsAsList().Any(_client => _client.Equals(E.Origin)))
|
|
|
|
|
{
|
2019-10-18 13:39:21 -05:00
|
|
|
|
pStats = E.Origin.GetAdditionalProperty<EFClientStatistics>(StatManager.CLIENT_STATS_KEY);
|
2019-09-09 17:40:04 -05:00
|
|
|
|
}
|
2018-10-15 19:51:04 -05:00
|
|
|
|
|
2019-09-09 17:40:04 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
using (var ctx = new DatabaseContext(true))
|
|
|
|
|
{
|
|
|
|
|
pStats = (await ctx.Set<EFClientStatistics>().FirstAsync(c => c.ServerId == serverId && c.ClientId == E.Origin.ClientId));
|
|
|
|
|
}
|
2018-10-07 21:34:30 -05:00
|
|
|
|
}
|
2019-09-09 17:40:04 -05:00
|
|
|
|
statLine = $"^5{pStats.Kills} ^7{loc["PLUGINS_STATS_TEXT_KILLS"]} | ^5{pStats.Deaths} ^7{loc["PLUGINS_STATS_TEXT_DEATHS"]} | ^5{pStats.KDR} ^7KDR | ^5{pStats.Performance} ^7{loc["PLUGINS_STATS_COMMANDS_PERFORMANCE"].ToUpper()} | {performanceRankingString}";
|
2018-02-10 00:26:38 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (E.Message.IsBroadcastCommand())
|
|
|
|
|
{
|
|
|
|
|
string name = E.Target == null ? E.Origin.Name : E.Target.Name;
|
2019-04-09 15:02:49 -05:00
|
|
|
|
E.Owner.Broadcast(loc["PLUGINS_STATS_COMMANDS_VIEW_SUCCESS"].FormatExt(name));
|
2018-09-29 14:52:22 -05:00
|
|
|
|
E.Owner.Broadcast(statLine);
|
2018-02-10 00:26:38 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (E.Target != null)
|
2018-09-29 14:52:22 -05:00
|
|
|
|
{
|
2019-04-09 15:02:49 -05:00
|
|
|
|
E.Origin.Tell(loc["PLUGINS_STATS_COMMANDS_VIEW_SUCCESS"].FormatExt(E.Target.Name));
|
2018-09-29 14:52:22 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
E.Origin.Tell(statLine);
|
2018-02-10 00:26:38 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|