KickTime in config, and gag

This commit is contained in:
daffyyyy
2023-12-03 19:22:34 +01:00
parent 5ea71f1679
commit 0f32daa4c0
7 changed files with 387 additions and 11 deletions

View File

@@ -1,6 +1,8 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Entities;
using static CounterStrikeSharp.API.Core.Listeners;
namespace CS2_SimpleAdmin
{
@@ -8,8 +10,23 @@ namespace CS2_SimpleAdmin
{
private void registerEvents()
{
RegisterListener<Listeners.OnClientAuthorized>(OnClientAuthorized);
RegisterListener<Listeners.OnMapStart>(OnMapStart);
RegisterListener<OnClientAuthorized>(OnClientAuthorized);
RegisterListener<OnClientDisconnect>(OnClientDisconnect);
RegisterListener<OnMapStart>(OnMapStart);
AddCommandListener("say", OnCommandSay);
AddCommandListener("say_team", OnCommandSay);
}
private HookResult OnCommandSay(CCSPlayerController? player, CommandInfo info)
{
if (player == null || !player.IsValid || info.GetArg(1).Length == 0) return HookResult.Continue;
if (gaggedPlayers.Contains((int)player.Index))
{
return HookResult.Handled;
}
return HookResult.Continue;
}
private void OnClientAuthorized(int playerSlot, SteamID steamID)
@@ -28,20 +45,53 @@ namespace CS2_SimpleAdmin
}
BanManager _banManager = new(dbConnectionString);
MuteManager _muteManager = new(dbConnectionString);
bool isBanned = _banManager.IsPlayerBanned(player.AuthorizedSteamID.SteamId64.ToString());
List<dynamic> activeMutes = _muteManager.IsPlayerMuted(player.AuthorizedSteamID.SteamId64.ToString());
if (activeMutes.Count > 0)
{
// Player is muted, handle mute
foreach (var mute in activeMutes)
{
string muteType = mute.type;
if (muteType == "GAG")
{
if (!gaggedPlayers.Contains((int)player.Index))
gaggedPlayers.Add((int)player.Index);
}
else
{
continue;
}
}
}
// Player is banned, kick him
if (isBanned)
{
Helper.KickPlayer(player.UserId, "Banned");
}
}
private void OnClientDisconnect(int playerSlot)
{
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
gaggedPlayers.Remove((int)player.Index);
}
private void OnMapStart(string mapName)
{
AddTimer(120.0f, () =>
{
BanManager _banManager = new(dbConnectionString);
_banManager.ExpireOldBans();
MuteManager _muteManager = new(dbConnectionString);
_muteManager.ExpireOldMutes();
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT | CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
}