Small changes

- Correct version
- null warnings
This commit is contained in:
Dawid Bepierszcz
2024-01-31 23:57:14 +01:00
parent 66f0ebe08c
commit 9acab82f86

View File

@@ -8,6 +8,7 @@ using CounterStrikeSharp.API.Modules.Commands.Targeting;
using CounterStrikeSharp.API.Modules.Cvars; using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Entities; using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Memory; using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using CounterStrikeSharp.API.Modules.Menu; using CounterStrikeSharp.API.Modules.Menu;
using CounterStrikeSharp.API.Modules.Utils; using CounterStrikeSharp.API.Modules.Utils;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
@@ -15,15 +16,12 @@ using Microsoft.Extensions.Logging;
using MySqlConnector; using MySqlConnector;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Text; using System.Text;
using CS2_SimpleAdmin.Menus;
namespace CS2_SimpleAdmin; namespace CS2_SimpleAdmin;
[MinimumApiVersion(159)] [MinimumApiVersion(159)]
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig> public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
{ {
public static CS2_SimpleAdmin Instance { get; private set; } = null;
public static IStringLocalizer? _localizer; public static IStringLocalizer? _localizer;
public static ConcurrentBag<string> gaggedPlayers = new ConcurrentBag<string>(); public static ConcurrentBag<string> gaggedPlayers = new ConcurrentBag<string>();
//public static ConcurrentBag<int> mutedPlayers = new ConcurrentBag<int>(); //public static ConcurrentBag<int> mutedPlayers = new ConcurrentBag<int>();
@@ -39,20 +37,22 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
public override string ModuleName => "CS2-SimpleAdmin"; public override string ModuleName => "CS2-SimpleAdmin";
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)"; public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
public override string ModuleAuthor => "daffyy"; public override string ModuleAuthor => "daffyy";
public override string ModuleVersion => "1.3.0"; public override string ModuleVersion => "1.2.9a";
private MemoryFunctionVoid<CBasePlayerController, CCSPlayerPawn, bool, bool>? CBasePlayerController_SetPawnFunc;
public CS2_SimpleAdminConfig Config { get; set; } = new(); public CS2_SimpleAdminConfig Config { get; set; } = new();
public override void Load(bool hotReload) public override void Load(bool hotReload)
{ {
Instance = this;
registerEvents(); registerEvents();
if (hotReload) if (hotReload)
{ {
OnMapStart(string.Empty); OnMapStart(string.Empty);
} }
CBasePlayerController_SetPawnFunc = new MemoryFunctionVoid<CBasePlayerController, CCSPlayerPawn, bool, bool>(@"\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x41\x54\x49\x89\xFC\x53\x48\x89\xF3\x48\x81\xEC\xC8\x00\x00\x00");
} }
public void OnConfigParsed(CS2_SimpleAdminConfig config) public void OnConfigParsed(CS2_SimpleAdminConfig config)
@@ -157,9 +157,9 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
_localizer = Localizer; _localizer = Localizer;
} }
[ConsoleCommand("css_adminhelp")] [ConsoleCommand("css_admin")]
[RequiresPermissions("@css/generic")] [RequiresPermissions("@css/generic")]
public void OnAdminHelpCommand(CCSPlayerController? caller, CommandInfo command) public void OnAdminCommand(CCSPlayerController? caller, CommandInfo command)
{ {
if (caller == null || !caller.IsValid) return; if (caller == null || !caller.IsValid) return;
@@ -171,16 +171,6 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
} }
} }
[ConsoleCommand("css_admin")]
[RequiresPermissions("@css/generic")]
public void OnAdminCommand(CCSPlayerController? caller, CommandInfo command)
{
if (caller == null || caller.IsValid == false)
return;
AdminMenu.OpenMenu(caller);
}
[ConsoleCommand("css_addadmin")] [ConsoleCommand("css_addadmin")]
[CommandHelper(minArgs: 4, usage: "<steamid> <name> <flags/groups> <immunity> <duration>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [CommandHelper(minArgs: 4, usage: "<steamid> <name> <flags/groups> <immunity> <duration>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
[RequiresPermissions("@css/root")] [RequiresPermissions("@css/root")]
@@ -275,37 +265,42 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
command.ReplyToCommand("Reloaded sql admins"); command.ReplyToCommand("Reloaded sql admins");
} }
[ConsoleCommand("css_silentmode")] [ConsoleCommand("css_stealth")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [ConsoleCommand("css_hide")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
[RequiresPermissions("@css/kick")] [RequiresPermissions("@css/kick")]
public void OnSilentModeCommand(CCSPlayerController? caller, CommandInfo command) public void OnHideCommand(CCSPlayerController? caller, CommandInfo command)
{ {
if (caller == null || caller.UserId == null) return; if (caller == null || caller.UserId == null) return;
if (silentPlayers.Contains((ushort)caller.UserId)) if (silentPlayers.Contains((ushort)caller.UserId))
{ {
silentPlayers.Remove((ushort)caller.UserId); silentPlayers.Remove((ushort)caller.UserId);
command.ReplyToCommand("SilentMode Deactivated"); caller.ChangeTeam(CsTeam.Spectator);
caller.PrintToChat($"You aren't hidden now!");
if (Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"{caller.PlayerName} isn't hidden now.");
} }
else else
{ {
silentPlayers.Add((ushort)caller.UserId); silentPlayers.Add((ushort)caller.UserId);
command.ReplyToCommand("SilentMode Activated"); Server.ExecuteCommand("sv_disable_teamselect_menu 1");
} Server.NextFrame(() =>
}
[ConsoleCommand("css_hide")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
[RequiresPermissions("@css/kick")]
public void OnHideCommand(CCSPlayerController? caller, CommandInfo command)
{ {
if (caller == null) return; if (caller.PlayerPawn.Value != null && caller.PawnIsAlive)
caller.PlayerPawn.Value.CommitSuicide(true, false);
caller.PlayerPawn.Value!.CommitSuicide(true, false); AddTimer(1.0f, () => { caller.ChangeTeam(CsTeam.Spectator); });
caller.ChangeTeam(CsTeam.Spectator); AddTimer(1.1f, () => { caller.ChangeTeam(CsTeam.None); });
AddTimer(1.0f, () => { caller.ChangeTeam(CsTeam.None); }); caller.PrintToChat($"You are hidden now!");
if (Config.DiscordWebhook.Length > 0)
command.ReplyToCommand("You are hidden now"); _ = SendWebhookMessage($"{caller.PlayerName} is hidden now.");
});
Server.NextFrame(() =>
{
AddTimer(1.25f, () => { Server.ExecuteCommand("sv_disable_teamselect_menu 0"); });
});
}
} }
[ConsoleCommand("css_who")] [ConsoleCommand("css_who")]
@@ -317,23 +312,13 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
if (targets == null) return; if (targets == null) return;
List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => caller!.CanTarget(player) && player != null && player.IsValid && !player.IsBot && !player.IsHLTV).ToList(); List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => caller!.CanTarget(player) && player != null && player.IsValid && !player.IsBot && !player.IsHLTV).ToList();
BanManager banManager = new(dbConnectionString, Config); BanManager _banManager = new(dbConnectionString, Config);
MuteManager muteManager = new(dbConnectionString); MuteManager _muteManager = new(dbConnectionString);
playersToTarget.ForEach(player => playersToTarget.ForEach(player =>
{ {
if (caller!.CanTarget(player)) if (caller!.CanTarget(player))
{ {
Who(caller, player, banManager, muteManager);
}
});
}
public void Who(CCSPlayerController? caller, CCSPlayerController player, BanManager banManager = null, MuteManager muteManager = null)
{
banManager ??= new(dbConnectionString, Config);
muteManager ??= new(dbConnectionString);
PlayerInfo playerInfo = new PlayerInfo PlayerInfo playerInfo = new PlayerInfo
{ {
UserId = player.UserId, UserId = player.UserId,
@@ -348,37 +333,64 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
int totalBans = 0; int totalBans = 0;
int totalMutes = 0; int totalMutes = 0;
totalBans = await banManager.GetPlayerBans(playerInfo); totalBans = await _banManager.GetPlayerBans(playerInfo);
totalMutes = await muteManager.GetPlayerMutes(playerInfo.SteamId!); totalMutes = await _muteManager.GetPlayerMutes(playerInfo.SteamId!);
Server.NextFrame(() => Server.NextFrame(() =>
{ {
Action<string> printMethod = caller == null ? Server.PrintToConsole : caller.PrintToConsole; if (caller != null)
printMethod($"--------- INFO ABOUT \"{playerInfo.Name}\" ---------"); {
caller!.PrintToConsole($"--------- INFO ABOUT \"{playerInfo.Name}\" ---------");
printMethod($"• Clan: \"{player!.Clan}\" Name: \"{playerInfo.Name}\""); caller!.PrintToConsole($"• Clan: \"{player!.Clan}\" Name: \"{playerInfo.Name}\"");
printMethod($"• UserID: \"{playerInfo.UserId}\""); caller!.PrintToConsole($"• UserID: \"{playerInfo.UserId}\"");
if (playerInfo.SteamId != null) if (playerInfo.SteamId != null)
printMethod($"• SteamID64: \"{playerInfo.SteamId}\""); caller!.PrintToConsole($"• SteamID64: \"{playerInfo.SteamId}\"");
if (player.AuthorizedSteamID != null) if (player.AuthorizedSteamID != null)
{ {
printMethod($"• SteamID2: \"{player.AuthorizedSteamID.SteamId2}\""); caller!.PrintToConsole($"• SteamID2: \"{player.AuthorizedSteamID.SteamId2}\"");
printMethod($"• Community link: \"{player.AuthorizedSteamID.ToCommunityUrl()}\""); caller!.PrintToConsole($"• Community link: \"{player.AuthorizedSteamID.ToCommunityUrl()}\"");
} }
if (playerInfo.IpAddress != null) if (playerInfo.IpAddress != null)
printMethod($"• IP Address: \"{playerInfo.IpAddress}\""); caller!.PrintToConsole($"• IP Address: \"{playerInfo.IpAddress}\"");
printMethod($"• Ping: \"{player.Ping}\""); caller!.PrintToConsole($"• Ping: \"{player.Ping}\"");
if (player.AuthorizedSteamID != null) if (player.AuthorizedSteamID != null)
{ {
printMethod($"• Total Bans: \"{totalBans}\""); caller!.PrintToConsole($"• Total Bans: \"{totalBans}\"");
printMethod($"• Total Mutes: \"{totalMutes}\""); caller!.PrintToConsole($"• Total Mutes: \"{totalMutes}\"");
} }
printMethod($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------"); caller!.PrintToConsole($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------");
}
else
{
Server.PrintToConsole($"--------- INFO ABOUT \"{playerInfo.Name}\" ---------");
Server.PrintToConsole($"• Clan: \"{player!.Clan}\" Name: \"{playerInfo.Name}\"");
Server.PrintToConsole($"• UserID: \"{playerInfo.UserId}\"");
if (playerInfo.SteamId != null)
Server.PrintToConsole($"• SteamID64: \"{playerInfo.SteamId}\"");
if (player.AuthorizedSteamID != null)
{
Server.PrintToConsole($"• SteamID2: \"{player.AuthorizedSteamID.SteamId2}\"");
Server.PrintToConsole($"• Community link: \"{player.AuthorizedSteamID.ToCommunityUrl()}\"");
}
if (playerInfo.IpAddress != null)
Server.PrintToConsole($"• IP Address: \"{playerInfo.IpAddress}\"");
Server.PrintToConsole($"• Ping: \"{player.Ping}\"");
if (player.AuthorizedSteamID != null)
{
Server.PrintToConsole($"• Total Bans: \"{totalBans}\"");
Server.PrintToConsole($"• Total Mutes: \"{totalMutes}\"");
}
Server.PrintToConsole($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------");
}
}); });
}); });
} }
});
}
[ConsoleCommand("css_players")] [ConsoleCommand("css_players")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
@@ -414,7 +426,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
[CommandHelper(minArgs: 1, usage: "<#userid or name> [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [CommandHelper(minArgs: 1, usage: "<#userid or name> [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
public void OnKickCommand(CCSPlayerController? caller, CommandInfo command) public void OnKickCommand(CCSPlayerController? caller, CommandInfo command)
{ {
string reason = null; string reason = "Unknown";
TargetResult? targets = GetTarget(command); TargetResult? targets = GetTarget(command);
if (targets == null) return; if (targets == null) return;
@@ -431,13 +443,6 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
targets.Players.ForEach(player => targets.Players.ForEach(player =>
{ {
if (caller!.CanTarget(player)) if (caller!.CanTarget(player))
{
Kick(caller, player, reason);
}
});
}
public void Kick(CCSPlayerController? caller, CCSPlayerController player, string reason = null)
{ {
if (player.PawnIsAlive) if (player.PawnIsAlive)
{ {
@@ -445,7 +450,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
player.CommitSuicide(true, true); player.CommitSuicide(true, true);
} }
if (string.IsNullOrEmpty(reason) == false) if (command.ArgCount >= 2)
{ {
player.PrintToCenter(_localizer!["sa_player_kick_message", reason, caller == null ? "Console" : caller.PlayerName]); player.PrintToCenter(_localizer!["sa_player_kick_message", reason, caller == null ? "Console" : caller.PlayerName]);
AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!, reason)); AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!, reason));
@@ -461,6 +466,14 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
sb.Append(_localizer["sa_admin_kick_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); sb.Append(_localizer["sa_admin_kick_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
} }
if (Config.DiscordWebhook.Length > 0 && _localizer != null)
{
LocalizedString localizedMessage = _localizer["sa_admin_kick_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
}
});
} }
[ConsoleCommand("css_gag")] [ConsoleCommand("css_gag")]
@@ -469,7 +482,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
public void OnGagCommand(CCSPlayerController? caller, CommandInfo command) public void OnGagCommand(CCSPlayerController? caller, CommandInfo command)
{ {
int time = 0; int time = 0;
string reason = null; string reason = "Unknown";
TargetResult? targets = GetTarget(command); TargetResult? targets = GetTarget(command);
if (targets == null) return; if (targets == null) return;
@@ -491,16 +504,6 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{ {
if (caller!.CanTarget(player)) if (caller!.CanTarget(player))
{ {
Gag(caller, player, time, reason, _muteManager);
}
});
}
public void Gag(CCSPlayerController? caller, CCSPlayerController player, int time, string reason = null, MuteManager muteManager = null)
{
reason ??= "Unknown";
muteManager ??= new(dbConnectionString);
PlayerInfo playerInfo = new PlayerInfo PlayerInfo playerInfo = new PlayerInfo
{ {
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(), SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
@@ -517,7 +520,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
Task.Run(async () => Task.Run(async () =>
{ {
await muteManager.MutePlayer(playerInfo, adminInfo, reason, time); await _muteManager.MutePlayer(playerInfo, adminInfo, reason, time);
}); });
if (TagsDetected) if (TagsDetected)
@@ -557,6 +560,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_gag_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); sb.Append(_localizer["sa_admin_gag_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_gag_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
else else
@@ -568,9 +576,16 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_gag_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); sb.Append(_localizer["sa_admin_gag_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_gag_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
} }
} }
} }
}
});
}
[ConsoleCommand("css_addgag")] [ConsoleCommand("css_addgag")]
[RequiresPermissions("@css/chat")] [RequiresPermissions("@css/chat")]
@@ -627,6 +642,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_gag_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); sb.Append(_localizer["sa_admin_gag_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_gag_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
else else
@@ -638,6 +658,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_gag_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); sb.Append(_localizer["sa_admin_gag_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_gag_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
@@ -773,6 +798,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
}); });
command.ReplyToCommand($"Ungaged player with pattern {pattern}."); command.ReplyToCommand($"Ungaged player with pattern {pattern}.");
if (Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"Ungaged player with pattern {pattern}.");
return; return;
} }
} }
@@ -783,7 +810,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
public void OnMuteCommand(CCSPlayerController? caller, CommandInfo command) public void OnMuteCommand(CCSPlayerController? caller, CommandInfo command)
{ {
int time = 0; int time = 0;
string reason = null; string reason = "Unknown";
TargetResult? targets = GetTarget(command); TargetResult? targets = GetTarget(command);
if (targets == null) return; if (targets == null) return;
@@ -805,16 +832,6 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{ {
if (caller!.CanTarget(player)) if (caller!.CanTarget(player))
{ {
Mute(caller, player, time, reason, _muteManager);
}
});
}
public void Mute(CCSPlayerController? caller, CCSPlayerController player, int time, string reason = null, MuteManager muteManager = null)
{
reason ??= "Unknown";
muteManager ??= new(dbConnectionString);
PlayerInfo playerInfo = new PlayerInfo PlayerInfo playerInfo = new PlayerInfo
{ {
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(), SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
@@ -836,15 +853,17 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
player!.VoiceFlags = VoiceFlags.Muted; player!.VoiceFlags = VoiceFlags.Muted;
Task.Run(async () => { await muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 1); }); Task.Run(async () =>
{
await _muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 1);
});
if (time > 0 && time <= 30) if (time > 0 && time <= 30)
{ {
AddTimer(time * 60, () => AddTimer(time * 60, () =>
{ {
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
return;
//MuteManager _muteManager = new(dbConnectionString); //MuteManager _muteManager = new(dbConnectionString);
//_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 1); //_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 1);
@@ -872,6 +891,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_mute_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); sb.Append(_localizer["sa_admin_mute_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_mute_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
else else
@@ -883,9 +907,16 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_mute_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); sb.Append(_localizer["sa_admin_mute_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_mute_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
} }
} }
} }
}
});
}
[ConsoleCommand("css_addmute")] [ConsoleCommand("css_addmute")]
[RequiresPermissions("@css/chat")] [RequiresPermissions("@css/chat")]
@@ -942,6 +973,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_mute_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); sb.Append(_localizer["sa_admin_mute_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_mute_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
else else
@@ -953,6 +989,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_mute_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); sb.Append(_localizer["sa_admin_mute_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_mute_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
@@ -1087,6 +1128,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
}); });
command.ReplyToCommand($"Unmuted player with pattern {pattern}."); command.ReplyToCommand($"Unmuted player with pattern {pattern}.");
if (Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"Unmuted player with pattern {pattern}.");
return; return;
} }
} }
@@ -1122,16 +1165,6 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{ {
if (caller!.CanTarget(player)) if (caller!.CanTarget(player))
{ {
Ban(caller, player, time, reason, _banManager);
}
});
}
public void Ban(CCSPlayerController? caller, CCSPlayerController player, int time, string reason = null, BanManager banManager = null)
{
reason ??= "Unknown";
banManager ??= new(dbConnectionString, Config);
if (player.PawnIsAlive) if (player.PawnIsAlive)
{ {
player.Pawn.Value!.Freeze(); player.Pawn.Value!.Freeze();
@@ -1154,7 +1187,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
Task.Run(async () => Task.Run(async () =>
{ {
await banManager.BanPlayer(playerInfo, adminInfo, reason, time); await _banManager.BanPlayer(playerInfo, adminInfo, reason, time);
}); });
AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player!.UserId!)); AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player!.UserId!));
@@ -1168,6 +1201,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
else else
@@ -1179,9 +1217,16 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
} }
} }
} }
}
});
}
[ConsoleCommand("css_addban")] [ConsoleCommand("css_addban")]
[RequiresPermissions("@css/ban")] [RequiresPermissions("@css/ban")]
@@ -1241,6 +1286,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
else else
@@ -1252,6 +1302,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
} }
@@ -1321,6 +1376,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
else else
@@ -1332,6 +1392,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
@@ -1365,6 +1430,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
_ = _banManager.UnbanPlayer(pattern); _ = _banManager.UnbanPlayer(pattern);
command.ReplyToCommand($"Unbanned player with pattern {pattern}."); command.ReplyToCommand($"Unbanned player with pattern {pattern}.");
if (Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"Unbanned player with pattern {pattern}.");
} }
[ConsoleCommand("css_slay")] [ConsoleCommand("css_slay")]
@@ -1377,12 +1444,6 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => caller!.CanTarget(player) && player != null && player.IsValid && player.PawnIsAlive).ToList(); List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => caller!.CanTarget(player) && player != null && player.IsValid && player.PawnIsAlive).ToList();
playersToTarget.ForEach(player => playersToTarget.ForEach(player =>
{
Slay(caller, player);
});
}
public void Slay(CCSPlayerController? caller, CCSPlayerController player)
{ {
player.CommitSuicide(false, true); player.CommitSuicide(false, true);
@@ -1391,8 +1452,14 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_slay_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); sb.Append(_localizer["sa_admin_slay_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_slay_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
} }
} }
});
}
[ConsoleCommand("css_give")] [ConsoleCommand("css_give")]
[RequiresPermissions("@css/cheats")] [RequiresPermissions("@css/cheats")]
@@ -1438,6 +1505,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_give_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, weaponName]); sb.Append(_localizer["sa_admin_give_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, weaponName]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_give_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, weaponName];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
}); });
} }
@@ -1463,6 +1535,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{ {
sb.Append(_localizer["sa_admin_strip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); sb.Append(_localizer["sa_admin_strip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_strip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
}); });
@@ -1492,6 +1569,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{ {
sb.Append(_localizer["sa_admin_hp_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); sb.Append(_localizer["sa_admin_hp_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_hp_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
}); });
@@ -1525,6 +1607,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{ {
sb.Append(_localizer["sa_admin_speed_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); sb.Append(_localizer["sa_admin_speed_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_speed_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
}); });
@@ -1556,6 +1643,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{ {
sb.Append(_localizer["sa_admin_god_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); sb.Append(_localizer["sa_admin_god_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_god_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
} }
@@ -1582,22 +1674,22 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{ {
if (caller!.CanTarget(player)) if (caller!.CanTarget(player))
{ {
Slap(caller, player, damage); player!.Pawn.Value!.Slap(damage);
}
});
}
public void Slap(CCSPlayerController? caller, CCSPlayerController player, int damage)
{
player.Pawn.Value!.Slap(damage);
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
if (caller == null || caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId)) if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{ {
sb.Append(_localizer["sa_admin_slap_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); sb.Append(_localizer["sa_admin_slap_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_slap_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
} }
} }
}
});
}
[ConsoleCommand("css_team")] [ConsoleCommand("css_team")]
[RequiresPermissions("@css/kick")] [RequiresPermissions("@css/kick")]
@@ -1637,19 +1729,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
break; break;
} }
bool kill = command.GetArg(3)?.ToLower().Equals("-k") ?? false;
playersToTarget.ForEach(player => playersToTarget.ForEach(player =>
{
ChangeTeam(caller, player, _teamName, teamNum, kill);
});
}
public void ChangeTeam(CCSPlayerController? caller, CCSPlayerController player, string teamName, CsTeam teamNum, bool kill)
{ {
if (!teamName.Equals("swap")) if (!teamName.Equals("swap"))
{ {
if (player.PawnIsAlive && teamNum != CsTeam.Spectator && !kill) if (player.PawnIsAlive && teamNum != CsTeam.Spectator && !command.GetArg(3).ToLower().Equals("-k"))
player.SwitchTeam(teamNum); player.SwitchTeam(teamNum);
else else
player.ChangeTeam(teamNum); player.ChangeTeam(teamNum);
@@ -1658,9 +1742,9 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{ {
if (player.TeamNum != (byte)CsTeam.Spectator) if (player.TeamNum != (byte)CsTeam.Spectator)
{ {
teamNum = (CsTeam)player.TeamNum == CsTeam.Terrorist ? CsTeam.CounterTerrorist : CsTeam.Terrorist; CsTeam teamNum = (CsTeam)player.TeamNum == CsTeam.Terrorist ? CsTeam.CounterTerrorist : CsTeam.Terrorist;
teamName = teamNum == CsTeam.Terrorist ? "TT" : "CT"; _teamName = teamNum == CsTeam.Terrorist ? "TT" : "CT";
if (player.PawnIsAlive && !kill) if (player.PawnIsAlive && !command.GetArg(3).ToLower().Equals("-k"))
{ {
player.SwitchTeam(teamNum); player.SwitchTeam(teamNum);
} }
@@ -1674,10 +1758,16 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId)) if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{ {
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_team_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, teamName]); sb.Append(_localizer["sa_admin_team_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, _teamName]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_team_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, _teamName];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
} }
} }
});
}
[ConsoleCommand("css_vote")] [ConsoleCommand("css_vote")]
[RequiresPermissions("@css/generic")] [RequiresPermissions("@css/generic")]
@@ -1706,6 +1796,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]); sb.Append(_localizer["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
voteInProgress = true; voteInProgress = true;
@@ -1721,12 +1816,22 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_vote_message_results", question]); sb.Append(_localizer["sa_admin_vote_message_results", question]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_vote_message_results", question];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
foreach (KeyValuePair<string, int> kvp in voteAnswers) foreach (KeyValuePair<string, int> kvp in voteAnswers)
{ {
sb = new(_localizer!["sa_prefix"]); sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_vote_message_results_answer", kvp.Key, kvp.Value]); sb.Append(_localizer["sa_admin_vote_message_results_answer", kvp.Key, kvp.Value]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_vote_message_results_answer", kvp.Key, kvp.Value];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
voteAnswers.Clear(); voteAnswers.Clear();
voteInProgress = false; voteInProgress = false;
@@ -1772,6 +1877,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map]); sb.Append(_localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
if (!map.StartsWith("ws:")) if (!map.StartsWith("ws:"))
@@ -1807,6 +1917,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map]); sb.Append(_localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
AddTimer(2.0f, () => AddTimer(2.0f, () =>
@@ -1827,6 +1942,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(); StringBuilder sb = new();
sb.Append(_localizer!["sa_adminchat_template_admin", caller == null ? "Console" : caller.PlayerName, utf8String]); sb.Append(_localizer!["sa_adminchat_template_admin", caller == null ? "Console" : caller.PlayerName, utf8String]);
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_adminchat_template_admin", caller == null ? "Console" : caller.PlayerName, utf8String];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
foreach (var p in Utilities.GetPlayers().Where(p => p.IsValid && !p.IsBot && !p.IsHLTV && AdminManager.PlayerHasPermissions(p, "@css/chat"))) foreach (var p in Utilities.GetPlayers().Where(p => p.IsValid && !p.IsBot && !p.IsHLTV && AdminManager.PlayerHasPermissions(p, "@css/chat")))
{ {
@@ -1847,6 +1967,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(); StringBuilder sb = new();
sb.Append(_localizer!["sa_adminsay_prefix", utf8String]); sb.Append(_localizer!["sa_adminsay_prefix", utf8String]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_adminsay_prefix", utf8String];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
[ConsoleCommand("css_psay", "Private message a player.")] [ConsoleCommand("css_psay", "Private message a player.")]
@@ -1867,6 +1992,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
playersToTarget.ForEach(player => playersToTarget.ForEach(player =>
{ {
player.PrintToChat(Helper.ReplaceTags($"({caller!.PlayerName}) {utf8String}")); player.PrintToChat(Helper.ReplaceTags($"({caller!.PlayerName}) {utf8String}"));
if (Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"PSAY: {caller!.PlayerName} --> {player!.PlayerName}: {utf8String}");
}); });
command.ReplyToCommand(Helper.ReplaceTags($" Private message sent!")); command.ReplyToCommand(Helper.ReplaceTags($" Private message sent!"));
@@ -1881,6 +2008,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
string utf8String = Encoding.UTF8.GetString(utf8BytesString); string utf8String = Encoding.UTF8.GetString(utf8BytesString);
Helper.PrintToCenterAll(Helper.ReplaceTags(utf8String)); Helper.PrintToCenterAll(Helper.ReplaceTags(utf8String));
if (Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"CSAY: {caller!.PlayerName}: {utf8String}");
} }
[ConsoleCommand("css_hsay", "Say to all players (in hud).")] [ConsoleCommand("css_hsay", "Say to all players (in hud).")]
@@ -1895,6 +2024,9 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
HudDestination.Alert, HudDestination.Alert,
Helper.ReplaceTags(utf8String), Helper.ReplaceTags(utf8String),
0, 0, 0, 0); 0, 0, 0, 0);
if (Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"HSAY: {caller!.PlayerName}: {utf8String}");
} }
[ConsoleCommand("css_noclip", "Noclip a player.")] [ConsoleCommand("css_noclip", "Noclip a player.")]
@@ -1916,6 +2048,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_noclip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); sb.Append(_localizer["sa_admin_noclip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_noclip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
}); });
@@ -1946,6 +2083,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_freeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); sb.Append(_localizer["sa_admin_freeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_freeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
} }
}); });
@@ -1968,6 +2110,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]); StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_unfreeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); sb.Append(_localizer["sa_admin_unfreeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
if (Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_unfreeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
}); });
} }
@@ -1984,7 +2131,12 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{ {
if (caller!.CanTarget(player)) if (caller!.CanTarget(player))
{ {
player!.Respawn(); if (CBasePlayerController_SetPawnFunc == null || player.PlayerPawn.Value == null || !player.PlayerPawn.IsValid) return;
var playerPawn = player.PlayerPawn.Value;
CBasePlayerController_SetPawnFunc.Invoke(player, playerPawn, true, false);
VirtualFunction.CreateVoid<CCSPlayerController>(player.Handle,
GameData.GetOffset("CCSPlayerController_Respawn"))(player);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId)) if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{ {
@@ -1992,6 +2144,12 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
sb.Append(_localizer["sa_admin_respawn_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); sb.Append(_localizer["sa_admin_respawn_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString()); Server.PrintToChatAll(sb.ToString());
} }
if (Config.DiscordWebhook.Length > 0 && _localizer != null)
{
LocalizedString localizedMessage = _localizer["sa_admin_respawn_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
} }
}); });
} }
@@ -2022,6 +2180,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
command.ReplyToCommand($"{playerName} changed cvar {cvar.Name} to {value}."); command.ReplyToCommand($"{playerName} changed cvar {cvar.Name} to {value}.");
Logger.LogInformation($"{playerName} changed cvar {cvar.Name} to {value}."); Logger.LogInformation($"{playerName} changed cvar {cvar.Name} to {value}.");
if (Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"{playerName} changed cvar {cvar.Name} to {value}.");
} }
[ConsoleCommand("css_rcon", "Run a server console command.")] [ConsoleCommand("css_rcon", "Run a server console command.")]
@@ -2033,6 +2193,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
Server.ExecuteCommand(command.ArgString); Server.ExecuteCommand(command.ArgString);
command.ReplyToCommand($"{playerName} executed command {command.ArgString}."); command.ReplyToCommand($"{playerName} executed command {command.ArgString}.");
Logger.LogInformation($"{playerName} executed command ({command.ArgString})."); Logger.LogInformation($"{playerName} executed command ({command.ArgString}).");
if (Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"{playerName} executed command ({command.ArgString}).");
} }
private static TargetResult? GetTarget(CommandInfo command) private static TargetResult? GetTarget(CommandInfo command)
@@ -2053,22 +2215,21 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
command.ReplyToCommand($"Multiple targets found for \"{command.GetArg(1)}\"."); command.ReplyToCommand($"Multiple targets found for \"{command.GetArg(1)}\".");
return null; return null;
/*
var matches = Helper.GetTarget(command.GetArg(1), out player);
switch (matches)
{
case TargetResult.None:
command.ReplyToCommand($"Target {command.GetArg(1)} not found.");
return false;
case TargetResult.Multiple:
command.ReplyToCommand($"Multiple targets found for \"{command.GetArg(1)}\".");
return false;
} }
return true; public async Task SendWebhookMessage(string message)
*/ {
using (var httpClient = new HttpClient())
{
var payload = new
{
content = message
};
var jsonPayload = Newtonsoft.Json.JsonConvert.SerializeObject(payload);
var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync(Config.DiscordWebhook, content);
}
} }
} }