Skip to content

Commit

Permalink
1.6.3b
Browse files Browse the repository at this point in the history
```diff
+ Small code cleanup
+ FIXED ban check on connect
```
  • Loading branch information
daffyyyy committed Oct 7, 2024
1 parent d0207f3 commit 9820d74
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 103 deletions.
21 changes: 12 additions & 9 deletions CS2-SimpleAdmin/CS2-SimpleAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CounterStrikeSharp.API.Core.Capabilities;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Commands.Targeting;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using CS2_SimpleAdmin.Managers;
using CS2_SimpleAdminApi;
Expand All @@ -19,7 +20,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
public override string ModuleName => "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)");
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
public override string ModuleAuthor => "daffyy & Dliix66";
public override string ModuleVersion => "1.6.3a";
public override string ModuleVersion => "1.6.3b";

public override void Load(bool hotReload)
{
Expand Down Expand Up @@ -48,6 +49,8 @@ public override void Load(bool hotReload)

SimpleAdminApi = new Api.CS2_SimpleAdminApi();
Capabilities.RegisterPluginCapability(ICS2_SimpleAdminApi.PluginCapability, () => SimpleAdminApi);

new PlayerManager().CheckPlayersTimer();
}

public override void OnAllPluginsLoaded(bool hotReload)
Expand All @@ -63,13 +66,13 @@ public override void OnAllPluginsLoaded(bool hotReload)

public void OnConfigParsed(CS2_SimpleAdminConfig config)
{
Instance = this;
_logger = Logger;

if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
{
throw new Exception("[CS2-SimpleAdmin] You need to setup Database credentials in config!");
}

Instance = this;
_logger = Logger;

MySqlConnectionStringBuilder builder = new()
{
Expand All @@ -95,11 +98,6 @@ public void OnConfigParsed(CS2_SimpleAdminConfig config)

Task.Run(() => Database.DatabaseMigration());

PermissionManager = new PermissionManager(Database);
BanManager = new BanManager(Database);
MuteManager = new MuteManager(Database);
WarnManager = new WarnManager(Database);

Config = config;
Helper.UpdateConfig(config);

Expand All @@ -116,6 +114,11 @@ public void OnConfigParsed(CS2_SimpleAdminConfig config)
PluginInfo.ShowAd(ModuleVersion);
if (Config.EnableUpdateCheck)
Task.Run(async () => await PluginInfo.CheckVersion(ModuleVersion, _logger));

PermissionManager = new PermissionManager(Database);
BanManager = new BanManager(Database);
MuteManager = new MuteManager(Database);
WarnManager = new WarnManager(Database);
}

private static TargetResult? GetTarget(CommandInfo command)
Expand Down
2 changes: 0 additions & 2 deletions CS2-SimpleAdmin/Commands/basebans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,6 @@ public void OnUnwarnCommand(CCSPlayerController? caller, CommandInfo command)
{
if (Database == null) return;

var callerSteamId = caller?.SteamID.ToString() ?? _localizer?["sa_console"] ?? "Console";

if (command.GetArg(1).Length <= 1)
{
command.ReplyToCommand($"Too short pattern to search.");
Expand Down
14 changes: 5 additions & 9 deletions CS2-SimpleAdmin/Commands/basecommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,9 @@ public void OnAddAdminCommand(CCSPlayerController? caller, CommandInfo command)
public static void AddAdmin(CCSPlayerController? caller, string steamid, string name, string flags, int immunity, int time = 0, bool globalAdmin = false, CommandInfo? command = null)
{
if (Database == null) return;
PermissionManager adminManager = new(Database);


var flagsList = flags.Split(',').Select(flag => flag.Trim()).ToList();
_ = adminManager.AddAdminBySteamId(steamid, name, flagsList, immunity, time, globalAdmin);
_ = Instance.PermissionManager.AddAdminBySteamId(steamid, name, flagsList, immunity, time, globalAdmin);

Helper.LogCommand(caller, $"css_addadmin {steamid} {name} {flags} {immunity} {time}");

Expand Down Expand Up @@ -289,10 +288,9 @@ public void OnAddGroup(CCSPlayerController? caller, CommandInfo command)
private static void AddGroup(CCSPlayerController? caller, string name, string flags, int immunity, bool globalGroup, CommandInfo? command = null)
{
if (Database == null) return;
PermissionManager adminManager = new(Database);

var flagsList = flags.Split(',').Select(flag => flag.Trim()).ToList();
_ = adminManager.AddGroup(name, flagsList, immunity, globalGroup);
_ = Instance.PermissionManager.AddGroup(name, flagsList, immunity, globalGroup);

Helper.LogCommand(caller, $"css_addgroup {name} {flags} {immunity}");

Expand Down Expand Up @@ -367,12 +365,10 @@ public void ReloadAdmins(CCSPlayerController? caller)
AdminManager.RemovePlayerAdminData(steamId);
}

PermissionManager adminManager = new(Database);

Task.Run(async () =>
{
await adminManager.CrateGroupsJsonFile();
await adminManager.CreateAdminsJsonFile();
await PermissionManager.CrateGroupsJsonFile();
await PermissionManager.CreateAdminsJsonFile();

var adminsFile = await File.ReadAllTextAsync(Instance.ModuleDirectory + "/data/admins.json");
var groupsFile = await File.ReadAllTextAsync(Instance.ModuleDirectory + "/data/groups.json");
Expand Down
48 changes: 21 additions & 27 deletions CS2-SimpleAdmin/Commands/basecomms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,17 @@ public void OnGagCommand(CCSPlayerController? caller, CommandInfo command)
return;
}

Gag(caller, player, time, reason, callerName, MuteManager, command);
Gag(caller, player, time, reason, callerName, command);
});
}

internal void Gag(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, MuteManager? muteManager = null, CommandInfo? command = null, bool silent = false)
internal void Gag(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, CommandInfo? command = null, bool silent = false)
{
if (Database == null || !player.IsValid || !player.UserId.HasValue) return;
if (!caller.CanTarget(player)) return;

// Set default caller name if not provided
callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName;
muteManager ??= new MuteManager(Database);

// Get player and admin information
var playerInfo = PlayersInfo[player.UserId.Value];
Expand All @@ -62,7 +61,7 @@ internal void Gag(CCSPlayerController? caller, CCSPlayerController player, int t
// Asynchronously handle gag logic
Task.Run(async () =>
{
await muteManager.MutePlayer(playerInfo, adminInfo, reason, time);
await MuteManager.MutePlayer(playerInfo, adminInfo, reason, time);
});

// Add penalty to the player's penalty manager
Expand Down Expand Up @@ -141,7 +140,7 @@ public void OnAddGagCommand(CCSPlayerController? caller, CommandInfo command)
if (!caller.CanTarget(player)) return;

// Perform the gag for an online player
Gag(caller, player, time, reason, callerName, MuteManager, silent: true);
Gag(caller, player, time, reason, callerName, silent: true);
}
else
{
Expand Down Expand Up @@ -176,7 +175,6 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)
}

Helper.LogCommand(caller, command);
var muteManager = new MuteManager(Database);

// Check if pattern is a valid SteamID64
if (Helper.ValidateSteamId(pattern, out var steamId) && steamId != null)
Expand All @@ -190,7 +188,7 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)

Task.Run(async () =>
{
await muteManager.UnmutePlayer(player.SteamID.ToString(), callerSteamId, reason);
await MuteManager.UnmutePlayer(player.SteamID.ToString(), callerSteamId, reason);
});

command.ReplyToCommand($"Ungaged player {player.PlayerName}.");
Expand All @@ -211,7 +209,7 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)

Task.Run(async () =>
{
await muteManager.UnmutePlayer(namePlayer.SteamID.ToString(), callerSteamId, reason);
await MuteManager.UnmutePlayer(namePlayer.SteamID.ToString(), callerSteamId, reason);
});

command.ReplyToCommand($"Ungaged player {namePlayer.PlayerName}.");
Expand All @@ -220,7 +218,7 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)
{
Task.Run(async () =>
{
await muteManager.UnmutePlayer(pattern, callerSteamId, reason);
await MuteManager.UnmutePlayer(pattern, callerSteamId, reason);
});

command.ReplyToCommand($"Ungaged offline player with pattern {pattern}.");
Expand Down Expand Up @@ -258,18 +256,17 @@ public void OnMuteCommand(CCSPlayerController? caller, CommandInfo command)
return;
}

Mute(caller, player, time, reason, callerName, MuteManager, command);
Mute(caller, player, time, reason, callerName, command);
});
}

internal void Mute(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, MuteManager? muteManager = null, CommandInfo? command = null, bool silent = false)
internal void Mute(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, CommandInfo? command = null, bool silent = false)
{
if (Database == null || !player.IsValid || !player.UserId.HasValue) return;
if (!caller.CanTarget(player)) return;

// Set default caller name if not provided
callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName;
muteManager ??= new MuteManager(Database);

// Get player and admin information
var playerInfo = PlayersInfo[player.UserId.Value];
Expand All @@ -281,7 +278,7 @@ internal void Mute(CCSPlayerController? caller, CCSPlayerController player, int
// Asynchronously handle mute logic
Task.Run(async () =>
{
await muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 1);
await MuteManager.MutePlayer(playerInfo, adminInfo, reason, time, 1);
});

// Add penalty to the player's penalty manager
Expand Down Expand Up @@ -360,7 +357,7 @@ public void OnAddMuteCommand(CCSPlayerController? caller, CommandInfo command)
if (!caller.CanTarget(player)) return;

// Perform the mute for an online player
Mute(caller, player, time, reason, callerName, MuteManager, silent: true);
Mute(caller, player, time, reason, callerName, silent: true);
}
else
{
Expand Down Expand Up @@ -395,7 +392,6 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command)
}

Helper.LogCommand(caller, command);
var muteManager = new MuteManager(Database);

// Check if pattern is a valid SteamID64
if (Helper.ValidateSteamId(pattern, out var steamId) && steamId != null)
Expand All @@ -410,7 +406,7 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command)

Task.Run(async () =>
{
await muteManager.UnmutePlayer(player.SteamID.ToString(), callerSteamId, reason, 1);
await MuteManager.UnmutePlayer(player.SteamID.ToString(), callerSteamId, reason, 1);
});

command.ReplyToCommand($"Unmuted player {player.PlayerName}.");
Expand All @@ -432,7 +428,7 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command)

Task.Run(async () =>
{
await muteManager.UnmutePlayer(namePlayer.SteamID.ToString(), callerSteamId, reason, 1);
await MuteManager.UnmutePlayer(namePlayer.SteamID.ToString(), callerSteamId, reason, 1);
});

command.ReplyToCommand($"Unmuted player {namePlayer.PlayerName}.");
Expand All @@ -441,7 +437,7 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command)
{
Task.Run(async () =>
{
await muteManager.UnmutePlayer(pattern, callerSteamId, reason, 1);
await MuteManager.UnmutePlayer(pattern, callerSteamId, reason, 1);
});

command.ReplyToCommand($"Unmuted offline player with pattern {pattern}.");
Expand Down Expand Up @@ -479,18 +475,17 @@ public void OnSilenceCommand(CCSPlayerController? caller, CommandInfo command)
return;
}

Silence(caller, player, time, reason, callerName, MuteManager, command);
Silence(caller, player, time, reason, callerName, command);
});
}

internal void Silence(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, MuteManager? muteManager = null, CommandInfo? command = null, bool silent = false)
internal void Silence(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, CommandInfo? command = null, bool silent = false)
{
if (Database == null || !player.IsValid || !player.UserId.HasValue) return;
if (!caller.CanTarget(player)) return;

// Set default caller name if not provided
callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName;
muteManager ??= new MuteManager(Database);

// Get player and admin information
var playerInfo = PlayersInfo[player.UserId.Value];
Expand All @@ -499,7 +494,7 @@ internal void Silence(CCSPlayerController? caller, CCSPlayerController player, i
// Asynchronously handle silence logic
Task.Run(async () =>
{
await muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 2); // Assuming 2 is the type for silence
await MuteManager.MutePlayer(playerInfo, adminInfo, reason, time, 2); // Assuming 2 is the type for silence
});

// Add penalty to the player's penalty manager
Expand Down Expand Up @@ -578,7 +573,7 @@ public void OnAddSilenceCommand(CCSPlayerController? caller, CommandInfo command
if (!caller.CanTarget(player)) return;

// Perform the silence for an online player
Silence(caller, player, time, reason, callerName, MuteManager, silent: true);
Silence(caller, player, time, reason, callerName, silent: true);
}
else
{
Expand Down Expand Up @@ -613,7 +608,6 @@ public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command)
}

Helper.LogCommand(caller, command);
var muteManager = new MuteManager(Database);

// Check if pattern is a valid SteamID64
if (Helper.ValidateSteamId(pattern, out var steamId) && steamId != null)
Expand All @@ -630,7 +624,7 @@ public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command)

Task.Run(async () =>
{
await muteManager.UnmutePlayer(player.SteamID.ToString(), callerSteamId, reason, 2); // Unmute by type 2 (silence)
await MuteManager.UnmutePlayer(player.SteamID.ToString(), callerSteamId, reason, 2); // Unmute by type 2 (silence)
});

command.ReplyToCommand($"Unsilenced player {player.PlayerName}.");
Expand All @@ -654,7 +648,7 @@ public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command)

Task.Run(async () =>
{
await muteManager.UnmutePlayer(namePlayer.SteamID.ToString(), callerSteamId, reason, 2); // Unmute by type 2 (silence)
await MuteManager.UnmutePlayer(namePlayer.SteamID.ToString(), callerSteamId, reason, 2); // Unmute by type 2 (silence)
});

command.ReplyToCommand($"Unsilenced player {namePlayer.PlayerName}.");
Expand All @@ -663,7 +657,7 @@ public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command)
{
Task.Run(async () =>
{
await muteManager.UnmutePlayer(pattern, callerSteamId, reason, 2); // Unmute by type 2 (silence)
await MuteManager.UnmutePlayer(pattern, callerSteamId, reason, 2); // Unmute by type 2 (silence)
});

command.ReplyToCommand($"Unsilenced offline player with pattern {pattern}.");
Expand Down
Loading

0 comments on commit 9820d74

Please sign in to comment.