huge modification

- modified respawn, now the players need to respawn
- added stealth command as hide, removed the team selection menu (from CSS discord)
- removed silentmode
- added discord webhook logging system (need to set in config -DiscordWebhook and edit Version to 4)

in the future, need to add every color to replace thing and maybe need to remove those replace messages and add to sendwebhook but not yet.
This commit is contained in:
originalaidn
2024-01-31 11:17:12 +01:00
parent e028bef5b0
commit dd7a2f4c16
3 changed files with 247 additions and 27 deletions

View File

@@ -8,6 +8,7 @@ using CounterStrikeSharp.API.Modules.Commands.Targeting;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using CounterStrikeSharp.API.Modules.Menu;
using CounterStrikeSharp.API.Modules.Utils;
using Microsoft.Extensions.Localization;
@@ -36,7 +37,9 @@ 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";
public override string ModuleVersion => "1.2.8d";
public override string ModuleVersion => "1.2.9d";
private MemoryFunctionVoid<CBasePlayerController, CCSPlayerPawn, bool, bool>? CBasePlayerController_SetPawnFunc;
public CS2_SimpleAdminConfig Config { get; set; } = new();
@@ -48,6 +51,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{
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)
@@ -260,25 +265,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
command.ReplyToCommand("Reloaded sql admins");
}
[ConsoleCommand("css_silentmode")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
[RequiresPermissions("@css/kick")]
public void OnSilentModeCommand(CCSPlayerController? caller, CommandInfo command)
{
if (caller == null || caller.UserId == null) return;
if (silentPlayers.Contains((ushort)caller.UserId))
{
silentPlayers.Remove((ushort)caller.UserId);
command.ReplyToCommand("SilentMode Deactivated");
}
else
{
silentPlayers.Add((ushort)caller.UserId);
command.ReplyToCommand("SilentMode Activated");
}
}
[ConsoleCommand("css_stealth")]
[ConsoleCommand("css_hide")]
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
[RequiresPermissions("@css/kick")]
@@ -286,11 +273,32 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{
if (caller == null) return;
caller.PlayerPawn.Value!.CommitSuicide(true, false);
caller.ChangeTeam(CsTeam.Spectator);
AddTimer(1.0f, () => { caller.ChangeTeam(CsTeam.None); });
command.ReplyToCommand("You are hidden now");
if (silentPlayers.Contains((ushort)caller.UserId))
{
silentPlayers.Remove((ushort)caller.UserId);
caller.ChangeTeam(CsTeam.Spectator);
caller.PrintToChat($"You aren't hidden now!");
if(Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"{caller.PlayerName} isn't hidden now.");
}
else
{
silentPlayers.Add((ushort)caller.UserId);
Server.ExecuteCommand("sv_disable_teamselect_menu 1");
Server.NextFrame(() =>
{
caller.PlayerPawn.Value.CommitSuicide(true, false);
AddTimer(1.0f, () => { caller.ChangeTeam(CsTeam.Spectator); });
AddTimer(1.1f, () => { caller.ChangeTeam(CsTeam.None); });
caller.PrintToChat($"You are hidden now!");
if(Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"{caller.PlayerName} is hidden now.");
});
Server.NextFrame(() =>
{
AddTimer(2.0f, () => { Server.ExecuteCommand("sv_disable_teamselect_menu 0"); });
});
}
}
[ConsoleCommand("css_who")]
@@ -456,6 +464,12 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
sb.Append(_localizer["sa_admin_kick_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString());
}
if(Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_kick_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
}
});
}
@@ -544,6 +558,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_gag_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
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
@@ -555,6 +574,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_gag_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
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("", ""));
}
}
}
}
@@ -616,6 +640,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_gag_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
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
@@ -627,6 +656,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_gag_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
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("", ""));
}
}
}
@@ -762,6 +796,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
});
command.ReplyToCommand($"Ungaged player with pattern {pattern}.");
if(Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"Ungaged player with pattern {pattern}.");
return;
}
}
@@ -853,6 +889,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_mute_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
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
@@ -864,6 +905,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_mute_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
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("", ""));
}
}
}
}
@@ -925,6 +971,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_mute_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
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
@@ -936,6 +987,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_mute_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
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("", ""));
}
}
}
@@ -1070,6 +1126,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
});
command.ReplyToCommand($"Unmuted player with pattern {pattern}.");
if(Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"Unmuted player with pattern {pattern}.");
return;
}
}
@@ -1141,6 +1199,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
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
@@ -1152,6 +1215,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
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("", ""));
}
}
}
}
@@ -1216,6 +1284,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
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
@@ -1227,6 +1300,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
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("", ""));
}
}
}
}
@@ -1296,6 +1374,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
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
@@ -1307,6 +1390,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
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("", ""));
}
}
}
@@ -1340,6 +1428,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
_ = _banManager.UnbanPlayer(pattern);
command.ReplyToCommand($"Unbanned player with pattern {pattern}.");
if(Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"Unbanned player with pattern {pattern}.");
}
[ConsoleCommand("css_slay")]
@@ -1360,6 +1450,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_slay_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
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("", ""));
}
}
});
}
@@ -1408,6 +1503,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_give_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, weaponName]);
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("", ""));
}
}
});
}
@@ -1433,6 +1533,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{
sb.Append(_localizer["sa_admin_strip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
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("", ""));
}
}
}
});
@@ -1462,6 +1567,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{
sb.Append(_localizer["sa_admin_hp_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
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("", ""));
}
}
}
});
@@ -1495,6 +1605,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{
sb.Append(_localizer["sa_admin_speed_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
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("", ""));
}
}
}
});
@@ -1526,6 +1641,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{
sb.Append(_localizer["sa_admin_god_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
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("", ""));
}
}
}
}
@@ -1559,6 +1679,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{
sb.Append(_localizer["sa_admin_slap_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
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("", ""));
}
}
}
});
@@ -1633,6 +1758,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_team_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, _teamName]);
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("", ""));
}
}
});
}
@@ -1664,6 +1794,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]);
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;
@@ -1679,12 +1814,22 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_vote_message_results", question]);
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)
{
sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_vote_message_results_answer", kvp.Key, kvp.Value]);
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();
voteInProgress = false;
@@ -1730,6 +1875,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map]);
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:"))
@@ -1765,6 +1915,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map]);
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, () =>
@@ -1785,6 +1940,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new();
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")))
{
@@ -1805,6 +1965,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new();
sb.Append(_localizer!["sa_adminsay_prefix", utf8String]);
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.")]
@@ -1825,6 +1990,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
playersToTarget.ForEach(player =>
{
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!"));
@@ -1839,6 +2006,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
string utf8String = Encoding.UTF8.GetString(utf8BytesString);
Helper.PrintToCenterAll(Helper.ReplaceTags(utf8String));
if(Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"CSAY: {caller!.PlayerName}: {utf8String}");
}
[ConsoleCommand("css_hsay", "Say to all players (in hud).")]
@@ -1853,6 +2022,9 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
HudDestination.Alert,
Helper.ReplaceTags(utf8String),
0, 0, 0, 0);
if(Config.DiscordWebhook.Length > 0)
_ = SendWebhookMessage($"HSAY: {caller!.PlayerName}: {utf8String}");
}
[ConsoleCommand("css_noclip", "Noclip a player.")]
@@ -1874,6 +2046,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_noclip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
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("", ""));
}
}
}
});
@@ -1904,6 +2081,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_freeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
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("", ""));
}
}
}
});
@@ -1926,6 +2108,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_unfreeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
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("", ""));
}
}
});
}
@@ -1942,7 +2129,10 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{
if (caller!.CanTarget(player))
{
player!.Respawn();
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))
{
@@ -1950,6 +2140,12 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
sb.Append(_localizer["sa_admin_respawn_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
}
if(Config.DiscordWebhook.Length > 0)
{
LocalizedString localizedMessage = _localizer["sa_admin_respawn_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName];
_ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", ""));
}
}
});
}
@@ -1980,6 +2176,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
command.ReplyToCommand($"{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.")]
@@ -1991,6 +2189,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
Server.ExecuteCommand(command.ArgString);
command.ReplyToCommand($"{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)
@@ -2029,4 +2229,20 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
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);
}
}
}

View File

@@ -12,6 +12,7 @@
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.159" />
<PackageReference Include="Dapper" Version="*" />
<PackageReference Include="MySqlConnector" Version="2.3.5" />
<PackageReference Include="Newtonsoft.Json" Version="*" />
</ItemGroup>
<ItemGroup>

View File

@@ -5,7 +5,7 @@ namespace CS2_SimpleAdmin
{
public class CS2_SimpleAdminConfig : BasePluginConfig
{
public override int Version { get; set; } = 3;
public override int Version { get; set; } = 4;
[JsonPropertyName("DatabaseHost")]
public string DatabaseHost { get; set; } = "";
@@ -31,5 +31,8 @@ namespace CS2_SimpleAdmin
[JsonPropertyName("BanType")]
public int BanType { get; set; } = 1;
[JsonPropertyName("DiscordWebhook")]
public string DiscordWebhook { get; set; } = "";
}
}