mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-11 07:40:54 -05:00
fixed issue with not escaping regex for validating commands
This commit is contained in:
@ -173,8 +173,8 @@ namespace StatsPlugin.Cheat
|
||||
double marginOfError = Thresholds.GetMarginOfError(chestKills);
|
||||
double lerpAmount = Math.Min(1.0, (chestKills - Thresholds.LowSampleMinKills) / (double)(Thresholds.HighSampleMinKills - Thresholds.LowSampleMinKills));
|
||||
// determine max acceptable ratio of chest to abdomen kills
|
||||
double chestAbdomenRatioLerpValueForFlag = Thresholds.Lerp(Thresholds.ChestAbdomenRatioThresholdLowSample(2.25), Thresholds.ChestAbdomenRatioThresholdHighSample(2.25), lerpAmount) + marginOfError;
|
||||
double chestAbdomenLerpValueForBan = Thresholds.Lerp(Thresholds.ChestAbdomenRatioThresholdLowSample(3.25), Thresholds.ChestAbdomenRatioThresholdHighSample(3.25), lerpAmount) + marginOfError;
|
||||
double chestAbdomenRatioLerpValueForFlag = Thresholds.Lerp(Thresholds.ChestAbdomenRatioThresholdLowSample(3), Thresholds.ChestAbdomenRatioThresholdHighSample(3), lerpAmount) + marginOfError;
|
||||
double chestAbdomenLerpValueForBan = Thresholds.Lerp(Thresholds.ChestAbdomenRatioThresholdLowSample(4), Thresholds.ChestAbdomenRatioThresholdHighSample(4), lerpAmount) + marginOfError;
|
||||
|
||||
double currentChestAbdomenRatio = HitLocationCount[IW4Info.HitLocation.torso_upper] / (double)HitLocationCount[IW4Info.HitLocation.torso_lower];
|
||||
|
||||
@ -198,7 +198,7 @@ namespace StatsPlugin.Cheat
|
||||
{
|
||||
ClientPenalty = Penalty.PenaltyType.Ban,
|
||||
RatioAmount = currentChestAbdomenRatio,
|
||||
Bone = IW4Info.HitLocation.torso_upper,
|
||||
Bone = 0,
|
||||
KillCount = chestKills
|
||||
};
|
||||
}
|
||||
@ -219,7 +219,7 @@ namespace StatsPlugin.Cheat
|
||||
{
|
||||
ClientPenalty = Penalty.PenaltyType.Flag,
|
||||
RatioAmount = currentChestAbdomenRatio,
|
||||
Bone = IW4Info.HitLocation.torso_upper,
|
||||
Bone = 0,
|
||||
KillCount = chestKills
|
||||
};
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace StatsPlugin.Cheat
|
||||
public const int HighSampleMinKills = 100;
|
||||
public const double KillTimeThreshold = 0.2;
|
||||
|
||||
public static double GetMarginOfError(int numKills) => 0.98 / Math.Sqrt(numKills);
|
||||
public static double GetMarginOfError(int numKills) => 1.6455 / Math.Sqrt(numKills);
|
||||
|
||||
public static double Lerp(double v1, double v2, double amount)
|
||||
{
|
||||
|
61
Plugins/SimpleStats/Config/StatsConfiguration.cs
Normal file
61
Plugins/SimpleStats/Config/StatsConfiguration.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using SharedLibrary.Configuration;
|
||||
using SharedLibrary.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StatsPlugin.Config
|
||||
{
|
||||
class StatsConfiguration : IBaseConfiguration
|
||||
{
|
||||
public bool EnableAntiCheat { get; set; }
|
||||
public List<StreakMessageConfiguration> KillstreakMessages { get; set; }
|
||||
public List<StreakMessageConfiguration> DeathstreakMessages { get; set; }
|
||||
public string Name() => "Stats";
|
||||
public IBaseConfiguration Generate()
|
||||
{
|
||||
var config = new StatsConfiguration();
|
||||
|
||||
Console.Write("Enable server-side anti-cheat? [y/n]: ");
|
||||
config.EnableAntiCheat = (Console.ReadLine().ToLower().FirstOrDefault() as char?) == 'y';
|
||||
|
||||
config.KillstreakMessages = new List<StreakMessageConfiguration>()
|
||||
{
|
||||
new StreakMessageConfiguration(){
|
||||
Count = -1,
|
||||
Message = "Try not to kill yourself anymore"
|
||||
},
|
||||
new StreakMessageConfiguration() {
|
||||
Count = 5,
|
||||
Message = "Great job! You're on a ^55 killstreak!"
|
||||
},
|
||||
new StreakMessageConfiguration()
|
||||
{
|
||||
Count = 10,
|
||||
Message = "Amazing! ^510 kills ^7without dying!"
|
||||
},
|
||||
new StreakMessageConfiguration(){
|
||||
Count = 25,
|
||||
Message = "You better call in that nuke, ^525 killstreak^7!"
|
||||
}
|
||||
};
|
||||
|
||||
config.DeathstreakMessages = new List<StreakMessageConfiguration>()
|
||||
{
|
||||
new StreakMessageConfiguration()
|
||||
{
|
||||
Count = 5,
|
||||
Message = "Pick it up soldier, you've died ^55 times ^7in a row..."
|
||||
},
|
||||
new StreakMessageConfiguration(){
|
||||
Count = 10,
|
||||
Message = "Seriously? ^510 deaths ^7without getting a kill?"
|
||||
},
|
||||
};
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
14
Plugins/SimpleStats/Config/StreakMessageConfiguration.cs
Normal file
14
Plugins/SimpleStats/Config/StreakMessageConfiguration.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StatsPlugin.Config
|
||||
{
|
||||
public class StreakMessageConfiguration
|
||||
{
|
||||
public int Count { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
}
|
@ -10,6 +10,8 @@ using SharedLibrary.Objects;
|
||||
using SharedLibrary.Services;
|
||||
using StatsPlugin.Models;
|
||||
using SharedLibrary.Commands;
|
||||
using SharedLibrary.Configuration;
|
||||
using StatsPlugin.Config;
|
||||
|
||||
namespace StatsPlugin.Helpers
|
||||
{
|
||||
@ -17,7 +19,6 @@ namespace StatsPlugin.Helpers
|
||||
{
|
||||
private ConcurrentDictionary<int, ServerStats> Servers;
|
||||
private ConcurrentDictionary<int, ThreadSafeStatsService> ContextThreads;
|
||||
private ConcurrentDictionary<int, StreakMessage> StreakMessages;
|
||||
private ILogger Log;
|
||||
private IManager Manager;
|
||||
|
||||
@ -25,7 +26,6 @@ namespace StatsPlugin.Helpers
|
||||
{
|
||||
Servers = new ConcurrentDictionary<int, ServerStats>();
|
||||
ContextThreads = new ConcurrentDictionary<int, ThreadSafeStatsService>();
|
||||
StreakMessages = new ConcurrentDictionary<int, StreakMessage>();
|
||||
Log = mgr.GetLogger();
|
||||
Manager = mgr;
|
||||
}
|
||||
@ -48,7 +48,6 @@ namespace StatsPlugin.Helpers
|
||||
int serverId = sv.GetHashCode();
|
||||
var statsSvc = new ThreadSafeStatsService();
|
||||
ContextThreads.TryAdd(serverId, statsSvc);
|
||||
StreakMessages.TryAdd(serverId, new StreakMessage(sv));
|
||||
|
||||
// get the server from the database if it exists, otherwise create and insert a new one
|
||||
var server = statsSvc.ServerSvc.Find(c => c.ServerId == serverId).FirstOrDefault();
|
||||
@ -247,7 +246,7 @@ namespace StatsPlugin.Helpers
|
||||
|
||||
//statsSvc.KillStatsSvc.Insert(kill);
|
||||
//await statsSvc.KillStatsSvc.SaveChangesAsync();
|
||||
if(Manager.GetApplicationSettings().EnableAntiCheat)
|
||||
if(Plugin.Config.Configuration().EnableAntiCheat)
|
||||
{
|
||||
async Task executePenalty(Cheat.DetectionPenaltyResult penalty)
|
||||
{
|
||||
@ -313,10 +312,9 @@ namespace StatsPlugin.Helpers
|
||||
CalculateKill(attackerStats, victimStats);
|
||||
|
||||
// show encouragement/discouragement
|
||||
var streakMessageGen = StreakMessages[serverId];
|
||||
string streakMessage = (attackerStats.ClientId != victimStats.ClientId) ?
|
||||
streakMessageGen.MessageOnStreak(attackerStats.KillStreak, attackerStats.DeathStreak) :
|
||||
streakMessageGen.MessageOnStreak(-1, -1);
|
||||
StreakMessage.MessageOnStreak(attackerStats.KillStreak, attackerStats.DeathStreak) :
|
||||
StreakMessage.MessageOnStreak(-1, -1);
|
||||
|
||||
if (streakMessage != string.Empty)
|
||||
await attacker.Tell(streakMessage);
|
||||
|
@ -10,55 +10,20 @@ namespace StatsPlugin.Helpers
|
||||
{
|
||||
public class StreakMessage
|
||||
{
|
||||
private ConfigurationManager config;
|
||||
|
||||
public StreakMessage(Server sv)
|
||||
{
|
||||
config = new ConfigurationManager(sv);
|
||||
|
||||
// initialize default messages
|
||||
if (config.GetProperty<Dictionary<int, string>>("KillstreakMessages") == null)
|
||||
{
|
||||
var killstreakMessages = new Dictionary<int, string>()
|
||||
{
|
||||
{ -1, "Try not to kill yourself anymore" },
|
||||
{ 5, "Great job! You're on a ^55 killstreak!" },
|
||||
{ 10, "Amazing! ^510 kills ^7without dying!" },
|
||||
{ 25, "You better call in that nuke, ^525 killstreak^7!" }
|
||||
};
|
||||
config.AddProperty(new KeyValuePair<string, object>("KillstreakMessages", killstreakMessages));
|
||||
}
|
||||
|
||||
if (config.GetProperty<Dictionary<int, string>>("DeathstreakMessages") == null)
|
||||
{
|
||||
var deathstreakMessages = new Dictionary<int, string>()
|
||||
{
|
||||
{ 5, "Pick it up soldier, you've died ^55 times ^7in a row..." },
|
||||
{ 10, "Seriously? ^510 deaths ^7without getting a kill?" },
|
||||
};
|
||||
config.AddProperty(new KeyValuePair<string, object>("DeathstreakMessages", deathstreakMessages));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a message from the configuration encouraging or discouraging clients
|
||||
/// </summary>
|
||||
/// <param name="killStreak">how many kills the client has without dying</param>
|
||||
/// <param name="deathStreak">how many deaths the client has without getting a kill</param>
|
||||
/// <returns>message to send to the client</returns>
|
||||
public string MessageOnStreak(int killStreak, int deathStreak)
|
||||
public static string MessageOnStreak(int killStreak, int deathStreak)
|
||||
{
|
||||
var killstreakMessage = config.GetProperty<Dictionary<int, string>>("KillstreakMessages");
|
||||
var deathstreakMessage = config.GetProperty<Dictionary<int, string>>("DeathstreakMessages");
|
||||
var killstreakMessage = Plugin.Config.Configuration().KillstreakMessages;
|
||||
var deathstreakMessage = Plugin.Config.Configuration().DeathstreakMessages;
|
||||
|
||||
string message = "";
|
||||
|
||||
if (killstreakMessage.ContainsKey(killStreak))
|
||||
message =killstreakMessage[killStreak];
|
||||
else if (deathstreakMessage.ContainsKey(deathStreak))
|
||||
message = deathstreakMessage[deathStreak];
|
||||
|
||||
return message;
|
||||
string message = killstreakMessage.FirstOrDefault(m => m.Count == killStreak)?.Message;
|
||||
message = (message == null) ? deathstreakMessage.FirstOrDefault(m => m.Count == deathStreak)?.Message : message;
|
||||
return message ?? "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,12 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using SharedLibrary;
|
||||
using SharedLibrary.Configuration;
|
||||
using SharedLibrary.Dtos;
|
||||
using SharedLibrary.Helpers;
|
||||
using SharedLibrary.Interfaces;
|
||||
using SharedLibrary.Services;
|
||||
using StatsPlugin.Config;
|
||||
using StatsPlugin.Helpers;
|
||||
using StatsPlugin.Models;
|
||||
|
||||
@ -24,6 +26,7 @@ namespace StatsPlugin
|
||||
|
||||
public static StatManager Manager { get; private set; }
|
||||
private IManager ServerManager;
|
||||
public static BaseConfigurationHandler<StatsConfiguration> Config { get; private set; }
|
||||
|
||||
public async Task OnEventAsync(Event E, Server S)
|
||||
{
|
||||
@ -80,8 +83,16 @@ namespace StatsPlugin
|
||||
}
|
||||
}
|
||||
|
||||
public Task OnLoadAsync(IManager manager)
|
||||
public async Task OnLoadAsync(IManager manager)
|
||||
{
|
||||
// load custom configuration
|
||||
Config = new BaseConfigurationHandler<StatsConfiguration>("StatsPluginSettings");
|
||||
if (Config.Configuration()== null)
|
||||
{
|
||||
Config.Set((StatsConfiguration)new StatsConfiguration().Generate());
|
||||
await Config.Save();
|
||||
}
|
||||
|
||||
// meta data info
|
||||
async Task<List<ProfileMeta>> getStats(int clientId)
|
||||
{
|
||||
@ -203,9 +214,7 @@ namespace StatsPlugin
|
||||
|
||||
ServerManager = manager;
|
||||
|
||||
return Task.FromResult(
|
||||
Manager = new StatManager(manager)
|
||||
);
|
||||
Manager = new StatManager(manager);
|
||||
}
|
||||
|
||||
public async Task OnTickAsync(Server S)
|
||||
|
@ -124,6 +124,8 @@
|
||||
<Compile Include="Commands\ResetStats.cs" />
|
||||
<Compile Include="Commands\TopStats.cs" />
|
||||
<Compile Include="Commands\ViewStats.cs" />
|
||||
<Compile Include="Config\StreakMessageConfiguration.cs" />
|
||||
<Compile Include="Config\StatsConfiguration.cs" />
|
||||
<Compile Include="Helpers\ServerStats.cs" />
|
||||
<Compile Include="Helpers\StatManager.cs" />
|
||||
<Compile Include="Helpers\StreakMessage.cs" />
|
||||
@ -150,11 +152,6 @@
|
||||
<Name>SharedLibrary</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions">
|
||||
<Version>1.1.2</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)BUILD\plugins\"</PostBuildEvent>
|
||||
|
Reference in New Issue
Block a user