Skip to content

Commit

Permalink
1.2.8d
Browse files Browse the repository at this point in the history
- Minor changes
- Added the ability to change the map to a workshop map via the `css_map ws:id/name` command
- Fixed the `css_wsmap` command and retained it for backward compatibility
- Changed gags from userid to steamid
  • Loading branch information
daffyyyy committed Jan 27, 2024
1 parent 67ad185 commit e028bef
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 225 deletions.
99 changes: 65 additions & 34 deletions CS2-SimpleAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace CS2_SimpleAdmin;
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
{
public static IStringLocalizer? _localizer;
public static ConcurrentBag<ushort> gaggedPlayers = new ConcurrentBag<ushort>();
public static ConcurrentBag<string> gaggedPlayers = new ConcurrentBag<string>();
//public static ConcurrentBag<int> mutedPlayers = new ConcurrentBag<int>();
public static Dictionary<string, int> voteAnswers = new Dictionary<string, int>();
public static HashSet<ushort> godPlayers = new HashSet<ushort>();
Expand All @@ -36,7 +36,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
public override string ModuleName => "CS2-SimpleAdmin";
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
public override string ModuleAuthor => "daffyy";
public override string ModuleVersion => "1.2.8c";
public override string ModuleVersion => "1.2.8d";

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

Expand Down Expand Up @@ -508,10 +508,10 @@ public void OnGagCommand(CCSPlayerController? caller, CommandInfo command)
});

if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_mute {player!.UserId}");
NativeAPI.IssueServerCommand($"css_tag_mute {player!.SteamID.ToString()}");

if (player != null && player.UserId != null && !gaggedPlayers.Contains((ushort)player.UserId))
gaggedPlayers.Add((ushort)player.UserId);
if (player != null && player.SteamID.ToString() != "" && !gaggedPlayers.Contains(player.SteamID.ToString()))
gaggedPlayers.Add(player.SteamID.ToString());

if (time > 0 && time <= 30)
{
Expand All @@ -520,11 +520,11 @@ public void OnGagCommand(CCSPlayerController? caller, CommandInfo command)
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;

if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_unmute {player.UserId}");
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.SteamID.ToString()}");

if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId))
if (player != null && player.SteamID.ToString() != "" && gaggedPlayers.Contains(player.SteamID.ToString()))
{
if (gaggedPlayers.TryTake(out ushort removedItem) && removedItem != (ushort)player.UserId)
if (gaggedPlayers.TryTake(out string? removedItem) && removedItem != player.SteamID.ToString())
{
gaggedPlayers.Add(removedItem);
}
Expand Down Expand Up @@ -631,7 +631,7 @@ public void OnAddGagCommand(CCSPlayerController? caller, CommandInfo command)
}

if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_mute {player!.UserId}");
NativeAPI.IssueServerCommand($"css_tag_mute {player!.SteamID.ToString()}");

if (time > 0 && time <= 30)
{
Expand All @@ -640,11 +640,11 @@ public void OnAddGagCommand(CCSPlayerController? caller, CommandInfo command)
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;

if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_unmute {player.UserId}");
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.SteamID.ToString()}");

if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId))
if (player != null && player.SteamID.ToString() != "" && gaggedPlayers.Contains(player.SteamID.ToString()))
{
if (gaggedPlayers.TryTake(out ushort removedItem) && removedItem != (ushort)player.UserId)
if (gaggedPlayers.TryTake(out string? removedItem) && removedItem != player.SteamID.ToString())
{
gaggedPlayers.Add(removedItem);
}
Expand All @@ -654,8 +654,8 @@ public void OnAddGagCommand(CCSPlayerController? caller, CommandInfo command)
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}

if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId))
gaggedPlayers.Add((ushort)player.UserId);
if (player != null && player.SteamID.ToString() != "" && gaggedPlayers.Contains(player.SteamID.ToString()))
gaggedPlayers.Add(player.SteamID.ToString());
}
}
_ = _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 0);
Expand Down Expand Up @@ -686,16 +686,16 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)
CCSPlayerController? player = matches.FirstOrDefault();
if (player != null && player.IsValid)
{
if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId))
if (player != null && player.SteamID.ToString() != "" && gaggedPlayers.Contains(player.SteamID.ToString()))
{
if (gaggedPlayers.TryTake(out ushort removedItem) && removedItem != (ushort)player.UserId)
if (gaggedPlayers.TryTake(out string? removedItem) && removedItem != player.SteamID.ToString())
{
gaggedPlayers.Add(removedItem);
}
}

if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.UserId}");
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.SteamID.ToString()}");

found = true;
}
Expand All @@ -709,16 +709,16 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)
CCSPlayerController? player = matches.FirstOrDefault();
if (player != null && player.IsValid)
{
if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId))
if (player != null && player.SteamID.ToString() != "" && gaggedPlayers.Contains(player.SteamID.ToString()))
{
if (gaggedPlayers.TryTake(out ushort removedItem) && removedItem != (ushort)player.UserId)
if (gaggedPlayers.TryTake(out string? removedItem) && removedItem != player.SteamID.ToString())
{
gaggedPlayers.Add(removedItem);
}
}

if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.UserId}");
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.SteamID.ToString()}");

pattern = player!.AuthorizedSteamID!.SteamId64.ToString();

Expand Down Expand Up @@ -746,9 +746,9 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)
{
playersToTarget.ForEach(player =>
{
if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId))
if (player != null && player.SteamID.ToString() != "" && gaggedPlayers.Contains(player.SteamID.ToString()))
{
if (gaggedPlayers.TryTake(out ushort removedItem) && removedItem != (ushort)player.UserId)
if (gaggedPlayers.TryTake(out string? removedItem) && removedItem != player.SteamID.ToString())
{
gaggedPlayers.Add(removedItem);
}
Expand All @@ -758,7 +758,7 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)
_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 0); // Unmute by type 0 (gag)

if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.UserId}");
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.SteamID.ToString()}");
});

command.ReplyToCommand($"Ungaged player with pattern {pattern}.");
Expand Down Expand Up @@ -1697,12 +1697,32 @@ public void OnVoteCommand(CCSPlayerController? caller, CommandInfo command)
[CommandHelper(minArgs: 1, usage: "<mapname>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
public void OnMapCommand(CCSPlayerController? caller, CommandInfo command)
{
string map = command.GetArg(1);
string _command = string.Empty;
string? map = command.GetCommandString.Split(" ")[1];

if (!Server.IsMapValid(map))
if (map.StartsWith("ws:"))
{
command.ReplyToCommand($"Map {map} not found.");
return;
if (long.TryParse(map.Replace("ws:", ""), out long mapId))
{
_command = $"host_workshop_map {mapId}";
}
else
{
_command = $"ds_workshop_changelevel {map.Replace("ws:", "")}";
}

AddTimer(2.0f, () =>
{
Server.ExecuteCommand(_command);
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
else
{
if (!Server.IsMapValid(map))
{
command.ReplyToCommand($"Map {map} not found.");
return;
}
}

if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
Expand All @@ -1712,10 +1732,13 @@ public void OnMapCommand(CCSPlayerController? caller, CommandInfo command)
Server.PrintToChatAll(sb.ToString());
}

AddTimer(3.0f, () =>
if (!map.StartsWith("ws:"))
{
Server.ExecuteCommand($"changelevel {map}");
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
AddTimer(2.0f, () =>
{
Server.ExecuteCommand($"changelevel {map}");
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
}

[ConsoleCommand("css_changewsmap", "Change workshop map.")]
Expand All @@ -1725,18 +1748,26 @@ public void OnMapCommand(CCSPlayerController? caller, CommandInfo command)
[RequiresPermissions("@css/changemap")]
public void OnWorkshopMapCommand(CCSPlayerController? caller, CommandInfo command)
{
string? _command = null;
var map = command.GetArg(1);
string _command = string.Empty;
string? map = command.GetArg(1);

if (long.TryParse(map, out long mapId))
{
_command = $"host_workshop_map {mapId}";
}
else
{
_command = $"ds_workshop_changelevel {map}";
}

_command = int.TryParse(map, out var mapId) ? $"host_workshop_map {mapId}" : $"ds_workshop_changelevel {map}";
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map]);
Server.PrintToChatAll(sb.ToString());
}

AddTimer(3.0f, () =>
AddTimer(2.0f, () =>
{
Server.ExecuteCommand(_command);
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
Expand Down
Loading

0 comments on commit e028bef

Please sign in to comment.