1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-07-01 01:20:49 -05:00

clean up rcon, fix a bunch of little things

This commit is contained in:
RaidMax
2018-09-29 14:52:22 -05:00
parent 6b8c112ccf
commit 1fc2d8e460
33 changed files with 993 additions and 813 deletions

View File

@ -139,10 +139,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat
}
// flag
if (
#if DEBUG == false
currentStrain > Thresholds.MaxStrainFlag &&
#endif
if (currentStrain > Thresholds.MaxStrainFlag &&
HitCount >= 10)
{
result = new DetectionPenaltyResult()

View File

@ -63,12 +63,16 @@ namespace IW4MAdmin.Plugins.Stats.Commands
if (!E.Message.IsBroadcastCommand())
{
foreach (var stat in topStats)
await E.Origin.Tell(stat);
{
E.Origin.Tell(stat);
}
}
else
{
foreach (var stat in topStats)
await E.Owner.Broadcast(stat);
{
E.Owner.Broadcast(stat);
}
}
}
}

View File

@ -34,12 +34,12 @@ namespace IW4MAdmin.Plugins.Stats.Commands
// fixme: this doesn't work properly when another context exists
await svc.SaveChangesAsync();
await E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_RESET_SUCCESS"]);
E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_RESET_SUCCESS"]);
}
else
{
await E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_RESET_FAIL"]);
E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_RESET_FAIL"]);
}
}
}

View File

@ -76,16 +76,15 @@ namespace IW4MAdmin.Plugins.Stats.Commands
{
foreach (var stat in topStats)
{
await E.Origin.Tell(stat);
await Task.Delay(SharedLibraryCore.RCon.StaticHelpers.FloodProtectionInterval);
E.Origin.Tell(stat);
}
}
else
{
foreach (var stat in topStats)
{
await E.Owner.Broadcast(stat);
await Task.Delay(SharedLibraryCore.RCon.StaticHelpers.FloodProtectionInterval);
E.Owner.Broadcast(stat);
}
}
}

View File

@ -35,39 +35,40 @@ namespace IW4MAdmin.Plugins.Stats.Commands
if (E.Target == null)
{
await E.Origin.Tell(loc["PLUGINS_STATS_COMMANDS_VIEW_FAIL"]);
return;
E.Origin.Tell(loc["PLUGINS_STATS_COMMANDS_VIEW_FAIL"]);
}
}
var clientStats = new GenericRepository<EFClientStatistics>();
int serverId = E.Owner.GetHashCode();
if (E.Target != null)
{
pStats = clientStats.Find(c => c.ServerId == serverId && c.ClientId == E.Target.ClientId).First();
pStats = (await clientStats.FindAsync(c => c.ServerId == serverId && c.ClientId == E.Target.ClientId)).First();
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()}";
}
else
{
pStats = pStats = clientStats.Find(c => c.ServerId == serverId && c.ClientId == E.Origin.ClientId).First();
pStats = (await clientStats.FindAsync(c => c.ServerId == serverId && c.ClientId == E.Origin.ClientId)).First();
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()}";
}
if (E.Message.IsBroadcastCommand())
{
string name = E.Target == null ? E.Origin.Name : E.Target.Name;
await E.Owner.Broadcast($"{loc["PLUGINS_STATS_COMMANDS_VIEW_SUCCESS"]} ^5{name}^7");
await E.Owner.Broadcast(statLine);
E.Owner.Broadcast($"{loc["PLUGINS_STATS_COMMANDS_VIEW_SUCCESS"]} ^5{name}^7");
E.Owner.Broadcast(statLine);
}
else
{
if (E.Target != null)
await E.Origin.Tell($"{loc["PLUGINS_STATS_COMMANDS_VIEW_SUCCESS"]} ^5{E.Target.Name}^7");
await E.Origin.Tell(statLine);
{
E.Origin.Tell($"{loc["PLUGINS_STATS_COMMANDS_VIEW_SUCCESS"]} ^5{E.Target.Name}^7");
}
E.Origin.Tell(statLine);
}
}
}

View File

@ -243,8 +243,8 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
}
var playerStats = Servers[serverId].PlayerStats;
var statsSvc = ContextThreads[serverId];
var detectionStats = Servers[serverId].PlayerDetections;
var statsSvc = ContextThreads[serverId];
if (playerStats.ContainsKey(pl.ClientId))
{
@ -295,17 +295,6 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
await statsSvc.ClientStatSvc.SaveChangesAsync();
}
// adjusts for adding new hit location
if (clientStats.HitLocations.Count == 19)
{
clientStats.HitLocations.Add(new EFHitLocationCount()
{
Location = IW4Info.HitLocation.shield
});
await statsSvc.ClientStatSvc.SaveChangesAsync();
}
// for stats before rating
if (clientStats.EloRating == 0.0)
{
@ -382,7 +371,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
if (match.Success)
{
// this gives us what time the player is on
// this gives us what team the player is on
var attackerStats = Servers[serverId].PlayerStats[attackerClientId];
var victimStats = Servers[serverId].PlayerStats[victimClientId];
IW4Info.Team victimTeam = (IW4Info.Team)Enum.Parse(typeof(IW4Info.Team), match.Groups[4].ToString());
@ -507,13 +496,14 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
await ApplyPenalty(clientDetection.ProcessTotalRatio(clientStats), clientDetection, attacker, ctx);
}
await ctx.SaveChangesAsync();
await clientStatsSvc.SaveChangesAsync();
await ctx.SaveChangesAsync();
}
catch (Exception ex)
{
Log.WriteError("AC ERROR");
Log.WriteDebug(ex.GetExceptionInfo());
}
OnProcessingPenalty.Release(1);
@ -529,7 +519,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
{
break;
}
await attacker.Ban(Utilities.CurrentLocalization.LocalizationIndex["PLUGIN_STATS_CHEAT_DETECTED"], new Player()
attacker.Ban(Utilities.CurrentLocalization.LocalizationIndex["PLUGIN_STATS_CHEAT_DETECTED"], new Player()
{
ClientId = 1,
AdministeredPenalties = new List<EFPenalty>()
@ -587,80 +577,80 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
while ((change = clientDetection.Tracker.GetNextChange()) != default(EFACSnapshot))
{
//if (change.HitOriginId == 0)
//{
// change.HitOriginId = change.HitOrigin.Vector3Id;
// change.HitOrigin = null;
//}
//if (change.HitDestinationId == 0)
//{
// change.HitDestinationId = change.HitDestination.Vector3Id;
// change.HitDestination = null;
//}
//if (change.CurrentViewAngleId == 0)
//{
// change.CurrentViewAngleId = change.CurrentViewAngle.Vector3Id;
// change.CurrentViewAngle = null;
//}
//if (change.LastStrainAngleId == 0)
//{
// change.LastStrainAngleId = change.LastStrainAngle.Vector3Id;
// change.LastStrainAngle = null;
//}
if (change.HitOrigin.Vector3Id > 0)
{
change.HitOriginId = change.HitOrigin.Vector3Id;
ctx.Attach(change.HitOrigin);
}
else if (change.HitOrigin.Vector3Id == 0)
{
ctx.Add(change.HitOrigin);
}
if (change.HitDestination.Vector3Id > 0)
{
change.HitDestinationId = change.HitDestination.Vector3Id;
ctx.Attach(change.HitDestination);
}
else if (change.HitDestination.Vector3Id == 0)
{
ctx.Add(change.HitOrigin);
}
if (change.CurrentViewAngle.Vector3Id > 0)
{
change.CurrentViewAngleId = change.CurrentViewAngle.Vector3Id;
ctx.Attach(change.CurrentViewAngle);
}
else if (change.CurrentViewAngle.Vector3Id == 0)
{
ctx.Add(change.HitOrigin);
}
if (change.LastStrainAngle.Vector3Id > 0)
{
change.LastStrainAngleId = change.LastStrainAngle.Vector3Id;
ctx.Attach(change.LastStrainAngle);
}
ctx.Add(change);
else if (change.LastStrainAngle.Vector3Id == 0)
{
ctx.Add(change.HitOrigin);
}
ctx.Add(change);
}
}
public async Task AddStandardKill(Player attacker, Player victim)
{
int serverId = attacker.CurrentServer.GetHashCode();
EFClientStatistics attackerStats = null;
try
if (!Servers[serverId].PlayerStats.ContainsKey(attacker.ClientId))
{
attackerStats = await AddPlayer(attacker);
}
else
{
attackerStats = Servers[serverId].PlayerStats[attacker.ClientId];
}
catch (KeyNotFoundException)
EFClientStatistics victimStats = null;
if (!Servers[serverId].PlayerStats.ContainsKey(victim.ClientId))
{
// happens when the client has disconnected before the last status update
Log.WriteWarning($"[Stats::AddStandardKill] kill attacker ClientId is invalid {attacker.ClientId}-{attacker}");
return;
victimStats = await AddPlayer(victim);
}
EFClientStatistics victimStats = null;
try
else
{
victimStats = Servers[serverId].PlayerStats[victim.ClientId];
}
catch (KeyNotFoundException)
{
Log.WriteWarning($"[Stats::AddStandardKill] kill victim ClientId is invalid {victim.ClientId}-{victim}");
return;
}
#if DEBUG
Log.WriteDebug("Calculating standard kill");
#endif
@ -691,7 +681,9 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
StreakMessage.MessageOnStreak(-1, -1);
if (streakMessage != string.Empty)
await attacker.Tell(streakMessage);
{
attacker.Tell(streakMessage);
}
// fixme: why?
if (double.IsNaN(victimStats.SPM) || double.IsNaN(victimStats.Skill))
@ -711,6 +703,8 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
// update their performance
#if !DEBUG
if ((DateTime.UtcNow - attackerStats.LastStatHistoryUpdate).TotalMinutes >= 2.5)
#else
if ((DateTime.UtcNow - attackerStats.LastStatHistoryUpdate).TotalMinutes >= 0.1)
#endif
{
attackerStats.LastStatHistoryUpdate = DateTime.UtcNow;
@ -765,13 +759,6 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
if (clientHistory.RatingHistoryId == 0)
{
ctx.Add(clientHistory);
// Log.WriteDebug($"adding first time client history {client.ClientId}");
await ctx.SaveChangesAsync();
}
else
{
//ctx.Update(clientHistory);
}
#region INDIVIDUAL_SERVER_PERFORMANCE
@ -793,8 +780,6 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
.First();
ctx.Remove(ratingToRemove);
//Log.WriteDebug($"remove oldest rating {client.ClientId}");
await ctx.SaveChangesAsync();
}
// set the previous newest to false
@ -810,8 +795,6 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
ctx.Update(ratingToUnsetNewest);
ctx.Entry(ratingToUnsetNewest).Property(r => r.Newest).IsModified = true;
ratingToUnsetNewest.Newest = false;
//Log.WriteDebug($"unsetting previous newest flag {client.ClientId}");
await ctx.SaveChangesAsync();
}
}
@ -829,9 +812,6 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
// add new rating for current server
ctx.Add(newServerRating);
//Log.WriteDebug($"adding new server rating {client.ClientId}");
await ctx.SaveChangesAsync();
#endregion
#region OVERALL_RATING
// select all performance & time played for current client
@ -877,8 +857,6 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
.First();
ctx.Remove(ratingToRemove);
//Log.WriteDebug($"remove oldest overall rating {client.ClientId}");
await ctx.SaveChangesAsync();
}
// set the previous average newest to false
@ -894,8 +872,6 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
ctx.Update(ratingToUnsetNewest);
ctx.Entry(ratingToUnsetNewest).Property(r => r.Newest).IsModified = true;
ratingToUnsetNewest.Newest = false;
//Log.WriteDebug($"unsetting overall newest rating {client.ClientId}");
await ctx.SaveChangesAsync();
}
}
@ -913,7 +889,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
ctx.Add(averageRating);
#endregion
//Log.WriteDebug($"adding new average rating {client.ClientId}");
await ctx.SaveChangesAsync();
}
}
@ -1148,7 +1124,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
await statsSvc.ServerSvc.SaveChangesAsync();
statsSvc = null;
// this should prevent the gunk for having a long lasting context.
// this should prevent the gunk from having a long lasting context.
ContextThreads[serverId] = new ThreadSafeStatsService();
}

View File

@ -14,7 +14,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
{
get
{
return new GenericRepository<EFClientStatistics>();
return new GenericRepository<EFClientStatistics>(true);
}
}
public GenericRepository<EFServer> ServerSvc { get; private set; }
@ -30,11 +30,9 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
public ThreadSafeStatsService()
{
//ClientStatSvc = new GenericRepository<EFClientStatistics>();
ServerSvc = new GenericRepository<EFServer>();
KillStatsSvc = new GenericRepository<EFClientKill>();
ServerStatsSvc = new GenericRepository<EFServerStatistics>();
//MessageSvc = new GenericRepository<EFClientMessage>();
}
}
}

View File

@ -81,11 +81,15 @@ namespace IW4MAdmin.Plugins.Stats
break;
case GameEvent.EventType.Kill:
if (!E.Owner.CustomCallback)
{
await Manager.AddStandardKill(E.Origin, E.Target);
}
break;
case GameEvent.EventType.Damage:
if (!E.Owner.CustomCallback)
{
Manager.AddDamageEvent(E.Data, E.Origin.ClientId, E.Target.ClientId, E.Owner.GetHashCode());
}
break;
case GameEvent.EventType.ScriptDamage:
killInfo = (E.Data != null) ? E.Data.Split(';') : new string[0];