AntiDLL Module Fix

Fixed banning when detecting a forbidden event
This commit is contained in:
Dawid Bepierszcz
2025-02-20 01:28:28 +01:00
parent 62b1987fde
commit 5d62c743dd
5 changed files with 45 additions and 35 deletions

View File

@@ -491,7 +491,7 @@ internal static class Helper
public static void SendDiscordPenaltyMessage(CCSPlayerController? caller, CCSPlayerController? target, string reason, int duration, PenaltyType penalty, IStringLocalizer? localizer) public static void SendDiscordPenaltyMessage(CCSPlayerController? caller, CCSPlayerController? target, string reason, int duration, PenaltyType penalty, IStringLocalizer? localizer)
{ {
if (localizer == null) return; if (localizer == null) return;
var penaltySetting = penalty switch var penaltySetting = penalty switch
{ {
PenaltyType.Ban => CS2_SimpleAdmin.Instance.Config.Discord.DiscordPenaltyBanSettings, PenaltyType.Ban => CS2_SimpleAdmin.Instance.Config.Discord.DiscordPenaltyBanSettings,
@@ -505,7 +505,7 @@ internal static class Helper
var webhookUrl = penaltySetting.FirstOrDefault(s => s.Name.Equals("Webhook"))?.Value; var webhookUrl = penaltySetting.FirstOrDefault(s => s.Name.Equals("Webhook"))?.Value;
if (string.IsNullOrEmpty(webhookUrl)) return; if (string.IsNullOrEmpty(webhookUrl)) return;
const string defaultCommunityUrl = "<https://steamcommunity.com/profiles/0>"; const string defaultCommunityUrl = "<https://steamcommunity.com/profiles/0>";
var callerCommunityUrl = caller != null ? $"<{new SteamID(caller.SteamID).ToCommunityUrl()}>" : defaultCommunityUrl; var callerCommunityUrl = caller != null ? $"<{new SteamID(caller.SteamID).ToCommunityUrl()}>" : defaultCommunityUrl;
var targetCommunityUrl = target != null ? $"<{new SteamID(target.SteamID).ToCommunityUrl()}>" : defaultCommunityUrl; var targetCommunityUrl = target != null ? $"<{new SteamID(target.SteamID).ToCommunityUrl()}>" : defaultCommunityUrl;
@@ -585,10 +585,10 @@ internal static class Helper
}); });
} }
public static void SendDiscordPenaltyMessage(CCSPlayerController? caller, string steamId, string reason, int duration, PenaltyType penalty, IStringLocalizer? localizer) public static void SendDiscordPenaltyMessage(CCSPlayerController? caller, string steamId, string reason, int duration, PenaltyType penalty, IStringLocalizer? localizer)
{ {
if (localizer == null) return; if (localizer == null) return;
var penaltySetting = penalty switch var penaltySetting = penalty switch
{ {
PenaltyType.Ban => CS2_SimpleAdmin.Instance.Config.Discord.DiscordPenaltyBanSettings, PenaltyType.Ban => CS2_SimpleAdmin.Instance.Config.Discord.DiscordPenaltyBanSettings,

View File

@@ -1,7 +1,7 @@
using CounterStrikeSharp.API.ValveConstants.Protobuf; namespace AntiDLL_CS2_SimpleAdmin;
namespace AntiDLL_CS2_SimpleAdmin;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.ValveConstants.Protobuf;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using CounterStrikeSharp.API; using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Modules.Entities; using CounterStrikeSharp.API.Modules.Entities;
@@ -9,7 +9,6 @@ using CS2_SimpleAdminApi;
using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Capabilities; using CounterStrikeSharp.API.Core.Capabilities;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using AntiDLL.API; using AntiDLL.API;
public class PluginConfig : IBasePluginConfig public class PluginConfig : IBasePluginConfig
@@ -23,16 +22,17 @@ public class PluginConfig : IBasePluginConfig
public sealed class AntiDLL_CS2_SimpleAdmin : BasePlugin, IPluginConfig<PluginConfig> public sealed class AntiDLL_CS2_SimpleAdmin : BasePlugin, IPluginConfig<PluginConfig>
{ {
private int _banType;
public PluginConfig Config { get; set; } = new(); public PluginConfig Config { get; set; } = new();
private readonly HashSet<int> _bannedPlayers = []; private readonly HashSet<int> _bannedPlayers = [];
private readonly HashSet<int> _detections = [];
private static PluginCapability<IAntiDLL> AntiDll { get; } = new("AntiDLL"); private static PluginCapability<IAntiDLL> AntiDll { get; } = new("AntiDLL");
private static PluginCapability<ICS2_SimpleAdminApi> SimpleAdminApi { get; } = new("simpleadmin:api"); private static PluginCapability<ICS2_SimpleAdminApi> SimpleAdminApi { get; } = new("simpleadmin:api");
private int _banType = 0;
private static ICS2_SimpleAdminApi? _simpleAdminApi; private static ICS2_SimpleAdminApi? _simpleAdminApi;
public override string ModuleName => "AntiDLL [CS2-SimpleAdmin Module]"; public override string ModuleName => "AntiDLL [CS2-SimpleAdmin Module]";
public override string ModuleDescription => "AntiDLL module for CS2-SimpleAdmin integration"; public override string ModuleDescription => "AntiDLL module for CS2-SimpleAdmin integration";
public override string ModuleVersion => "1.0.0"; public override string ModuleVersion => "1.0.1";
public override string ModuleAuthor => "daffyy"; public override string ModuleAuthor => "daffyy";
public override void Load(bool hotReload) public override void Load(bool hotReload)
@@ -65,6 +65,9 @@ public sealed class AntiDLL_CS2_SimpleAdmin : BasePlugin, IPluginConfig<PluginCo
Unload(false); Unload(false);
} }
if (Config.BanType != "auto" && Config.BanType != "simpleadmin")
return;
try try
{ {
_simpleAdminApi = SimpleAdminApi.Get(); _simpleAdminApi = SimpleAdminApi.Get();
@@ -79,32 +82,55 @@ public sealed class AntiDLL_CS2_SimpleAdmin : BasePlugin, IPluginConfig<PluginCo
private void OnClientDisconnect(int playerSlot) private void OnClientDisconnect(int playerSlot)
{ {
var player = Utilities.GetPlayerFromSlot(playerSlot); // var player = Utilities.GetPlayerFromSlot(playerSlot);
if (player == null || !player.IsValid || player.IsBot) // if (player == null || !player.IsValid || player.IsBot)
return; // return;
_bannedPlayers.Remove(playerSlot); _bannedPlayers.Remove(playerSlot);
_detections.Remove(playerSlot);
}
[GameEventHandler]
public HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo _)
{
var player = @event.Userid;
if (player == null || !player.IsValid || player.IsBot || !_detections.Contains(player.Slot))
return HookResult.Continue;
if (!_bannedPlayers.Contains(player.Slot) && player.Connected == PlayerConnectedState.PlayerConnected && player.TeamNum != 0)
PunishPlayer(player);
return HookResult.Continue;
} }
private void OnDetection(CCSPlayerController? player, string eventName) private void OnDetection(CCSPlayerController? player, string eventName)
{ {
if (player == null || !player.IsValid || player.IsBot) return; if (player == null || !player.IsValid || player.IsBot) return;
if (player.Connected != PlayerConnectedState.PlayerConnected) if (!_detections.Add(player.Slot))
{
AddTimer(3.0f, () => OnDetection(player, eventName));
return; return;
}
// if (player.Connected != PlayerConnectedState.PlayerConnected)
// {
// _detections.Add(player.Slot);
// // AddTimer(3.0f, () => OnDetection(player, eventName));
// return;
// }
Logger.LogInformation("Detected \"{eventName}\" for \"{player}({steamid})\"", eventName, player.PlayerName, player.SteamID.ToString());
}
private void PunishPlayer(CCSPlayerController player)
{
if (!_bannedPlayers.Add(player.Slot)) if (!_bannedPlayers.Add(player.Slot))
return; return;
if (_banType == 1 && _simpleAdminApi != null) if (_banType == 1 && _simpleAdminApi != null)
{ {
_simpleAdminApi.IssuePenalty(new SteamID(player.SteamID), null, PenaltyType.Ban, Config.Reason, Config.Duration); _simpleAdminApi.IssuePenalty(new SteamID(player.SteamID), null, PenaltyType.Ban, Config.Reason, Config.Duration);
} }
else if (Config.BanType == "kick") else if (Config.BanType == "kick")
{ {
player.Disconnect(NetworkDisconnectionReason.NETWORK_DISCONNECT_KICKED_UNTRUSTEDACCOUNT); player.Disconnect(NetworkDisconnectionReason.NETWORK_DISCONNECT_KICKED_VACNETABNORMALBEHAVIOR);
} }
else else
{ {

View File

@@ -1,16 +0,0 @@
"Config"
{
// Доступные переменные: {userid}, {steamid}, {name}
"punish_type" "1" // 0 - kick, 1 - command(punish_command)
"punish_command" "css_addban {steamid} 0 [AC] Cheats detected #5" // Command to execute when a player is detected with a DLL
// Команда для выполнения, когда игрок обнаружен с DLL
"chat_message" "" // Сообщение в чат при обнаружении DLL для всех игроков, пусто - не отправлять
// Chat message when a player is detected with a DLL for all players, empty - dont send
"logs" "1" // Логировать в файл наказания? 0 - нет, 1 - да
// Log punishments to file? 0 - no, 1 - yes
"interval" "120" // Интервал проверки игроков на наличие DLL в секундах
// Interval to check players for DLL in seconds
}