2018-11-27 19:31:48 -05:00
|
|
|
|
using IW4MAdmin.Plugins.Stats.Models;
|
2018-10-07 22:34:30 -04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2018-11-27 19:31:48 -05:00
|
|
|
|
using SharedLibraryCore;
|
2020-01-31 21:15:07 -05:00
|
|
|
|
using SharedLibraryCore.Configuration;
|
2018-11-27 19:31:48 -05:00
|
|
|
|
using SharedLibraryCore.Database;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2020-01-31 21:15:07 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-11-27 19:31:48 -05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
2018-04-08 17:50:58 -04:00
|
|
|
|
namespace IW4MAdmin.Plugins.Stats.Commands
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
|
|
|
|
public class ResetStats : Command
|
|
|
|
|
{
|
2020-01-31 21:15:07 -05:00
|
|
|
|
public ResetStats(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, translationLookup)
|
|
|
|
|
{
|
|
|
|
|
Name = "resetstats";
|
|
|
|
|
Description = translationLookup["PLUGINS_STATS_COMMANDS_RESET_DESC"];
|
|
|
|
|
Alias = "rs";
|
|
|
|
|
Permission = EFClient.Permission.User;
|
|
|
|
|
RequiresTarget = false;
|
2020-04-26 22:12:49 -04:00
|
|
|
|
//AllowImpersonation = true;
|
2020-01-31 21:15:07 -05:00
|
|
|
|
}
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
public override async Task ExecuteAsync(GameEvent E)
|
2018-02-10 01:26:38 -05:00
|
|
|
|
{
|
|
|
|
|
if (E.Origin.ClientNumber >= 0)
|
|
|
|
|
{
|
2018-10-07 22:34:30 -04:00
|
|
|
|
|
2019-08-23 19:34:31 -04:00
|
|
|
|
long serverId = Helpers.StatManager.GetIdForServer(E.Owner);
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
2018-10-07 22:34:30 -04:00
|
|
|
|
EFClientStatistics clientStats;
|
|
|
|
|
using (var ctx = new DatabaseContext(disableTracking: true))
|
|
|
|
|
{
|
|
|
|
|
clientStats = await ctx.Set<EFClientStatistics>()
|
2018-11-27 19:31:48 -05:00
|
|
|
|
.Where(s => s.ClientId == E.Origin.ClientId)
|
|
|
|
|
.Where(s => s.ServerId == serverId)
|
2018-10-07 22:34:30 -04:00
|
|
|
|
.FirstAsync();
|
|
|
|
|
|
|
|
|
|
clientStats.Deaths = 0;
|
|
|
|
|
clientStats.Kills = 0;
|
|
|
|
|
clientStats.SPM = 0.0;
|
|
|
|
|
clientStats.Skill = 0.0;
|
|
|
|
|
clientStats.TimePlayed = 0;
|
|
|
|
|
// todo: make this more dynamic
|
|
|
|
|
clientStats.EloRating = 200.0;
|
2018-02-10 01:26:38 -05:00
|
|
|
|
|
2018-10-07 22:34:30 -04:00
|
|
|
|
// reset the cached version
|
2019-10-18 14:39:21 -04:00
|
|
|
|
Plugin.Manager.ResetStats(E.Origin);
|
2018-03-06 02:22:19 -05:00
|
|
|
|
|
2018-10-07 22:34:30 -04:00
|
|
|
|
// fixme: this doesn't work properly when another context exists
|
|
|
|
|
await ctx.SaveChangesAsync();
|
|
|
|
|
}
|
2020-01-31 21:15:07 -05:00
|
|
|
|
E.Origin.Tell(_translationLookup["PLUGINS_STATS_COMMANDS_RESET_SUCCESS"]);
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-01-31 21:15:07 -05:00
|
|
|
|
E.Origin.Tell(_translationLookup["PLUGINS_STATS_COMMANDS_RESET_FAIL"]);
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|