Skip to content

Commit

Permalink
1.4.5a
Browse files Browse the repository at this point in the history
- Added `ReloadAdminsEveryMapChange` - Reloading sql admins on map start
- Ability to use any valid steamid instead of steamid64
- Fixed chat commands when gagged
- Votes now respect `UseChatMenu` config setting
  • Loading branch information
daffyyyy committed Jun 9, 2024
1 parent 962529e commit 00facaf
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 62 deletions.
2 changes: 1 addition & 1 deletion CS2-SimpleAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
public override string ModuleName => "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)");
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
public override string ModuleAuthor => "daffyy & Dliix66";
public override string ModuleVersion => "1.4.4b";
public override string ModuleVersion => "1.4.5a";

public CS2_SimpleAdminConfig Config { get; set; } = new();

Expand Down
2 changes: 1 addition & 1 deletion CS2-SimpleAdmin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.228" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.239" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="Discord.Net.Webhook" Version="3.14.1" />
<PackageReference Include="MySqlConnector" Version="2.3.7" />
Expand Down
5 changes: 3 additions & 2 deletions Commands/basebans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ public void OnAddBanCommand(CCSPlayerController? caller, CommandInfo command)
return;
if (string.IsNullOrEmpty(command.GetArg(1))) return;

var steamid = command.GetArg(1);

if (!Helper.IsValidSteamId64(steamid))
if (!Helper.ValidateSteamId(command.GetArg(1), out var steamId) || steamId == null)
{
command.ReplyToCommand($"Invalid SteamID64.");
return;
}

var steamid = steamId.SteamId64.ToString();

var reason = _localizer?["sa_unknown"] ?? "Unknown";

int.TryParse(command.GetArg(2), out var time);
Expand Down
27 changes: 14 additions & 13 deletions Commands/basecommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,16 @@ public void OnAdminHelpCommand(CCSPlayerController? caller, CommandInfo command)
public void OnAddAdminCommand(CCSPlayerController? caller, CommandInfo command)
{
if (_database == null) return;

if (!Helper.IsValidSteamId64(command.GetArg(1)))


if (!Helper.ValidateSteamId(command.GetArg(1), out var steamId) || steamId == null)
{
command.ReplyToCommand($"Invalid SteamID64.");
return;
}

var steamid = steamId.SteamId64.ToString();

if (command.GetArg(2).Length <= 0)
{
command.ReplyToCommand($"Invalid player name.");
Expand All @@ -114,7 +118,6 @@ public void OnAddAdminCommand(CCSPlayerController? caller, CommandInfo command)
return;
}

var steamid = command.GetArg(1);
var name = command.GetArg(2);
var flags = command.GetArg(3);
var globalAdmin = command.GetArg(4).ToLower().Equals("-g") || command.GetArg(5).ToLower().Equals("-g") ||
Expand Down Expand Up @@ -153,16 +156,15 @@ public void OnDelAdminCommand(CCSPlayerController? caller, CommandInfo command)
{
if (_database == null) return;

if (!Helper.IsValidSteamId64(command.GetArg(1)))
if (!Helper.ValidateSteamId(command.GetArg(1), out var steamId) || steamId == null)
{
command.ReplyToCommand($"Invalid SteamID64.");
return;
}

var steamid = command.GetArg(1);

var globalDelete = command.GetArg(2).ToLower().Equals("-g");

RemoveAdmin(caller, steamid, globalDelete, command);
RemoveAdmin(caller, steamId.SteamId64.ToString(), globalDelete, command);
}

public void RemoveAdmin(CCSPlayerController? caller, string steamid, bool globalDelete = false, CommandInfo? command = null)
Expand Down Expand Up @@ -534,21 +536,20 @@ public void OnKickCommand(CCSPlayerController? caller, CommandInfo command)

public void Kick(CCSPlayerController? caller, CCSPlayerController? player, string? reason = "Unknown", string? callerName = null, CommandInfo? command = null)
{
if (player == null || !player.IsValid) return;

callerName ??= caller == null ? "Console" : caller.PlayerName;
if (player != null && player.PawnIsAlive)
{
player.Pawn.Value!.Freeze();
}

reason ??= _localizer?["sa_unknown"] ?? "Unknown";

player.Pawn.Value!.Freeze();

if (command != null)
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
Helper.LogCommand(caller, $"css_kick {player?.PlayerName} {reason}");

if (string.IsNullOrEmpty(reason) == false)
{
if (player != null && !player.IsBot && !player.IsHLTV)
if (player != null && !player.IsBot)
using (new WithTemporaryCulture(player.GetLanguage()))
{
player.PrintToCenter(_localizer!["sa_player_kick_message", reason, caller == null ? "Console" : caller.PlayerName]);
Expand Down
50 changes: 25 additions & 25 deletions Commands/basecomms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ public void OnAddGagCommand(CCSPlayerController? caller, CommandInfo command)

if (string.IsNullOrEmpty(command.GetArg(1))) return;

var steamid = command.GetArg(1);

if (!Helper.IsValidSteamId64(steamid))
if (!Helper.ValidateSteamId(command.GetArg(1), out var steamId) || steamId == null)
{
command.ReplyToCommand($"Invalid SteamID64.");
return;
}

var steamid = steamId.SteamId64.ToString();

var reason = _localizer?["sa_unknown"] ?? "Unknown";

MuteManager muteManager = new(_database);
Expand Down Expand Up @@ -265,10 +265,10 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)

var pattern = command.GetArg(1);
MuteManager muteManager = new(_database);

if (Helper.IsValidSteamId64(pattern))
if (Helper.ValidateSteamId(pattern, out var steamId) && steamId != null)
{
var matches = Helper.GetPlayerFromSteamid64(pattern);
var matches = Helper.GetPlayerFromSteamid64(steamId.SteamId64.ToString());
if (matches.Count == 1)
{
var player = matches.FirstOrDefault();
Expand Down Expand Up @@ -474,16 +474,17 @@ public void OnAddMuteCommand(CCSPlayerController? caller, CommandInfo command)

if (command.ArgCount < 2)
return;

if (string.IsNullOrEmpty(command.GetArg(1))) return;

var steamid = command.GetArg(1);

if (!Helper.IsValidSteamId64(steamid))
if (!Helper.ValidateSteamId(command.GetArg(1), out var steamId) || steamId == null)
{
command.ReplyToCommand($"Invalid SteamID64.");
return;
}

var steamid = steamId.SteamId64.ToString();

var reason = _localizer?["sa_unknown"] ?? "Unknown";

MuteManager muteManager = new(_database);
Expand Down Expand Up @@ -595,9 +596,9 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command)
var found = false;
MuteManager muteManager = new(_database);

if (Helper.IsValidSteamId64(pattern))
if (Helper.ValidateSteamId(pattern, out var steamId) && steamId != null)
{
var matches = Helper.GetPlayerFromSteamid64(pattern);
var matches = Helper.GetPlayerFromSteamid64(steamId.SteamId64.ToString());
if (matches.Count == 1)
{
var player = matches.FirstOrDefault();
Expand Down Expand Up @@ -735,7 +736,7 @@ internal void Silence(CCSPlayerController? caller, CCSPlayerController? player,

if (time == 0)
{
if (!player.IsBot && !player.IsHLTV)
if (!player.IsBot)
{
using (new WithTemporaryCulture(player.GetLanguage()))
{
Expand Down Expand Up @@ -780,12 +781,11 @@ internal void Silence(CCSPlayerController? caller, CCSPlayerController? player,
}
}

if (command != null)
{
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Mute, DiscordWebhookClientPenalty, _localizer);
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
Helper.LogCommand(caller, command);
}
if (command == null) return;

Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Mute, DiscordWebhookClientPenalty, _localizer);
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
Helper.LogCommand(caller, command);
}

[ConsoleCommand("css_addsilence")]
Expand All @@ -800,14 +800,14 @@ public void OnAddSilenceCommand(CCSPlayerController? caller, CommandInfo command
return;
if (string.IsNullOrEmpty(command.GetArg(1))) return;

var steamid = command.GetArg(1);

if (!Helper.IsValidSteamId64(steamid))
if (!Helper.ValidateSteamId(command.GetArg(1), out var steamId) || steamId == null)
{
command.ReplyToCommand($"Invalid SteamID64.");
return;
}

var steamid = steamId.SteamId64.ToString();

var reason = _localizer?["sa_unknown"] ?? "Unknown";

MuteManager muteManager = new(_database);
Expand Down Expand Up @@ -843,7 +843,7 @@ public void OnAddSilenceCommand(CCSPlayerController? caller, CommandInfo command

if (time == 0)
{
if (!player.IsBot && !player.IsHLTV)
if (player is { IsBot: false, IsHLTV: false })
using (new WithTemporaryCulture(player.GetLanguage()))
{
player.PrintToCenter(_localizer!["sa_player_silence_message_perm", reason, caller == null ? "Console" : caller.PlayerName]);
Expand All @@ -863,7 +863,7 @@ public void OnAddSilenceCommand(CCSPlayerController? caller, CommandInfo command
}
else
{
if (!player.IsBot && !player.IsHLTV)
if (player is { IsBot: false, IsHLTV: false })
using (new WithTemporaryCulture(player.GetLanguage()))
{
player.PrintToCenter(_localizer!["sa_player_silence_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]);
Expand Down Expand Up @@ -921,9 +921,9 @@ public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command)
var found = false;
MuteManager muteManager = new(_database);

if (Helper.IsValidSteamId64(pattern))
if (Helper.ValidateSteamId(pattern, out var steamId) && steamId != null)
{
var matches = Helper.GetPlayerFromSteamid64(pattern);
var matches = Helper.GetPlayerFromSteamid64(steamId.SteamId64.ToString());
if (matches.Count == 1)
{
var player = matches.FirstOrDefault();
Expand Down
11 changes: 8 additions & 3 deletions Commands/basevotes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public void OnVoteCommand(CCSPlayerController? caller, CommandInfo command)
{
using (new WithTemporaryCulture(player.GetLanguage()))
{
ChatMenu voteMenu = new(_localizer!["sa_admin_vote_menu_title", question]);
BaseMenu voteMenu = Config.UseChatMenu
? new ChatMenu(_localizer!["sa_admin_vote_menu_title", question])
: new CenterHtmlMenu(_localizer!["sa_admin_vote_menu_title", question], Instance);
//ChatMenu voteMenu = new(_localizer!["sa_admin_vote_menu_title", question]);

for (var i = 2; i <= answersCount - 1; i++)
{
Expand All @@ -50,8 +53,10 @@ public void OnVoteCommand(CCSPlayerController? caller, CommandInfo command)
StringBuilder sb = new(_localizer["sa_prefix"]);
sb.Append(_localizer["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]);
player.PrintToChat(sb.ToString());

MenuManager.OpenChatMenu(player, voteMenu);

voteMenu.OpenToAll();

//MenuManager.OpenChatMenu(player, voteMenu);
}
}

Expand Down
7 changes: 5 additions & 2 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ public class CS2_SimpleAdminConfig : BasePluginConfig

[JsonPropertyName("EnableMetrics")]
public bool EnableMetrics { get; set; } = true;

[JsonPropertyName("ReloadAdminsEveryMapChange")]
public bool ReloadAdminsEveryMapChange { get; set; } = false;

[JsonPropertyName("UseChatMenu")]
public bool UseChatMenu { get; set; } = false;
Expand Down Expand Up @@ -160,10 +163,10 @@ public class CS2_SimpleAdminConfig : BasePluginConfig
public Discord Discord { get; set; } = new();

[JsonPropertyName("DefaultMaps")]
public List<string> DefaultMaps { get; set; } = [];
public List<string> DefaultMaps { get; set; } = new();

[JsonPropertyName("WorkshopMaps")]
public List<string> WorkshopMaps { get; set; } = [];
public List<string> WorkshopMaps { get; set; } = new();

[JsonPropertyName("CustomServerCommands")]
public List<CustomServerCommandData> CustomServerCommands { get; set; } = new();
Expand Down
17 changes: 13 additions & 4 deletions Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,11 @@ public HookResult OnRoundEnd(EventRoundStart @event, GameEventInfo info)

public HookResult OnCommandSay(CCSPlayerController? player, CommandInfo info)
{
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || info.GetArg(1).StartsWith($"/")
|| info.GetArg(1).StartsWith($"!") && info.GetArg(1).Length >= 12)
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV)
return HookResult.Continue;

if (info.GetArg(1).StartsWith($"/")
|| info.GetArg(1).StartsWith($"!"))
return HookResult.Continue;

if (info.GetArg(1).Length == 0)
Expand All @@ -220,8 +223,11 @@ public HookResult OnCommandSay(CCSPlayerController? player, CommandInfo info)

public HookResult OnCommandTeamSay(CCSPlayerController? player, CommandInfo info)
{
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || info.GetArg(1).StartsWith($"/")
|| info.GetArg(1).StartsWith($"!") && info.GetArg(1).Length >= 12)
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV )
return HookResult.Continue;

if (info.GetArg(1).StartsWith($"/")
|| info.GetArg(1).StartsWith($"!"))
return HookResult.Continue;

if (info.GetArg(1).Length == 0)
Expand Down Expand Up @@ -257,6 +263,9 @@ public HookResult OnCommandTeamSay(CCSPlayerController? player, CommandInfo info

public void OnMapStart(string mapName)
{
if (Config.ReloadAdminsEveryMapChange)
AddTimer(3.0f, () => ReloadAdmins(null));

var path = Path.GetDirectoryName(ModuleDirectory);
if (Directory.Exists(path + "/CS2-Tags"))
{
Expand Down
8 changes: 4 additions & 4 deletions Extensions/PlayerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public static void Print(this CCSPlayerController controller, string message = "

public static bool CanTarget(this CCSPlayerController? controller, CCSPlayerController? target)
{
if (target != null && target.IsBot) return true;
if (controller is null) return true;
if (controller is null || target is null) return true;
if (target.IsBot) return true;

return target != null && (AdminManager.CanPlayerTarget(controller, target) ||
return AdminManager.CanPlayerTarget(controller, target) ||
AdminManager.CanPlayerTarget(new SteamID(controller.SteamID),
new SteamID(target.SteamID)));
new SteamID(target.SteamID));
}

public static void SetSpeed(this CCSPlayerController? controller, float speed)
Expand Down
15 changes: 15 additions & 0 deletions Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ public static bool IsValidSteamId64(string input)
const string pattern = @"^\d{17}$";
return Regex.IsMatch(input, pattern);
}

public static bool ValidateSteamId(string input, out SteamID? steamId)
{
steamId = null;

if (string.IsNullOrEmpty(input))
{
return false;
}

if (!SteamID.TryParse(input, out var parsedSteamId)) return false;

steamId = parsedSteamId;
return true;
}

public static bool IsValidIp(string input)
{
Expand Down
Loading

0 comments on commit 00facaf

Please sign in to comment.