Skip to content

Commit

Permalink
1.3.3a
Browse files Browse the repository at this point in the history
- Fixed godmode
- Added logging commands to simpleadmin logs file
- Fixed votes?
- Added updating player_ip and player_name after connect with ban issued by css_addban
  • Loading branch information
daffyyyy committed Feb 21, 2024
1 parent 619bdfb commit 5bf966f
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 87 deletions.
5 changes: 2 additions & 3 deletions CS2-SimpleAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@

namespace CS2_SimpleAdmin;

[MinimumApiVersion(163)]
[MinimumApiVersion(168)]
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
{
public static CS2_SimpleAdmin Instance { get; private set; } = new();

public static IStringLocalizer? _localizer;
public static Dictionary<string, int> voteAnswers = new Dictionary<string, int>();
public static HashSet<int> votePlayers = new HashSet<int>();
public static ConcurrentBag<int> godPlayers = new ConcurrentBag<int>();
public static ConcurrentBag<int> silentPlayers = new ConcurrentBag<int>();
public static ConcurrentBag<string> bannedPlayers = new ConcurrentBag<string>();
Expand All @@ -39,7 +38,7 @@ 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.2b";
public override string ModuleVersion => "1.3.3a";

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

Expand Down
2 changes: 1 addition & 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.166" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.168" />
<PackageReference Include="Dapper" Version="*" />
<PackageReference Include="Discord.Net.Webhook" Version="3.13.1" />
<PackageReference Include="MySqlConnector" Version="2.3.5" />
Expand Down
9 changes: 9 additions & 0 deletions Commands/basebans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void OnBanCommand(CCSPlayerController? caller, CommandInfo command)
internal void Ban(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, BanManager? banManager = null)
{
if (_database == null) return;

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

Expand All @@ -80,6 +81,8 @@ internal void Ban(CCSPlayerController? caller, CCSPlayerController player, int t
IpAddress = caller?.IpAddress?.Split(":")[0]
};

Helper.LogCommand(caller, $"css_ban {player?.SteamID} {time} {reason}");

Task.Run(async () =>
{
await banManager.BanPlayer(playerInfo, adminInfo, reason, time);
Expand Down Expand Up @@ -177,6 +180,8 @@ public void OnAddBanCommand(CCSPlayerController? caller, CommandInfo command)
IpAddress = caller?.IpAddress?.Split(":")[0]
};

Helper.LogCommand(caller, command);

List<CCSPlayerController> matches = Helper.GetPlayerFromSteamid64(steamid);
if (matches.Count == 1)
{
Expand Down Expand Up @@ -281,6 +286,8 @@ public void OnBanIp(CCSPlayerController? caller, CommandInfo command)
IpAddress = caller?.IpAddress?.Split(":")[0]
};

Helper.LogCommand(caller, command);

int.TryParse(command.GetArg(2), out int time);

if (command.ArgCount >= 3 && command.GetArg(3).Length > 0)
Expand Down Expand Up @@ -375,6 +382,8 @@ public void OnUnbanCommand(CCSPlayerController? caller, CommandInfo command)
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}

Helper.LogCommand(caller, command);

string pattern = command.GetArg(1);

Database database = new Database(dbConnectionString);
Expand Down
10 changes: 10 additions & 0 deletions Commands/basechat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public void OnAdminToAdminSayCommand(CCSPlayerController? caller, CommandInfo co
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}

Helper.LogCommand(caller, command);

byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]);
string utf8String = Encoding.UTF8.GetString(utf8BytesString);

Expand Down Expand Up @@ -58,6 +60,8 @@ public void OnAdminSayCommand(CCSPlayerController? caller, CommandInfo command)
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}

Helper.LogCommand(caller, command);

foreach (CCSPlayerController _player in Helper.GetValidPlayers())
{
using (new WithTemporaryCulture(_player.GetLanguage()))
Expand All @@ -78,6 +82,8 @@ public void OnAdminPrivateSayCommand(CCSPlayerController? caller, CommandInfo co
if (targets == null) return;
List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList();

Helper.LogCommand(caller, command);

int range = command.GetArg(0).Length + command.GetArg(1).Length + 2;
string message = command.GetCommandString[range..];

Expand Down Expand Up @@ -107,6 +113,8 @@ public void OnAdminCenterSayCommand(CCSPlayerController? caller, CommandInfo com
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}

Helper.LogCommand(caller, command);

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

Expand All @@ -125,6 +133,8 @@ public void OnAdminHudSayCommand(CCSPlayerController? caller, CommandInfo comman
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}

Helper.LogCommand(caller, command);

VirtualFunctions.ClientPrintAll(
HudDestination.Alert,
Helper.ReplaceTags(utf8String),
Expand Down
37 changes: 27 additions & 10 deletions Commands/basecommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public void AddAdmin(CCSPlayerController? caller, string steamid, string name, s
AdminSQLManager _adminManager = new(_database);
_ = _adminManager.AddAdminBySteamId(steamid, name, flags, immunity, time, globalAdmin);

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

string msg = $"Added '{flags}' flags to '{name}' ({steamid})";
if (command != null)
command.ReplyToCommand(msg);
Expand Down Expand Up @@ -171,6 +173,8 @@ public void RemoveAdmin(CCSPlayerController? caller, string steamid, bool global
}
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);

Helper.LogCommand(caller, $"css_deladmin {steamid}");

string msg = $"Removed flags from '{steamid}'";
if (command != null)
command.ReplyToCommand(msg);
Expand All @@ -195,6 +199,7 @@ public void OnRelAdminCommand(CCSPlayerController? caller, CommandInfo command)
public void ReloadAdmins()
{
if (_database == null) return;

foreach (SteamID steamId in AdminSQLManager._adminCache.Keys.ToList())
{
if (AdminSQLManager._adminCache.TryRemove(steamId, out _))
Expand All @@ -216,6 +221,8 @@ public void OnHideCommand(CCSPlayerController? caller, CommandInfo command)
{
if (caller == null) return;

Helper.LogCommand(caller, command);

if (silentPlayers.Contains(caller.Slot))
{
RemoveFromConcurrentBag(silentPlayers, caller.Slot);
Expand All @@ -226,16 +233,14 @@ public void OnHideCommand(CCSPlayerController? caller, CommandInfo command)
{
silentPlayers.Add(caller.Slot);
Server.ExecuteCommand("sv_disable_teamselect_menu 1");
Server.NextFrame(() =>
{
if (caller.PlayerPawn.Value != null && caller.PawnIsAlive)
caller.PlayerPawn.Value.CommitSuicide(true, false);

AddTimer(1.0f, () => { caller.ChangeTeam(CsTeam.Spectator); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
AddTimer(1.15f, () => { caller.ChangeTeam(CsTeam.None); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
caller.PrintToChat($"You are hidden now!");
AddTimer(1.22f, () => { Server.ExecuteCommand("sv_disable_teamselect_menu 0"); });
});
if (caller.PlayerPawn.Value != null && caller.PawnIsAlive)
caller.PlayerPawn.Value.CommitSuicide(true, false);

AddTimer(1.0f, () => { Server.NextFrame(() => caller.ChangeTeam(CsTeam.Spectator)); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
AddTimer(1.4f, () => { Server.NextFrame(() => caller.ChangeTeam(CsTeam.None)); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
caller.PrintToChat($"You are hidden now!");
AddTimer(2.0f, () => { Server.NextFrame(() => Server.ExecuteCommand("sv_disable_teamselect_menu 0")); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
}

Expand Down Expand Up @@ -390,6 +395,8 @@ public void Kick(CCSPlayerController? caller, CCSPlayerController player, string
player.Pawn.Value!.Freeze();
}

Helper.LogCommand(caller, $"css_kick {player.PlayerName} {reason}");

if (string.IsNullOrEmpty(reason) == false)
{
if (!player.IsBot && !player.IsHLTV)
Expand Down Expand Up @@ -450,6 +457,8 @@ public void ChangeMap(CCSPlayerController? caller, string map, CommandInfo? comm
string commandName = command?.GetCommandString ?? "css_changemap";
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandName]));
}
if (command is not null)
Helper.LogCommand(caller, command);

AddTimer(2.0f, () =>
{
Expand Down Expand Up @@ -537,6 +546,8 @@ public void ChangeWorkshopMap(CCSPlayerController? caller, string map, CommandIn
string commandName = command?.GetCommandString ?? "css_changewsmap";
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandName]));
}
if (command is not null)
Helper.LogCommand(caller, command);

AddTimer(2.0f, () =>
{
Expand Down Expand Up @@ -570,6 +581,8 @@ public void OnCvarCommand(CCSPlayerController? caller, CommandInfo command)
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}

Helper.LogCommand(caller, command);

var value = command.GetArg(2);

Server.ExecuteCommand($"{cvar.Name} {value}");
Expand All @@ -591,6 +604,8 @@ public void OnRconCommand(CCSPlayerController? caller, CommandInfo command)
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}

Helper.LogCommand(caller, command);

Server.ExecuteCommand(command.ArgString);
command.ReplyToCommand($"{callerName} executed command {command.ArgString}.");
Logger.LogInformation($"{callerName} executed command ({command.ArgString}).");
Expand All @@ -609,9 +624,11 @@ public void OnRestartCommand(CCSPlayerController? caller, CommandInfo command)

public static void RestartGame(CCSPlayerController? admin)
{
Helper.LogCommand(admin, "css_restartgame");

// TODO: Localize
var name = admin == null ? "Console" : admin.PlayerName;
Server.PrintToChatAll($"[SimpleAdmin] {name}: Restarting game...");
Server.PrintToChatAll($"[SA] {name}: Restarting game...");
Server.ExecuteCommand("mp_restartgame 2");
}
}
Expand Down
18 changes: 18 additions & 0 deletions Commands/basecomms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ internal void Gag(CCSPlayerController? caller, CCSPlayerController player, int t
IpAddress = caller?.IpAddress?.Split(":")[0]
};

Helper.LogCommand(caller, $"css_gag {player?.SteamID} {time} {reason}");

Task.Run(async () =>
{
await muteManager.MutePlayer(playerInfo, adminInfo, reason, time);
Expand Down Expand Up @@ -179,6 +181,8 @@ public void OnAddGagCommand(CCSPlayerController? caller, CommandInfo command)
IpAddress = caller?.IpAddress?.Split(":")[0]
};

Helper.LogCommand(caller, command);

List<CCSPlayerController> matches = Helper.GetPlayerFromSteamid64(steamid);
if (matches.Count == 1)
{
Expand Down Expand Up @@ -264,6 +268,8 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}

Helper.LogCommand(caller, command);

bool found = false;

string pattern = command.GetArg(1);
Expand Down Expand Up @@ -405,6 +411,8 @@ internal void Mute(CCSPlayerController? caller, CCSPlayerController player, int
IpAddress = caller?.IpAddress?.Split(":")[0]
};

Helper.LogCommand(caller, $"css_mute {player?.SteamID} {time} {reason}");

player!.VoiceFlags = VoiceFlags.Muted;

Task.Run(async () =>
Expand Down Expand Up @@ -483,6 +491,8 @@ public void OnAddMuteCommand(CCSPlayerController? caller, CommandInfo command)
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}

Helper.LogCommand(caller, command);

int time = 0;
string reason = "Unknown";

Expand Down Expand Up @@ -581,6 +591,8 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command)
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}

Helper.LogCommand(caller, command);

string pattern = command.GetArg(1);
bool found = false;
MuteManager _muteManager = new(_database);
Expand Down Expand Up @@ -711,6 +723,8 @@ internal void Silence(CCSPlayerController? caller, CCSPlayerController player, i
IpAddress = caller?.IpAddress?.Split(":")[0]
};

Helper.LogCommand(caller, $"css_silence {player?.SteamID} {time} {reason}");

Task.Run(async () =>
{
await muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 2);
Expand Down Expand Up @@ -797,6 +811,8 @@ public void OnAddSilenceCommand(CCSPlayerController? caller, CommandInfo command
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}

Helper.LogCommand(caller, command);

int time = 0;
string reason = "Unknown";

Expand Down Expand Up @@ -898,6 +914,8 @@ public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command)
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}

Helper.LogCommand(caller, command);

string pattern = command.GetArg(1);
bool found = false;
MuteManager _muteManager = new(_database);
Expand Down
18 changes: 12 additions & 6 deletions Commands/basevotes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,39 @@ public void OnVoteCommand(CCSPlayerController? caller, CommandInfo command)
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}

Helper.LogCommand(caller, command);

voteAnswers.Clear();

string question = command.GetArg(1);
int answersCount = command.ArgCount;

if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot))
{
ChatMenu voteMenu = new(_localizer!["sa_admin_vote_menu_title", question]);

for (int i = 2; i <= answersCount - 1; i++)
{
voteAnswers.Add(command.GetArg(i), 0);
voteMenu.AddMenuOption(command.GetArg(i), Helper.HandleVotes);
}

foreach (CCSPlayerController _player in Helper.GetValidPlayers())
{
using (new WithTemporaryCulture(_player.GetLanguage()))
{
ChatMenu voteMenu = new(_localizer!["sa_admin_vote_menu_title", question]);

for (int i = 2; i <= answersCount - 1; i++)
{
voteMenu.AddMenuOption(command.GetArg(i), Helper.HandleVotes);
}

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);
}

voteInProgress = true;
Expand Down Expand Up @@ -84,7 +91,6 @@ public void OnVoteCommand(CCSPlayerController? caller, CommandInfo command)
}
}
voteAnswers.Clear();
votePlayers.Clear();
voteInProgress = false;
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
Expand Down
Loading

0 comments on commit 5bf966f

Please sign in to comment.