- 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
This commit is contained in:
Dawid Bepierszcz
2024-01-27 23:56:13 +01:00
parent 67ad1851bf
commit e028bef5b0
3 changed files with 88 additions and 225 deletions

View File

@@ -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>();
@@ -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();
@@ -508,10 +508,10 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
});
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)
{
@@ -520,11 +520,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
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);
}
@@ -631,7 +631,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
}
if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_mute {player!.UserId}");
NativeAPI.IssueServerCommand($"css_tag_mute {player!.SteamID.ToString()}");
if (time > 0 && time <= 30)
{
@@ -640,11 +640,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
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);
}
@@ -654,8 +654,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
}, 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);
@@ -686,16 +686,16 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
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;
}
@@ -709,16 +709,16 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
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();
@@ -746,9 +746,9 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{
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);
}
@@ -758,7 +758,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
_ = _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}.");
@@ -1697,12 +1697,32 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
[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))
@@ -1712,10 +1732,13 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
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.")]
@@ -1725,10 +1748,18 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
[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"]);
@@ -1736,7 +1767,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
Server.PrintToChatAll(sb.ToString());
}
AddTimer(3.0f, () =>
AddTimer(2.0f, () =>
{
Server.ExecuteCommand(_command);
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);

208
Events.cs
View File

@@ -3,7 +3,6 @@ using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Entities;
using Dapper;
using MySqlConnector;
using System.Text;
@@ -64,7 +63,7 @@ public partial class CS2_SimpleAdmin
{
if (player == null || !player.IsValid || info.GetArg(1).Length == 0) return HookResult.Continue;
if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId))
if (player != null && player.SteamID.ToString() != "" && gaggedPlayers.Contains(player.SteamID.ToString()))
{
return HookResult.Handled;
}
@@ -76,7 +75,7 @@ public partial class CS2_SimpleAdmin
{
if (player == null || !player.IsValid || info.GetArg(1).Length == 0) return HookResult.Continue;
if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId))
if (player != null && player.SteamID.ToString() != "" && gaggedPlayers.Contains(player.SteamID.ToString()))
{
return HookResult.Handled;
}
@@ -133,6 +132,8 @@ public partial class CS2_SimpleAdmin
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV)
return;
Console.WriteLine("test");
string? ipAddress = !string.IsNullOrEmpty(player.IpAddress) ? player.IpAddress.Split(":")[0] : null;
if (
@@ -150,7 +151,7 @@ public partial class CS2_SimpleAdmin
IpAddress = ipAddress
};
Task.Run(async () =>
_ = Task.Run(async () =>
{
BanManager _banManager = new(dbConnectionString, Config);
bool isBanned = await _banManager.IsPlayerBanned(playerInfo);
@@ -188,11 +189,11 @@ public partial class CS2_SimpleAdmin
if (muteType == "GAG")
{
// Chat mute
if (player.UserId != null && !gaggedPlayers.Any(index => index == (ushort)player.UserId))
gaggedPlayers.Add((ushort)player.UserId);
if (player.SteamID.ToString() != "" && !gaggedPlayers.Any(steamid => steamid.Equals(player.SteamID.ToString())))
gaggedPlayers.Add(player.SteamID.ToString());
if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_mute {player.UserId}");
NativeAPI.IssueServerCommand($"css_tag_mute {player!.SteamID.ToString()}");
if (durationInSeconds != 0 && duration.Minutes >= 0 && duration.Minutes <= 30)
{
@@ -200,16 +201,16 @@ public partial class CS2_SimpleAdmin
{
if (player == null || !player.IsValid || player.SteamID.ToString() == "") return;
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()}");
MuteManager _muteManager = new(dbConnectionString);
_ = _muteManager.UnmutePlayer(player!.SteamID.ToString(), 0);
@@ -230,7 +231,7 @@ public partial class CS2_SimpleAdmin
}
*/
}
else
else if (muteType == "MUTE")
{
// Voice mute
player.VoiceFlags = VoiceFlags.Muted;
@@ -334,187 +335,15 @@ public partial class CS2_SimpleAdmin
*/
}
private void OnClientAuthorized(int playerSlot, SteamID steamID)
{
return;
#pragma warning disable CS0162
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
#pragma warning restore CS0162
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV)
return;
if (
player.IpAddress != null && bannedPlayers.Contains(player.IpAddress) ||
player.AuthorizedSteamID != null && bannedPlayers.Contains(player.AuthorizedSteamID.SteamId64.ToString())
)
Helper.KickPlayer((ushort)player.UserId!, "Banned");
PlayerInfo playerInfo = new PlayerInfo
{
UserId = player.UserId,
Index = (ushort)player.Index,
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
Name = player?.PlayerName,
IpAddress = player?.IpAddress?.Split(":")[0]
};
Task.Run(async () =>
{
BanManager _banManager = new(dbConnectionString, Config);
bool isBanned = await _banManager.IsPlayerBanned(playerInfo);
MuteManager _muteManager = new(dbConnectionString);
List<dynamic> activeMutes = await _muteManager.IsPlayerMuted(playerInfo.SteamId!);
AdminSQLManager _adminManager = new(dbConnectionString);
List<(List<string>, int)> activeFlags = await _adminManager.GetAdminFlags(playerInfo.SteamId!);
Server.NextFrame(() =>
{
if (player == null || !player.IsValid) return;
if (isBanned)
{
if (player.IpAddress != null && !bannedPlayers.Contains(player.IpAddress))
bannedPlayers.Add(player.IpAddress);
if (player.AuthorizedSteamID != null && !bannedPlayers.Contains(player.AuthorizedSteamID.SteamId64.ToString()))
bannedPlayers.Add(player.AuthorizedSteamID.SteamId64.ToString());
Helper.KickPlayer((ushort)player.UserId!, "Banned");
return;
}
//Helper.GivePlayerFlags(player, activeFlags);
if (activeMutes.Count > 0)
{
foreach (var mute in activeMutes)
{
string muteType = mute.type;
TimeSpan duration = mute.ends - mute.created;
int durationInSeconds = (int)duration.TotalSeconds;
if (muteType == "GAG")
{
// Chat mute
if (player.UserId != null && !gaggedPlayers.Any(index => index == (ushort)player.UserId))
gaggedPlayers.Add((ushort)player.UserId);
if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_mute {player.UserId}");
if (durationInSeconds != 0 && duration.Minutes >= 0 && duration.Minutes <= 30)
{
AddTimer(durationInSeconds, () =>
{
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId))
{
if (gaggedPlayers.TryTake(out ushort removedItem) && removedItem != (int)player.UserId)
{
gaggedPlayers.Add(removedItem);
}
}
if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.UserId}");
MuteManager _muteManager = new(dbConnectionString);
_ = _muteManager.UnmutePlayer(player!.AuthorizedSteamID.SteamId64.ToString(), 0);
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
/*
CCSPlayerController currentPlayer = player;
if (mute.duration == 0 || durationInSeconds >= 1800) continue;
await Task.Delay(TimeSpan.FromSeconds(durationInSeconds));
if (currentPlayer != null && currentPlayer.IsValid)
{
NativeAPI.IssueServerCommand($"css_tag_unmute {currentPlayer.Index.ToString()}");
await UnmutePlayer(currentPlayer.AuthorizedSteamID.SteamId64.ToString(), 0);
}
*/
}
else
{
// Voice mute
player.VoiceFlags = VoiceFlags.Muted;
if (durationInSeconds != 0 && duration.Minutes >= 0 && duration.Minutes <= 30)
{
AddTimer(durationInSeconds, () =>
{
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
/*
if (mutedPlayers.Contains((ushort)player.UserId))
{
if (mutedPlayers.TryTake(out int removedItem) && removedItem != (ushort)player.UserId)
{
mutedPlayers.Add(removedItem);
}
}
*/
player.VoiceFlags = VoiceFlags.Normal;
//MuteManager _muteManager = new(dbConnectionString);
//_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 1);
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
}
}
}
/*
if (_adminManager._adminCache != null && _adminManager._adminCache.Count > 0)
{
foreach (var flags in activeFlags)
{
if (flags == null) continue;
string flagsValue = flags.flags.ToString();
if (!string.IsNullOrEmpty(flagsValue))
{
string[] _flags = flagsValue.Split(",");
AddTimer(10, () =>
{
if (player == null) return;
foreach (var _flag in _flags)
{
if (_flag.StartsWith("@"))
{
AdminManager.AddPlayerPermissions(player, _flag);
}
if (_flag.StartsWith("3"))
{
AdminManager.AddPlayerToGroup(player, _flag);
}
}
});
}
}
}
*/
});
});
}
private void OnClientDisconnect(int playerSlot)
{
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
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);
}
@@ -550,11 +379,13 @@ public partial class CS2_SimpleAdmin
}
if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.UserId}");
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.SteamID.ToString()}");
}
private void OnMapStart(string mapName)
{
gaggedPlayers.Clear();
AdminSQLManager _adminManager = new(dbConnectionString);
AddTimer(60.0f, bannedPlayers.Clear, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT | CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
@@ -573,7 +404,7 @@ public partial class CS2_SimpleAdmin
TagsDetected = true;
}
AddTimer(1.0f, () =>
AddTimer(2.0f, () =>
{
using (var connection = new MySqlConnection(dbConnectionString))
{
@@ -591,10 +422,11 @@ public partial class CS2_SimpleAdmin
ServerId = serverId;
connection.Close();
_ = _adminManager.GiveAllFlags();
}
});
_ = _adminManager.GiveAllFlags();
}
private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info)

View File

@@ -174,11 +174,11 @@ namespace CS2_SimpleAdmin
if (muteType == "GAG")
{
if (!CS2_SimpleAdmin.gaggedPlayers.Any(index => index == player.UserId))
CS2_SimpleAdmin.gaggedPlayers.Add((ushort)player.UserId);
if (!CS2_SimpleAdmin.gaggedPlayers.Any(steamid => steamid == player.SteamId!.ToString()))
CS2_SimpleAdmin.gaggedPlayers.Add(player.SteamId!.ToString());
if (CS2_SimpleAdmin.TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_mute {player!.UserId}");
NativeAPI.IssueServerCommand($"css_tag_mute {player!.SteamId!.ToString()}");
/*
CCSPlayerController currentPlayer = player;