1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

fix issue with view stats and reset stats failing

fix issue with set level returning wrong error message if setting a client to the same level they're currently at
update CoD4x parser version
update nuget packages
This commit is contained in:
RaidMax
2020-12-16 13:11:30 -06:00
parent c53895ca11
commit 50f7767bf1
11 changed files with 139 additions and 70 deletions

View File

@ -23,40 +23,44 @@ namespace IW4MAdmin.Plugins.Stats.Commands
Permission = EFClient.Permission.User;
RequiresTarget = false;
AllowImpersonation = true;
_contextFactory = contextFactory;
}
public override async Task ExecuteAsync(GameEvent E)
public override async Task ExecuteAsync(GameEvent gameEvent)
{
if (E.Origin.ClientNumber >= 0)
if (gameEvent.Origin.ClientNumber >= 0)
{
var serverId = Helpers.StatManager.GetIdForServer(gameEvent.Owner);
long serverId = Helpers.StatManager.GetIdForServer(E.Owner);
EFClientStatistics clientStats;
await using var context = _contextFactory.CreateContext();
clientStats = await context.Set<EFClientStatistics>()
.Where(s => s.ClientId == E.Origin.ClientId)
var clientStats = await context.Set<EFClientStatistics>()
.Where(s => s.ClientId == gameEvent.Origin.ClientId)
.Where(s => 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;
.FirstOrDefaultAsync();
// want to prevent resetting stats before they've gotten any kills
if (clientStats != null)
{
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;
await context.SaveChangesAsync();
}
// reset the cached version
Plugin.Manager.ResetStats(E.Origin);
Plugin.Manager.ResetStats(gameEvent.Origin);
await context.SaveChangesAsync();
E.Origin.Tell(_translationLookup["PLUGINS_STATS_COMMANDS_RESET_SUCCESS"]);
gameEvent.Origin.Tell(_translationLookup["PLUGINS_STATS_COMMANDS_RESET_SUCCESS"]);
}
else
{
E.Origin.Tell(_translationLookup["PLUGINS_STATS_COMMANDS_RESET_FAIL"]);
gameEvent.Origin.Tell(_translationLookup["PLUGINS_STATS_COMMANDS_RESET_FAIL"]);
}
}
}