-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
171 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using CounterStrikeSharp.API.Modules.Utils; | ||
|
||
namespace Jailbreak.Public.Utils; | ||
|
||
public static class TeamUtil { | ||
public static CsTeam? FromString(string team) { | ||
return team.ToLower() switch { | ||
"0" or "n" or "none" => CsTeam.None, | ||
"1" or "s" or "spec" or "spectator" or "spectators" or "specs" => CsTeam | ||
.Spectator, | ||
"2" or "t" or "ts" or "terror" or "terrorist" or "terrorists" | ||
or "prisoner" or "prisoners" => CsTeam.Terrorist, | ||
"3" or "ct" or "cts" or "counter" or "counterterrorist" | ||
or "counterterrorists" or "guard" | ||
or "guards" => CsTeam.CounterTerrorist, | ||
_ => null | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using CounterStrikeSharp.API.Modules.Cvars.Validators; | ||
|
||
namespace Jailbreak.Validator; | ||
|
||
public class ItemValidator( | ||
ItemValidator.WeaponType type = ItemValidator.WeaponType.WEAPON | ||
| ItemValidator.WeaponType.UTILITY, bool allowEmpty = true, | ||
bool allowMultiple = false) : IValidator<string> { | ||
[Flags] | ||
public enum WeaponType { | ||
GRENADE, | ||
UTILITY, | ||
WEAPON, | ||
SNIPERS, | ||
RIFLES, | ||
PISTOLS, | ||
SHOTGUNS, | ||
SMGS, | ||
HEAVY | ||
} | ||
|
||
public bool Validate(string value, out string? errorMessage) { | ||
if (value.Contains(',') && !allowMultiple) { | ||
errorMessage = "Value cannot contain multiple values"; | ||
return false; | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(value)) { | ||
errorMessage = allowEmpty ? null : "weapon cannot be empty"; | ||
return allowEmpty; | ||
} | ||
|
||
foreach (var weapon in value.Split(',')) { | ||
if (string.IsNullOrWhiteSpace(weapon)) { | ||
if (!allowEmpty) { | ||
errorMessage = allowEmpty ? null : "weapon cannot be empty"; | ||
return allowEmpty; | ||
} | ||
|
||
continue; | ||
} | ||
|
||
errorMessage = $"invalid {nameof(type).ToLower()}: {weapon}"; | ||
return Enum.GetValues<WeaponType>() | ||
.Where(t => (t & type) == type) | ||
.Any(t => validateType(t, weapon)); | ||
} | ||
|
||
errorMessage = null; | ||
return true; | ||
} | ||
|
||
private bool validateType(WeaponType current, string weapon) { | ||
var result = current switch { | ||
WeaponType.GRENADE => Tag.GRENADES.Contains(weapon), | ||
WeaponType.UTILITY => Tag.UTILITY.Contains(weapon), | ||
WeaponType.WEAPON => Tag.WEAPONS.Contains(weapon), | ||
WeaponType.SNIPERS => Tag.SNIPERS.Contains(weapon), | ||
WeaponType.RIFLES => Tag.RIFLES.Contains(weapon), | ||
WeaponType.PISTOLS => Tag.PISTOLS.Contains(weapon), | ||
WeaponType.SHOTGUNS => Tag.SHOTGUNS.Contains(weapon), | ||
WeaponType.SMGS => Tag.SMGS.Contains(weapon), | ||
WeaponType.HEAVY => Tag.HEAVY.Contains(weapon), | ||
_ => throw new ArgumentOutOfRangeException(nameof(weapon)) | ||
}; | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using CounterStrikeSharp.API.Modules.Cvars.Validators; | ||
using CounterStrikeSharp.API.Modules.Utils; | ||
using Jailbreak.Public.Utils; | ||
|
||
namespace Jailbreak.Validator; | ||
|
||
public class TeamValidator(bool allowSpecs = true) : IValidator<string> { | ||
public bool Validate(string value, out string? errorMessage) { | ||
errorMessage = null; | ||
|
||
var team = TeamUtil.FromString(value); | ||
|
||
if (team == null) { | ||
errorMessage = $"Unknown team: \"{value}\""; | ||
return false; | ||
} | ||
|
||
if (team is CsTeam.None or CsTeam.Spectator && !allowSpecs) { | ||
errorMessage = "Team must be CT or T"; | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.