Files
CS2-SimpleAdmin/Modules/CS2-SimpleAdmin_BanSoundModule/CS2-SimpleAdmin_BanSoundModule.cs
Dawid Bepierszcz eea700bfb4 Version bump and multi-account/IP ban fixes
Bump version to 1.7.9a and update package references (CounterStrikeSharp.API, Dapper, System.Linq.Async, ZLinq). Replace usages of PlayerConnectedState.PlayerConnected with PlayerConnectedState.Connected across commands, events, and helpers. Add DB method GetExpireOldPlayerIpsQuery (MySQL/SQLite) and call it to purge old player IP records during ban expiration. Improve CacheManager multi-account/ip ban detection (direct IP bans, cross-account IP checks) and adjust ban logic to respect expiration window. In PlayerManager: reduce semaphore, save player IP to DB before performing ban checks (add SavePlayerIpAddress), and always perform ban checks on connect. Simplify config upgrade logic in Helper.UpdateConfig to update the JSON file Version via JsonNode. Misc: adjust ban sound volume, minor exception catch cleanup, and add module folder to .gitignore.
2026-04-23 22:15:44 +02:00

51 lines
1.7 KiB
C#

using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Capabilities;
using CounterStrikeSharp.API.Modules.Utils;
using CS2_SimpleAdminApi;
using Microsoft.Extensions.Logging;
namespace CS2_SimpleAdmin_BanSoundModule;
public class CS2_SimpleAdmin_BanSoundModule: BasePlugin
{
public override string ModuleName => "[CS2-SimpleAdmin] BanSound Module";
public override string ModuleVersion => "v1.0.0";
public override string ModuleAuthor => "daffyy";
private static ICS2_SimpleAdminApi? _sharedApi;
private readonly PluginCapability<ICS2_SimpleAdminApi> _pluginCapability = new("simpleadmin:api");
public override void OnAllPluginsLoaded(bool hotReload)
{
_sharedApi = _pluginCapability.Get();
if (_sharedApi == null)
{
Logger.LogError("CS2-SimpleAdmin SharedApi not found");
Unload(false);
return;
}
RegisterListener<Listeners.OnServerPrecacheResources>(OnServerPrecacheResources);
_sharedApi.OnPlayerPenaltied += OnPlayerPenaltied;
}
private void OnServerPrecacheResources(ResourceManifest manifest)
{
manifest.AddResource("soundevents/soundevents_addon.vsndevts");
}
private void OnPlayerPenaltied(PlayerInfo playerInfo, PlayerInfo? admin, PenaltyType penaltyType,
string reason, int duration, int? penaltyId, int? serverId)
{
if (penaltyType != PenaltyType.Ban || admin == null)
return;
foreach (var player in Utilities.GetPlayers().Where(p => p.IsValid && !p.IsBot))
{
var filter = new RecipientFilter(player);
player?.EmitSound("bansound", volume: 0.75f, recipients: filter);
}
}
}