Skip to content

Commit

Permalink
1.3.4a
Browse files Browse the repository at this point in the history
- Minor changes
- Escape kick reason @Poggu suggestion
- Auto-updater for config
- Using UTC time
- Added expiring IP bans after x days (`ExpireOldIpBans` in config => value = days, 0 = disabled)
- Added exception message to database error
- Fixed? ungag/unmute/unsilence commands
- Updated css version to `178`
- Changed `css_adminhelp` command to use new file `admin_help.txt` as output
  • Loading branch information
daffyyyy committed Mar 1, 2024
1 parent 5bf966f commit 229b8d7
Show file tree
Hide file tree
Showing 29 changed files with 724 additions and 737 deletions.
12 changes: 7 additions & 5 deletions CS2-SimpleAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CS2_SimpleAdmin;

[MinimumApiVersion(168)]
[MinimumApiVersion(178)]
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
{
public static CS2_SimpleAdmin Instance { get; private set; } = new();
Expand All @@ -38,15 +38,15 @@ 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 & Dliix66";
public override string ModuleVersion => "1.3.3a";
public override string ModuleVersion => "1.3.4a";

public CS2_SimpleAdminConfig Config { get; set; } = new();

public override void Load(bool hotReload)
{
Instance = this;

registerEvents();
RegisterEvents();

if (hotReload)
{
Expand Down Expand Up @@ -101,14 +101,16 @@ public void OnConfigParsed(CS2_SimpleAdminConfig config)
}
}
}
catch (Exception)
catch (Exception ex)
{
Logger.LogError("Unable to connect to the database!");
Logger.LogError($"Unable to connect to the database: {ex.Message}");
throw;
}
});

Config = config;
Helper.UpdateConfig(config);

_localizer = Localizer;

if (!string.IsNullOrEmpty(Config.Discord.DiscordLogWebhook))
Expand Down
6 changes: 5 additions & 1 deletion CS2-SimpleAdmin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.168" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.178" />
<PackageReference Include="Dapper" Version="*" />
<PackageReference Include="Discord.Net.Webhook" Version="3.13.1" />
<PackageReference Include="MySqlConnector" Version="2.3.5" />
Expand All @@ -24,5 +24,9 @@
<ItemGroup>
<None Update="Database\database_setup.sql" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<None Update="admin_help.txt" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
21 changes: 9 additions & 12 deletions Commands/basebans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ internal void Ban(CCSPlayerController? caller, CCSPlayerController player, int t
if (_database == null) return;

callerName ??= caller == null ? "Console" : caller.PlayerName;
banManager ??= new BanManager(_database, Config);

if (player.PawnIsAlive)
{
Expand All @@ -85,6 +84,7 @@ internal void Ban(CCSPlayerController? caller, CCSPlayerController player, int t

Task.Run(async () =>
{
banManager ??= new BanManager(_database, Config);
await banManager.BanPlayer(playerInfo, adminInfo, reason, time);
});

Expand Down Expand Up @@ -143,6 +143,7 @@ internal void Ban(CCSPlayerController? caller, CCSPlayerController player, int t
[CommandHelper(minArgs: 1, usage: "<steamid> [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
public void OnAddBanCommand(CCSPlayerController? caller, CommandInfo command)
{
if (_database == null) return;
string callerName = caller == null ? "Console" : caller.PlayerName;
if (command.ArgCount < 2)
return;
Expand Down Expand Up @@ -243,9 +244,7 @@ public void OnAddBanCommand(CCSPlayerController? caller, CommandInfo command)

Task.Run(async () =>
{
Database database = new Database(dbConnectionString);

BanManager _banManager = new(database, Config);
BanManager _banManager = new(_database, Config);
await _banManager.AddBanBySteamid(steamid, adminInfo, reason, time);
});

Expand All @@ -257,6 +256,7 @@ public void OnAddBanCommand(CCSPlayerController? caller, CommandInfo command)
[CommandHelper(minArgs: 1, usage: "<ip> [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
public void OnBanIp(CCSPlayerController? caller, CommandInfo command)
{
if (_database == null) return;
string callerName = caller == null ? "Console" : caller.PlayerName;

if (command.ArgCount < 2)
Expand Down Expand Up @@ -355,9 +355,7 @@ public void OnBanIp(CCSPlayerController? caller, CommandInfo command)

Task.Run(async () =>
{
Database database = new Database(dbConnectionString);

BanManager _banManager = new(database, Config);
BanManager _banManager = new(_database, Config);
await _banManager.AddBanByIp(ipAddress, adminInfo, reason, time);
});

Expand All @@ -369,6 +367,8 @@ public void OnBanIp(CCSPlayerController? caller, CommandInfo command)
[CommandHelper(minArgs: 1, usage: "<steamid or name or ip>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
public void OnUnbanCommand(CCSPlayerController? caller, CommandInfo command)
{
if (_database == null) return;

string callerName = caller == null ? "Console" : caller.PlayerName;
if (command.GetArg(1).Length <= 1)
{
Expand All @@ -386,11 +386,8 @@ public void OnUnbanCommand(CCSPlayerController? caller, CommandInfo command)

string pattern = command.GetArg(1);

Database database = new Database(dbConnectionString);

BanManager _banManager = new(database, Config);

_ = _banManager.UnbanPlayer(pattern);
BanManager _banManager = new BanManager(_database, Config);
Task.Run(async () => await _banManager.UnbanPlayer(pattern));

command.ReplyToCommand($"Unbanned player with pattern {pattern}.");
}
Expand Down
8 changes: 4 additions & 4 deletions Commands/basechat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public void OnAdminPrivateSayCommand(CCSPlayerController? caller, CommandInfo co

playersToTarget.ForEach(player =>
{
player.PrintToChat(Helper.ReplaceTags($"({caller!.PlayerName}) {utf8String}"));
player.PrintToChat(StringExtensions.ReplaceColorTags($"({caller!.PlayerName}) {utf8String}"));
});

command.ReplyToCommand(Helper.ReplaceTags($" Private message sent!"));
command.ReplyToCommand(StringExtensions.ReplaceColorTags($" Private message sent!"));
}

[ConsoleCommand("css_csay", "Say to all players (in center).")]
Expand All @@ -115,7 +115,7 @@ public void OnAdminCenterSayCommand(CCSPlayerController? caller, CommandInfo com

Helper.LogCommand(caller, command);

Helper.PrintToCenterAll(Helper.ReplaceTags(utf8String));
Helper.PrintToCenterAll(StringExtensions.ReplaceColorTags(utf8String));
}

[ConsoleCommand("css_hsay", "Say to all players (in hud).")]
Expand All @@ -137,7 +137,7 @@ public void OnAdminHudSayCommand(CCSPlayerController? caller, CommandInfo comman

VirtualFunctions.ClientPrintAll(
HudDestination.Alert,
Helper.ReplaceTags(utf8String),
StringExtensions.ReplaceColorTags(utf8String),
0, 0, 0, 0);
}
}
Expand Down
17 changes: 16 additions & 1 deletion Commands/basecommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public void OnAdminCommand(CCSPlayerController? caller, CommandInfo command)
[RequiresPermissions("@css/generic")]
public void OnAdminHelpCommand(CCSPlayerController? caller, CommandInfo command)
{
if (caller == null || !caller.IsValid) return;
//if (caller == null || !caller.IsValid) return;

/*
using (new WithTemporaryCulture(caller.GetLanguage()))
{
var splitMessage = _localizer!["sa_adminhelp"].ToString().Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
Expand All @@ -65,6 +66,20 @@ public void OnAdminHelpCommand(CCSPlayerController? caller, CommandInfo command)
{
caller.PrintToChat(Helper.ReplaceTags($" {line}"));
}
} */

string[] lines = File.ReadAllLines(ModuleDirectory + "/admin_help.txt");

foreach (string line in lines)
{
if (string.IsNullOrWhiteSpace(line))
{
command.ReplyToCommand(" ");
}
else
{
command.ReplyToCommand(StringExtensions.ReplaceColorTags(line));
}
}
}

Expand Down
59 changes: 45 additions & 14 deletions Commands/basecomms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,12 @@ public void OnAddGagCommand(CCSPlayerController? caller, CommandInfo command)
playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Gag, DateTime.Now.AddMinutes(time), time);
}
}
_ = _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 0);

Task.Run(async () =>
{
await _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 0);
});

command.ReplyToCommand($"Gagged player with steamid {steamid}.");
}

Expand Down Expand Up @@ -277,6 +282,11 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)

PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();

Task.Run(async () =>
{
await _muteManager.UnmutePlayer(pattern, 0); // Unmute by type 0 (gag)
});

if (Helper.IsValidSteamID64(pattern))
{
List<CCSPlayerController> matches = Helper.GetPlayerFromSteamid64(pattern);
Expand Down Expand Up @@ -313,12 +323,6 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)
}
}
}
if (found)
{
_ = _muteManager.UnmutePlayer(pattern, 0); // Unmute by type 0 (gag)
command.ReplyToCommand($"Ungaged player with pattern {pattern}.");
return;
}

TargetResult? targets = GetTarget(command);
if (targets == null) return;
Expand All @@ -336,7 +340,11 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)
playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Gag);

if (player!.SteamID.ToString().Length == 17)
_ = _muteManager.UnmutePlayer(player.SteamID.ToString(), 0); // Unmute by type 0 (gag)
Task.Run(async () =>
{
await _muteManager.UnmutePlayer(player.SteamID.ToString(), 0); // Unmute by type 0 (gag)
});


if (TagsDetected)
Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}");
Expand Down Expand Up @@ -567,7 +575,12 @@ public void OnAddMuteCommand(CCSPlayerController? caller, CommandInfo command)
}
}
}
_ = _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 1);

Task.Run(async () =>
{
await _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 1);
});

command.ReplyToCommand($"Muted player with steamid {steamid}.");
}

Expand Down Expand Up @@ -598,6 +611,11 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command)
MuteManager _muteManager = new(_database);
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();

Task.Run(async () =>
{
await _muteManager.UnmutePlayer(pattern, 1); // Unmute by type 1 (mute)
});

if (Helper.IsValidSteamID64(pattern))
{
List<CCSPlayerController> matches = Helper.GetPlayerFromSteamid64(pattern);
Expand Down Expand Up @@ -630,12 +648,12 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command)

if (found)
{
_ = _muteManager.UnmutePlayer(pattern, 1); // Unmute by type 1 (mute)
command.ReplyToCommand($"Unmuted player with pattern {pattern}.");
return;
}

TargetResult? targets = GetTarget(command);
if (targets == null) return;
List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList();

if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0)
Expand All @@ -648,7 +666,10 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command)
playersToTarget.ForEach(player =>
{
if (player.SteamID.ToString().Length == 17)
_ = _muteManager.UnmutePlayer(player.SteamID.ToString(), 1); // Unmute by type 1 (mute)
Task.Run(async () =>
{
await _muteManager.UnmutePlayer(player.SteamID.ToString(), 1); // Unmute by type 1 (mute)
});

playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Mute);
player.VoiceFlags = VoiceFlags.Normal;
Expand Down Expand Up @@ -890,7 +911,11 @@ public void OnAddSilenceCommand(CCSPlayerController? caller, CommandInfo command
}
}
}
_ = _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 2);
Task.Run(async () =>
{
await _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 2);
});

command.ReplyToCommand($"Silenced player with steamid {steamid}.");
}

Expand Down Expand Up @@ -921,6 +946,11 @@ public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command)
MuteManager _muteManager = new(_database);
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();

Task.Run(async () =>
{
await _muteManager.UnmutePlayer(pattern, 2); // Unmute by type 2 (silence)
});

if (Helper.IsValidSteamID64(pattern))
{
List<CCSPlayerController> matches = Helper.GetPlayerFromSteamid64(pattern);
Expand Down Expand Up @@ -959,12 +989,13 @@ public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command)

if (found)
{
_ = _muteManager.UnmutePlayer(pattern, 2); // Unmute by type 2 (silence)
//Task.Run(async () => { await _muteManager.UnmutePlayer(pattern, 2); }); // Unmute by type 2 (silence)
command.ReplyToCommand($"Unsilenced player with pattern {pattern}.");
return;
}

TargetResult? targets = GetTarget(command);
if (targets == null) return;
List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList();

if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0)
Expand All @@ -977,7 +1008,7 @@ public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command)
playersToTarget.ForEach(player =>
{
if (player.SteamID.ToString().Length == 17)
_ = _muteManager.UnmutePlayer(player.SteamID.ToString(), 2); // Unmute by type 2 (silence)
Task.Run(async () => { await _muteManager.UnmutePlayer(player.SteamID.ToString(), 2); }); // Unmute by type 2 (silence)

if (TagsDetected)
Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}");
Expand Down
3 changes: 2 additions & 1 deletion Commands/basevotes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ public void OnVoteCommand(CCSPlayerController? caller, CommandInfo command)
}

voteMenu.PostSelectAction = PostSelectAction.Close;
MenuManager.OpenChatMenu(_player, voteMenu);

Helper.PrintToCenterAll(_localizer!["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]);
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]);
_player.PrintToChat(sb.ToString());

MenuManager.OpenChatMenu(_player, voteMenu);
}
}

Expand Down
Loading

0 comments on commit 229b8d7

Please sign in to comment.