2018-04-08 17:50:58 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Objects;
|
|
|
|
|
using IW4MAdmin.Plugins.Stats.Models;
|
2018-02-10 01:26:38 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-10-07 22:34:30 -04:00
|
|
|
|
using SharedLibraryCore.Database;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
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-05-05 16:36:26 -04:00
|
|
|
|
public ResetStats() : base("resetstats", Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_RESET_DESC"], "rs", Player.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-02-26 23:24:19 -05:00
|
|
|
|
int serverId = E.Owner.GetHashCode();
|
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>()
|
|
|
|
|
.Where(s => s.ClientId == E.Origin.ClientId && s.ServerId == serverId)
|
|
|
|
|
.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
|
|
|
|
|
Plugin.Manager.ResetStats(E.Origin.ClientId, E.Owner.GetHashCode());
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|