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;
|
|
|
|
|
using SharedLibraryCore.Database;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
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
|
|
|
|
|
{
|
2018-11-05 22:01:29 -05:00
|
|
|
|
public ResetStats() : base("resetstats", Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_RESET_DESC"], "rs", EFClient.Permission.User, false) { }
|
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
|
|
|
|
|
2018-11-27 19:31:48 -05:00
|
|
|
|
long serverId = await 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
|
2018-11-27 19:31:48 -05:00
|
|
|
|
Plugin.Manager.ResetStats(E.Origin.ClientId, serverId);
|
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();
|
|
|
|
|
}
|
2018-09-29 15:52:22 -04:00
|
|
|
|
E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_RESET_SUCCESS"]);
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-09-29 15:52:22 -04:00
|
|
|
|
E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_RESET_FAIL"]);
|
2018-02-10 01:26:38 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|