1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-07 21:58:06 -05:00

Utilise Minutes in TempBan for under 1 hour bans. (#362)

* Update tempban command to use minutes instead of hours

The duration calculation for tempbans now uses minutes rather than hours for greater precision. This change ensures better alignment with user expectations and configurations in smaller timeframes.

* Update regex patterns to enforce stricter input validation

Adjusted regex in `ParseTimespan` and `TempBanCommand` to ensure input starts with 1-5 numeric characters, improving validation. This prevents malformed user inputs and enhances overall command reliability.

* \w includes digits. Who knew.
This commit is contained in:
Amos 2025-05-12 01:13:41 +01:00 committed by GitHub
parent 081c522b96
commit 072e6da4d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 4 deletions

View File

@ -229,7 +229,7 @@ namespace SharedLibraryCore.Commands
/// </summary> /// </summary>
public class TempBanCommand : Command public class TempBanCommand : Command
{ {
private static readonly string TempBanRegex = @"([0-9]+\w+)\ (.+)"; private static readonly string TempBanRegex = @"^([0-9]{1,5}\p{L}+)\ (.+)";
private readonly ApplicationConfiguration _appConfig; private readonly ApplicationConfiguration _appConfig;
public TempBanCommand(ApplicationConfiguration appConfig, CommandConfiguration config, public TempBanCommand(ApplicationConfiguration appConfig, CommandConfiguration config,

View File

@ -510,7 +510,7 @@ namespace SharedLibraryCore
public static TimeSpan ParseTimespan(this string input) public static TimeSpan ParseTimespan(this string input)
{ {
var expressionMatch = Regex.Match(input, @"([0-9]+)(\w+)"); var expressionMatch = Regex.Match(input, @"^([0-9]{1,5})(\p{L}+)");
if (!expressionMatch.Success) // fallback to default tempban length of 1 hour if (!expressionMatch.Success) // fallback to default tempban length of 1 hour
{ {

View File

@ -312,8 +312,8 @@ namespace WebfrontCore.Controllers
else else
{ {
var durationSpan = _appConfig.BanDurations[duration - 1]; var durationSpan = _appConfig.BanDurations[duration - 1];
var durationValue = durationSpan.TotalHours.ToString(CultureInfo.InvariantCulture) + var durationValue = durationSpan.TotalMinutes.ToString(CultureInfo.InvariantCulture) +
Localization["GLOBAL_TIME_HOURS"][0]; Localization["GLOBAL_TIME_MINUTES"][0];
command = command =
$"{_appConfig.CommandPrefix}{_tempbanCommandName} @{targetId} {durationValue} {fallthroughReason}"; $"{_appConfig.CommandPrefix}{_tempbanCommandName} @{targetId} {durationValue} {fallthroughReason}";
} }