mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-17 18:39:07 +00:00
Admin immunity + Discord
- Fixed command logging + small refactor - Fixed admin immunity - Separated penalty webhook - More customizable penalty webhook
This commit is contained in:
@@ -27,10 +27,10 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
private static bool _tagsDetected;
|
||||
public static bool VoteInProgress = false;
|
||||
public static int? ServerId = null;
|
||||
public static bool UnlockedCommands = CoreConfig.UnlockConCommands;
|
||||
private static readonly bool UnlockedCommands = CoreConfig.UnlockConCommands;
|
||||
|
||||
public static DiscordWebhookClient? DiscordWebhookClientLog;
|
||||
public static DiscordWebhookClient? DiscordWebhookClientPenalty;
|
||||
// public static DiscordWebhookClient? DiscordWebhookClientPenalty;
|
||||
|
||||
private string _dbConnectionString = string.Empty;
|
||||
private static Database.Database? _database;
|
||||
@@ -120,8 +120,10 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
|
||||
if (!string.IsNullOrEmpty(Config.Discord.DiscordLogWebhook))
|
||||
DiscordWebhookClientLog = new DiscordWebhookClient(Config.Discord.DiscordLogWebhook);
|
||||
/*
|
||||
if (!string.IsNullOrEmpty(Config.Discord.DiscordPenaltyWebhook))
|
||||
DiscordWebhookClientPenalty = new DiscordWebhookClient(Config.Discord.DiscordPenaltyWebhook);
|
||||
*/
|
||||
|
||||
PluginInfo.ShowAd(ModuleVersion);
|
||||
if (Config.EnableUpdateCheck)
|
||||
|
||||
@@ -52,7 +52,6 @@ namespace CS2_SimpleAdmin
|
||||
if (_database == null || player is null || !player.IsValid) return;
|
||||
if (!caller.CanTarget(player)) return;
|
||||
|
||||
|
||||
if (CheckValidBan(caller, time) == false)
|
||||
return;
|
||||
|
||||
@@ -139,11 +138,10 @@ namespace CS2_SimpleAdmin
|
||||
Server.ExecuteCommand($"banid 2 {new SteamID(player.SteamID).SteamId3}");
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
}
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Ban, DiscordWebhookClientPenalty, _localizer);
|
||||
|
||||
Helper.LogCommand(caller, $"css_ban {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)} {time} {reason}");
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Ban, _localizer);
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_addban")]
|
||||
@@ -244,7 +242,7 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
}
|
||||
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Ban, DiscordWebhookClientPenalty, _localizer);
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Ban, _localizer);
|
||||
}
|
||||
|
||||
Task.Run(async () =>
|
||||
@@ -254,7 +252,6 @@ namespace CS2_SimpleAdmin
|
||||
});
|
||||
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
//Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Ban, _discordWebhookClientPenalty, _localizer);
|
||||
if (UnlockedCommands)
|
||||
Server.ExecuteCommand($"banid 2 {steamId.SteamId3}");
|
||||
@@ -282,8 +279,6 @@ namespace CS2_SimpleAdmin
|
||||
return;
|
||||
}
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
|
||||
var reason = _localizer?["sa_unknown"] ?? "Unknown";
|
||||
|
||||
var adminInfo = new PlayerInfo
|
||||
@@ -365,7 +360,8 @@ namespace CS2_SimpleAdmin
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
}
|
||||
}
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Ban, DiscordWebhookClientPenalty, _localizer);
|
||||
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Ban, _localizer);
|
||||
}
|
||||
|
||||
Task.Run(async () =>
|
||||
@@ -375,7 +371,6 @@ namespace CS2_SimpleAdmin
|
||||
});
|
||||
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
|
||||
command.ReplyToCommand($"Banned player with IP address {ipAddress}.");
|
||||
}
|
||||
@@ -422,7 +417,6 @@ namespace CS2_SimpleAdmin
|
||||
BanManager banManager = new(_database, Config);
|
||||
Task.Run(async () => await banManager.UnbanPlayer(pattern, callerSteamId, reason));
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
command.ReplyToCommand($"Unbanned player with pattern {pattern}.");
|
||||
|
||||
@@ -18,7 +18,6 @@ namespace CS2_SimpleAdmin
|
||||
{
|
||||
if (caller == null || !caller.IsValid || command.GetCommandString[command.GetCommandString.IndexOf(' ')..].Length == 0) return;
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
var utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]);
|
||||
@@ -45,7 +44,6 @@ namespace CS2_SimpleAdmin
|
||||
var utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]);
|
||||
var utf8String = Encoding.UTF8.GetString(utf8BytesString);
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
foreach (var player in Helper.GetValidPlayers())
|
||||
@@ -92,7 +90,6 @@ namespace CS2_SimpleAdmin
|
||||
var utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]);
|
||||
var utf8String = Encoding.UTF8.GetString(utf8BytesString);
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
Helper.PrintToCenterAll(utf8String.ReplaceColorTags());
|
||||
@@ -106,7 +103,6 @@ namespace CS2_SimpleAdmin
|
||||
var utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]);
|
||||
var utf8String = Encoding.UTF8.GetString(utf8BytesString);
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
VirtualFunctions.ClientPrintAll(
|
||||
|
||||
@@ -135,8 +135,6 @@ namespace CS2_SimpleAdmin
|
||||
var flagsList = flags.Split(',').Select(flag => flag.Trim()).ToList();
|
||||
_ = adminManager.AddAdminBySteamId(steamid, name, flagsList, immunity, time, globalAdmin);
|
||||
|
||||
if (command != null)
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, $"css_addadmin {steamid} {name} {flags} {immunity} {time}");
|
||||
|
||||
var msg = $"Added '{flags}' flags to '{name}' ({steamid})";
|
||||
@@ -185,8 +183,6 @@ namespace CS2_SimpleAdmin
|
||||
AdminManager.RemovePlayerAdminData(steamId);
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
|
||||
if (command != null)
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, $"css_deladmin {steamid}");
|
||||
|
||||
var msg = $"Removed flags from '{steamid}'";
|
||||
@@ -233,8 +229,6 @@ namespace CS2_SimpleAdmin
|
||||
var flagsList = flags.Split(',').Select(flag => flag.Trim()).ToList();
|
||||
_ = adminManager.AddGroup(name, flagsList, immunity, globalGroup);
|
||||
|
||||
if (command != null)
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, $"css_addgroup {name} {flags} {immunity}");
|
||||
|
||||
var msg = $"Created group '{name}' with flags '{flags}'";
|
||||
@@ -275,8 +269,6 @@ namespace CS2_SimpleAdmin
|
||||
ReloadAdmins(caller);
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
|
||||
if (command != null)
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, $"css_delgroup {name}");
|
||||
|
||||
var msg = $"Removed group '{name}'";
|
||||
@@ -348,7 +340,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
if (SilentPlayers.Contains(caller.Slot))
|
||||
if (!SilentPlayers.Add(caller.Slot))
|
||||
{
|
||||
SilentPlayers.Remove(caller.Slot);
|
||||
caller.PrintToChat($"You aren't hidden now!");
|
||||
@@ -356,7 +348,6 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
else
|
||||
{
|
||||
SilentPlayers.Add(caller.Slot);
|
||||
Server.ExecuteCommand("sv_disable_teamselect_menu 1");
|
||||
|
||||
if (caller.PlayerPawn.Value != null && caller.PawnIsAlive)
|
||||
@@ -547,24 +538,22 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
player.Pawn.Value!.Freeze();
|
||||
|
||||
if (command != null)
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, $"css_kick {player?.PlayerName} {reason}");
|
||||
Helper.LogCommand(caller, $"css_kick {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)} {reason}");
|
||||
|
||||
if (string.IsNullOrEmpty(reason) == false)
|
||||
{
|
||||
if (player != null && !player.IsBot)
|
||||
if (!player.IsBot)
|
||||
using (new WithTemporaryCulture(player.GetLanguage()))
|
||||
{
|
||||
player.PrintToCenter(_localizer!["sa_player_kick_message", reason, callerName]);
|
||||
}
|
||||
if (player != null && player.UserId.HasValue)
|
||||
if (player.UserId.HasValue)
|
||||
AddTimer(Config.KickTime, () => Helper.KickPlayer(player.UserId.Value, reason),
|
||||
CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player != null && player.UserId.HasValue)
|
||||
if (player.UserId.HasValue)
|
||||
AddTimer(Config.KickTime, () => Helper.KickPlayer(player.UserId.Value),
|
||||
CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
}
|
||||
@@ -638,9 +627,7 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
}
|
||||
|
||||
if (command == null) return;
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.LogCommand(caller, command?.GetCommandString ?? $"css_map {map}");
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_changewsmap", "Change workshop map.")]
|
||||
@@ -677,9 +664,7 @@ namespace CS2_SimpleAdmin
|
||||
Server.ExecuteCommand(issuedCommand);
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
|
||||
if (command == null) return;
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.LogCommand(caller, command?.GetCommandString ?? $"css_wsmap {map}");
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_cvar", "Change a cvar.")]
|
||||
@@ -702,7 +687,6 @@ namespace CS2_SimpleAdmin
|
||||
return;
|
||||
}
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
var value = command.GetArg(2);
|
||||
@@ -720,7 +704,6 @@ namespace CS2_SimpleAdmin
|
||||
{
|
||||
var callerName = caller == null ? "Console" : caller.PlayerName;
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
Server.ExecuteCommand(command.ArgString);
|
||||
|
||||
@@ -124,10 +124,8 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
}
|
||||
|
||||
if (command == null) return;
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Gag, DiscordWebhookClientPenalty, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.LogCommand(caller, $"css_gag {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)} {time} {reason}");
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Gag, _localizer);
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_addgag")]
|
||||
@@ -229,7 +227,7 @@ namespace CS2_SimpleAdmin
|
||||
PlayerPenaltyManager.AddPenalty(player.Slot, PenaltyType.Gag, DateTime.Now.AddMinutes(time), time);
|
||||
}
|
||||
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Gag, DiscordWebhookClientPenalty, _localizer);
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Gag, _localizer);
|
||||
}
|
||||
|
||||
Task.Run(async () =>
|
||||
@@ -237,7 +235,6 @@ namespace CS2_SimpleAdmin
|
||||
await muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time);
|
||||
});
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
command.ReplyToCommand($"Gagged player with steamid {steamid}.");
|
||||
@@ -260,13 +257,13 @@ namespace CS2_SimpleAdmin
|
||||
command.ReplyToCommand($"Too short pattern to search.");
|
||||
return;
|
||||
}
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
|
||||
var found = false;
|
||||
|
||||
var pattern = command.GetArg(1);
|
||||
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
MuteManager muteManager = new(_database);
|
||||
|
||||
if (Helper.ValidateSteamId(pattern, out var steamId) && steamId != null)
|
||||
@@ -461,13 +458,9 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Mute, DiscordWebhookClientPenalty, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
}
|
||||
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Mute, _localizer);
|
||||
Helper.LogCommand(caller, $"css_mute {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)} {time} {reason}");
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_addmute")]
|
||||
@@ -564,7 +557,7 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
}
|
||||
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Mute, DiscordWebhookClientPenalty, _localizer);
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Mute, _localizer);
|
||||
}
|
||||
|
||||
Task.Run(async () =>
|
||||
@@ -572,7 +565,6 @@ namespace CS2_SimpleAdmin
|
||||
await muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 1);
|
||||
});
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
command.ReplyToCommand($"Muted player with steamid {steamid}.");
|
||||
@@ -596,7 +588,6 @@ namespace CS2_SimpleAdmin
|
||||
return;
|
||||
}
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
var pattern = command.GetArg(1);
|
||||
@@ -793,9 +784,8 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
if (command == null) return;
|
||||
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Mute, DiscordWebhookClientPenalty, _localizer);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Silence, _localizer);
|
||||
Helper.LogCommand(caller, $"css_silence {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)} {time} {reason}");
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_addsilence")]
|
||||
@@ -893,7 +883,7 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
}
|
||||
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Mute, DiscordWebhookClientPenalty, _localizer);
|
||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Silence, _localizer);
|
||||
}
|
||||
}
|
||||
Task.Run(async () =>
|
||||
@@ -901,7 +891,6 @@ namespace CS2_SimpleAdmin
|
||||
await muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 2);
|
||||
});
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
command.ReplyToCommand($"Silenced player with steamid {steamid}.");
|
||||
@@ -925,7 +914,6 @@ namespace CS2_SimpleAdmin
|
||||
return;
|
||||
}
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
var pattern = command.GetArg(1);
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace CS2_SimpleAdmin
|
||||
if (command.ArgCount < 2)
|
||||
return;
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
VoteAnswers.Clear();
|
||||
@@ -50,11 +49,10 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
Helper.PrintToCenterAll(_localizer["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]);
|
||||
|
||||
if (_localizer != null)
|
||||
player.SendLocalizedMessage(_localizer,
|
||||
"sa_admin_vote_message",
|
||||
caller == null ? "Console" : caller.PlayerName,
|
||||
question);
|
||||
player.SendLocalizedMessage(_localizer,
|
||||
"sa_admin_vote_message",
|
||||
caller == null ? "Console" : caller.PlayerName,
|
||||
question);
|
||||
|
||||
voteMenu.Open(player);
|
||||
|
||||
|
||||
@@ -19,9 +19,7 @@ namespace CS2_SimpleAdmin
|
||||
var playersToTarget = targets.Players.Where(player =>
|
||||
player.IsValid &&
|
||||
player is { PawnIsAlive: true, IsHLTV: false, Connected: PlayerConnectedState.PlayerConnected }).ToList();
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
if (caller!.CanTarget(player))
|
||||
@@ -62,9 +60,7 @@ namespace CS2_SimpleAdmin
|
||||
var targets = GetTarget(command);
|
||||
if (targets == null) return;
|
||||
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, PawnIsAlive: true, IsHLTV: false }).ToList();
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
if (caller!.CanTarget(player))
|
||||
@@ -123,11 +119,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
player!.Pawn.Value!.Unfreeze();
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
}
|
||||
Helper.LogCommand(caller, $"css_unfreeze {player?.PlayerName}");
|
||||
|
||||
if (caller != null && SilentPlayers.Contains(caller.Slot)) return;
|
||||
foreach (var controller in Helper.GetValidPlayers().Where(controller => controller is { IsValid: true, IsBot: false }))
|
||||
|
||||
@@ -33,16 +33,11 @@ namespace CS2_SimpleAdmin
|
||||
return;
|
||||
if (!caller.CanTarget(player)) return;
|
||||
|
||||
|
||||
callerName ??= caller == null ? "Console" : caller.PlayerName;
|
||||
|
||||
player?.CommitSuicide(false, true);
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, command);
|
||||
}
|
||||
Helper.LogCommand(caller, $"css_slay {player?.PlayerName}");
|
||||
|
||||
if (caller != null && SilentPlayers.Contains(caller.Slot)) return;
|
||||
foreach (var controller in Helper.GetValidPlayers().Where(controller => controller is { IsValid: true, IsBot: false }))
|
||||
@@ -114,11 +109,7 @@ namespace CS2_SimpleAdmin
|
||||
{
|
||||
if (!caller.CanTarget(player)) return;
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
}
|
||||
Helper.LogCommand(caller, $"css_give {player.PlayerName} {weaponName}");
|
||||
|
||||
player.GiveNamedItem(weaponName);
|
||||
SubGiveWeapon(caller, player, weaponName, callerName);
|
||||
@@ -173,11 +164,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
player.RemoveWeapons();
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
}
|
||||
Helper.LogCommand(caller, $"css_strip {player.PlayerName}");
|
||||
|
||||
if (caller != null && SilentPlayers.Contains(caller.Slot)) return;
|
||||
foreach (var controller in Helper.GetValidPlayers().Where(controller => controller is { IsValid: true, IsBot: false }))
|
||||
@@ -222,11 +209,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
player.SetHp(health);
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
}
|
||||
Helper.LogCommand(caller, $"css_hp {player.PlayerName} {health}");
|
||||
|
||||
if (caller != null && SilentPlayers.Contains(caller.Slot)) return;
|
||||
foreach (var controller in Helper.GetValidPlayers().Where(controller => controller is { IsValid: true, IsBot: false }))
|
||||
@@ -272,11 +255,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
player.SetSpeed((float)speed);
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
}
|
||||
Helper.LogCommand(caller, $"css_speed {player?.PlayerName} {speed}");
|
||||
|
||||
if (caller != null && SilentPlayers.Contains(caller.Slot)) return;
|
||||
foreach (var controller in Helper.GetValidPlayers().Where(controller => controller is { IsValid: true, IsBot: false }))
|
||||
@@ -299,9 +278,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
var targets = GetTarget(command);
|
||||
if (targets == null) return;
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
|
||||
|
||||
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { PawnIsAlive: true, IsHLTV: false }).ToList();
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
@@ -324,11 +301,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
player.SetGravity((float)gravity);
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
}
|
||||
Helper.LogCommand(caller, $"css_gravity {player?.PlayerName} {gravity}");
|
||||
|
||||
if (caller != null && SilentPlayers.Contains(caller.Slot)) return;
|
||||
foreach (var controller in Helper.GetValidPlayers().Where(controller => controller is { IsValid: true, IsBot: false }))
|
||||
@@ -374,11 +347,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
player.SetMoney(money);
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
}
|
||||
Helper.LogCommand(caller, $"css_money {player?.PlayerName} {money}");
|
||||
|
||||
if (caller != null && SilentPlayers.Contains(caller.Slot)) return;
|
||||
foreach (var controller in Helper.GetValidPlayers().Where(controller => controller is { IsValid: true, IsBot: false }))
|
||||
@@ -421,17 +390,10 @@ namespace CS2_SimpleAdmin
|
||||
callerName ??= caller == null ? "Console" : caller.PlayerName;
|
||||
|
||||
if (player == null) return;
|
||||
if (command != null)
|
||||
{
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
}
|
||||
|
||||
Helper.LogCommand(caller, $"css_god {player.PlayerName}");
|
||||
|
||||
if (!GodPlayers.Contains(player.Slot))
|
||||
{
|
||||
GodPlayers.Add(player.Slot);
|
||||
}
|
||||
else
|
||||
if (!GodPlayers.Add(player.Slot))
|
||||
{
|
||||
GodPlayers.Remove(player.Slot);
|
||||
}
|
||||
@@ -483,12 +445,7 @@ namespace CS2_SimpleAdmin
|
||||
var callerName = caller == null ? "Console" : caller.PlayerName;
|
||||
player!.Pawn.Value!.Slap(damage);
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
Helper.LogCommand(caller, command);
|
||||
if (_localizer != null)
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
}
|
||||
Helper.LogCommand(caller, $"css_slap {player?.PlayerName} {damage}");
|
||||
|
||||
if (_localizer == null)
|
||||
return;
|
||||
@@ -599,9 +556,7 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
}
|
||||
|
||||
if (command == null) return;
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
Helper.LogCommand(caller, $"css_team {player?.PlayerName} {teamName}");
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_rename", "Rename a player.")]
|
||||
@@ -620,7 +575,6 @@ namespace CS2_SimpleAdmin
|
||||
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, IsHLTV: false }).ToList();
|
||||
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
@@ -658,7 +612,6 @@ namespace CS2_SimpleAdmin
|
||||
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, IsHLTV: false }).ToList();
|
||||
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
@@ -728,11 +681,7 @@ namespace CS2_SimpleAdmin
|
||||
VirtualFunction.CreateVoid<CCSPlayerController>(player.Handle,
|
||||
GameData.GetOffset("CCSPlayerController_Respawn"))(player);
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
}
|
||||
Helper.LogCommand(caller, $"css_respawn {player?.PlayerName}");
|
||||
|
||||
if (caller != null && SilentPlayers.Contains(caller.Slot)) return;
|
||||
foreach (var controller in Helper.GetValidPlayers().Where(controller => controller is { IsValid: true, IsBot: false }))
|
||||
@@ -762,7 +711,6 @@ namespace CS2_SimpleAdmin
|
||||
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, IsHLTV: false }).ToList();
|
||||
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
@@ -806,7 +754,6 @@ namespace CS2_SimpleAdmin
|
||||
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, IsHLTV: false }).ToList();
|
||||
|
||||
Helper.LogCommand(caller, command);
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
|
||||
54
Config.cs
54
Config.cs
@@ -10,7 +10,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
[JsonPropertyName("duration")]
|
||||
public int Duration { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
public class AdminFlag
|
||||
{
|
||||
@@ -20,14 +20,60 @@ namespace CS2_SimpleAdmin
|
||||
[JsonPropertyName("flag")]
|
||||
public required string Flag { get; set; }
|
||||
}
|
||||
|
||||
public class DiscordPenaltySetting
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public required string Name { get; set; }
|
||||
|
||||
[JsonPropertyName("value")]
|
||||
public string Value { get; set; } = "";
|
||||
}
|
||||
|
||||
public class Discord
|
||||
{
|
||||
[JsonPropertyName("DiscordLogWebhook")]
|
||||
public string DiscordLogWebhook { get; set; } = "";
|
||||
|
||||
[JsonPropertyName("DiscordPenaltyWebhook")]
|
||||
public string DiscordPenaltyWebhook { get; set; } = "";
|
||||
[JsonPropertyName("DiscordPenaltyBanSettings")]
|
||||
public DiscordPenaltySetting[] DiscordPenaltyBanSettings { get; set; } =
|
||||
[
|
||||
new DiscordPenaltySetting { Name = "Color", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "Webhook", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "ThumbnailUrl", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "ImageUrl", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "Footer", Value = "" },
|
||||
];
|
||||
|
||||
[JsonPropertyName("DiscordPenaltyMuteSettings")]
|
||||
public DiscordPenaltySetting[] DiscordPenaltyMuteSettings { get; set; } =
|
||||
[
|
||||
new DiscordPenaltySetting { Name = "Color", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "Webhook", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "ThumbnailUrl", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "ImageUrl", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "Footer", Value = "" },
|
||||
];
|
||||
|
||||
[JsonPropertyName("DiscordPenaltyGagSettings")]
|
||||
public DiscordPenaltySetting[] DiscordPenaltyGagSettings { get; set; } =
|
||||
[
|
||||
new DiscordPenaltySetting { Name = "Color", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "Webhook", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "ThumbnailUrl", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "ImageUrl", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "Footer", Value = "" },
|
||||
];
|
||||
|
||||
[JsonPropertyName("DiscordPenaltySilenceSettings")]
|
||||
public DiscordPenaltySetting[] DiscordPenaltySilenceSettings { get; set; } =
|
||||
[
|
||||
new DiscordPenaltySetting { Name = "Color", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "Webhook", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "ThumbnailUrl", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "ImageUrl", Value = "" },
|
||||
new DiscordPenaltySetting { Name = "Footer", Value = "" },
|
||||
];
|
||||
}
|
||||
|
||||
public class CustomServerCommandData
|
||||
@@ -111,7 +157,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
public class CS2_SimpleAdminConfig : BasePluginConfig
|
||||
{
|
||||
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 16;
|
||||
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 17;
|
||||
|
||||
[JsonPropertyName("DatabaseHost")]
|
||||
public string DatabaseHost { get; set; } = "";
|
||||
|
||||
14
Events.cs
14
Events.cs
@@ -44,9 +44,7 @@ public partial class CS2_SimpleAdmin
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_getIpTryCount = 0;
|
||||
|
||||
|
||||
var address = $"{ipAddress}:{ConVar.Find("hostport")?.GetPrimitiveValue<int>()}";
|
||||
var hostname = ConVar.Find("hostname")!.StringValue;
|
||||
|
||||
@@ -106,6 +104,8 @@ public partial class CS2_SimpleAdmin
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
_getIpTryCount = 0;
|
||||
}
|
||||
|
||||
[GameEventHandler]
|
||||
@@ -370,11 +370,17 @@ public partial class CS2_SimpleAdmin
|
||||
return HookResult.Handled;
|
||||
}
|
||||
|
||||
public void OnMapStart(string mapName)
|
||||
private void OnMapStart(string mapName)
|
||||
{
|
||||
if (Config.ReloadAdminsEveryMapChange && _serverLoaded && ServerId != null)
|
||||
AddTimer(3.0f, () => ReloadAdmins(null));
|
||||
|
||||
AddTimer(34, () =>
|
||||
{
|
||||
if (!_serverLoaded)
|
||||
OnGameServerSteamAPIActivated();
|
||||
});
|
||||
|
||||
var path = Path.GetDirectoryName(ModuleDirectory);
|
||||
if (Directory.Exists(path + "/CS2-Tags"))
|
||||
{
|
||||
|
||||
84
Helper.cs
84
Helper.cs
@@ -1,4 +1,5 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using System.Drawing;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Admin;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
@@ -16,6 +17,7 @@ using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using Color = Discord.Color;
|
||||
|
||||
namespace CS2_SimpleAdmin
|
||||
{
|
||||
@@ -176,6 +178,8 @@ namespace CS2_SimpleAdmin
|
||||
CS2_SimpleAdmin.Instance.Logger.LogInformation($"{CS2_SimpleAdmin._localizer[
|
||||
"sa_discord_log_command",
|
||||
playerName, command.GetCommandString]}".Replace("HOSTNAME", hostname).Replace("**", ""));
|
||||
|
||||
SendDiscordLogMessage(caller, command, CS2_SimpleAdmin.DiscordWebhookClientLog, CS2_SimpleAdmin._localizer);
|
||||
}
|
||||
|
||||
internal static void LogCommand(CCSPlayerController? caller, string command)
|
||||
@@ -184,14 +188,17 @@ namespace CS2_SimpleAdmin
|
||||
return;
|
||||
|
||||
var playerName = caller?.PlayerName ?? "Console";
|
||||
|
||||
var hostname = ConVar.Find("hostname")?.StringValue ?? CS2_SimpleAdmin._localizer["sa_unknown"];
|
||||
var hostnameCvar = ConVar.Find("hostname");
|
||||
|
||||
var hostname = hostnameCvar?.StringValue ?? CS2_SimpleAdmin._localizer["sa_unknown"];
|
||||
|
||||
CS2_SimpleAdmin.Instance.Logger.LogInformation($"{CS2_SimpleAdmin._localizer["sa_discord_log_command",
|
||||
playerName, command]}".Replace("HOSTNAME", hostname).Replace("**", ""));
|
||||
|
||||
SendDiscordLogMessage(caller, command, CS2_SimpleAdmin.DiscordWebhookClientLog, CS2_SimpleAdmin._localizer);
|
||||
}
|
||||
|
||||
public static IEnumerable<Embed> GenerateEmbedsDiscord(string title, string description, string thumbnailUrl, Color color, string[] fieldNames, string[] fieldValues, bool[] inlineFlags)
|
||||
/*public static IEnumerable<Embed> GenerateEmbedsDiscord(string title, string description, string thumbnailUrl, Color color, string[] fieldNames, string[] fieldValues, bool[] inlineFlags)
|
||||
{
|
||||
var hostname = ConVar.Find("hostname")?.StringValue ?? CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown";
|
||||
var address = $"{ConVar.Find("ip")?.StringValue}:{ConVar.Find("hostport")!.GetPrimitiveValue<int>()}";
|
||||
@@ -221,9 +228,9 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
|
||||
return new List<Embed> { embed.Build() };
|
||||
}
|
||||
}*/
|
||||
|
||||
public static void SendDiscordLogMessage(CCSPlayerController? caller, CommandInfo command, DiscordWebhookClient? discordWebhookClientLog, IStringLocalizer? localizer)
|
||||
private static void SendDiscordLogMessage(CCSPlayerController? caller, CommandInfo command, DiscordWebhookClient? discordWebhookClientLog, IStringLocalizer? localizer)
|
||||
{
|
||||
if (discordWebhookClientLog == null || localizer == null) return;
|
||||
|
||||
@@ -232,6 +239,15 @@ namespace CS2_SimpleAdmin
|
||||
discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
|
||||
}
|
||||
|
||||
private static void SendDiscordLogMessage(CCSPlayerController? caller, string command, DiscordWebhookClient? discordWebhookClientLog, IStringLocalizer? localizer)
|
||||
{
|
||||
if (discordWebhookClientLog == null || localizer == null) return;
|
||||
|
||||
var communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl() + ">" : "<https://steamcommunity.com/profiles/0>";
|
||||
var callerName = caller != null ? caller.PlayerName : "Console";
|
||||
discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command]));
|
||||
}
|
||||
|
||||
public enum PenaltyType
|
||||
{
|
||||
Ban,
|
||||
@@ -247,17 +263,34 @@ namespace CS2_SimpleAdmin
|
||||
return time.Days > 0 ? $"{time.Days}d {time.Hours}h {time.Minutes}m" : time.Hours > 0 ? $"{time.Hours}h {time.Minutes}m" : $"{time.Minutes}m";
|
||||
}
|
||||
|
||||
public static void SendDiscordPenaltyMessage(CCSPlayerController? caller, CCSPlayerController? target, string reason, int duration, PenaltyType penalty, DiscordWebhookClient? discordWebhookClientPenalty, IStringLocalizer? localizer)
|
||||
public static void SendDiscordPenaltyMessage(CCSPlayerController? caller, CCSPlayerController? target, string reason, int duration, PenaltyType penalty, IStringLocalizer? localizer)
|
||||
{
|
||||
if (discordWebhookClientPenalty == null || localizer == null) return;
|
||||
if (localizer == null) return;
|
||||
|
||||
DiscordPenaltySetting[] penaltySetting = penalty switch
|
||||
{
|
||||
PenaltyType.Ban => CS2_SimpleAdmin.Instance.Config.Discord.DiscordPenaltyBanSettings,
|
||||
PenaltyType.Mute => CS2_SimpleAdmin.Instance.Config.Discord.DiscordPenaltyMuteSettings,
|
||||
PenaltyType.Gag => CS2_SimpleAdmin.Instance.Config.Discord.DiscordPenaltyGagSettings,
|
||||
PenaltyType.Silence => CS2_SimpleAdmin.Instance.Config.Discord.DiscordPenaltySilenceSettings,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(penalty), penalty, null)
|
||||
};
|
||||
|
||||
var webhookUrl = penaltySetting.FirstOrDefault(s => s.Name.Equals("Webhook"))?.Value;
|
||||
|
||||
if (string.IsNullOrEmpty(webhookUrl)) return;
|
||||
|
||||
var callerCommunityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl() + ">" : "<https://steamcommunity.com/profiles/0>";
|
||||
var targetCommunityUrl = target != null ? "<" + new SteamID(target.SteamID).ToCommunityUrl() + ">" : "<https://steamcommunity.com/profiles/0>";
|
||||
var callerName = caller != null ? caller.PlayerName : "Console";
|
||||
var targetName = target != null ? target.PlayerName : localizer["sa_unknown"];
|
||||
var targetSteamId = target != null ? new SteamID(target.SteamID).SteamId2 : localizer["sa_unknown"];
|
||||
var targetSteamId = target != null ? new SteamID(target.SteamID).SteamId64.ToString() : localizer["sa_unknown"];
|
||||
|
||||
DateTime futureTime = DateTime.Now.AddMinutes(duration);
|
||||
long futureUnixTimestamp = new DateTimeOffset(futureTime).ToUnixTimeSeconds();
|
||||
|
||||
var time = duration != 0 ? ConvertMinutesToTime(duration) : localizer["sa_permanent"];
|
||||
//var time = duration != 0 ? ConvertMinutesToTime(duration) : localizer["sa_permanent"];
|
||||
var time = duration != 0 ? $"<t:{futureUnixTimestamp}:R>": localizer["sa_permanent"];
|
||||
|
||||
string[] fieldNames = [
|
||||
localizer["sa_player"],
|
||||
@@ -265,42 +298,45 @@ namespace CS2_SimpleAdmin
|
||||
localizer["sa_duration"],
|
||||
localizer["sa_reason"],
|
||||
localizer["sa_admin"]];
|
||||
string[] fieldValues = [$"[{targetName}]({targetCommunityUrl})", targetSteamId, time, reason, $"[{callerName}]({callerCommunityUrl})"];
|
||||
string[] fieldValues =
|
||||
[
|
||||
$"[{targetName}]({targetCommunityUrl})", $"||{targetSteamId}||", time, reason,
|
||||
$"[{callerName}]({callerCommunityUrl})"
|
||||
];
|
||||
bool[] inlineFlags = [true, true, true, false, false];
|
||||
|
||||
var hostname = ConVar.Find("hostname")?.StringValue ?? localizer["sa_unknown"];
|
||||
|
||||
var colorHex = penaltySetting.FirstOrDefault(s => s.Name.Equals("Color"))?.Value ?? "#FFFFFF";
|
||||
var color = ColorTranslator.FromHtml(colorHex);
|
||||
|
||||
var embed = new EmbedBuilder
|
||||
{
|
||||
Color = new Color(color.R, color.G, color.B),
|
||||
Title = penalty switch
|
||||
{
|
||||
PenaltyType.Ban => localizer["sa_discord_penalty_ban"],
|
||||
PenaltyType.Mute => localizer["sa_discord_penalty_mute"],
|
||||
PenaltyType.Gag => localizer["sa_discord_penalty_gag"],
|
||||
PenaltyType.Silence => localizer["sa_discord_penalty_silence"],
|
||||
_ => localizer["sa_discord_penalty_unknown"],
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(penalty), penalty, null)
|
||||
},
|
||||
|
||||
Color = penalty switch
|
||||
ThumbnailUrl = penaltySetting.FirstOrDefault(s => s.Name.Equals("ThumbnailUrl"))?.Value,
|
||||
ImageUrl = penaltySetting.FirstOrDefault(s => s.Name.Equals("ImageUrl"))?.Value,
|
||||
Footer = new EmbedFooterBuilder
|
||||
{
|
||||
PenaltyType.Ban => Color.Red,
|
||||
PenaltyType.Mute => Color.Blue,
|
||||
PenaltyType.Gag => Color.Gold,
|
||||
PenaltyType.Silence => Color.Green,
|
||||
_ => Color.Default,
|
||||
Text = penaltySetting.FirstOrDefault(s => s.Name.Equals("Footer"))?.Value,
|
||||
},
|
||||
|
||||
Description = $"{hostname}",
|
||||
|
||||
Timestamp = DateTimeOffset.UtcNow
|
||||
Timestamp = DateTimeOffset.Now,
|
||||
};
|
||||
|
||||
for (var i = 0; i < fieldNames.Length; i++)
|
||||
{
|
||||
embed.AddField(fieldNames[i], fieldValues[i], inlineFlags[i]);
|
||||
}
|
||||
|
||||
discordWebhookClientPenalty.SendMessageAsync(embeds: [embed.Build()]);
|
||||
|
||||
new DiscordWebhookClient(webhookUrl).SendMessageAsync(embeds: [embed.Build()]);
|
||||
}
|
||||
|
||||
private static string GenerateMessageDiscord(string message)
|
||||
|
||||
@@ -74,64 +74,32 @@ public class PermissionManager(Database.Database database)
|
||||
ORDER BY sa_admins.player_steamid
|
||||
""";
|
||||
|
||||
var activeFlags = (await connection.QueryAsync(sql, new { CurrentTime = now, serverid = CS2_SimpleAdmin.ServerId })).ToList();
|
||||
var admins = (await connection.QueryAsync(sql, new { CurrentTime = now, serverid = CS2_SimpleAdmin.ServerId })).ToList();
|
||||
|
||||
// Group by player_steamid and aggregate the flags
|
||||
var groupedPlayers = admins
|
||||
.GroupBy(r => new { r.player_steamid, r.player_name, r.immunity, r.ends })
|
||||
.Select(g => (
|
||||
PlayerSteamId: (string)g.Key.player_steamid,
|
||||
PlayerName: (string)g.Key.player_name,
|
||||
Flags: g.Select(r => (string)r.flag).Distinct().ToList(),
|
||||
Immunity: g.Key.immunity is int i ? i : int.TryParse((string)g.Key.immunity, out var immunity) ? immunity : 0,
|
||||
Ends: g.Key.ends is DateTime dateTime ? dateTime : (DateTime?)null
|
||||
))
|
||||
.ToList();
|
||||
|
||||
/*
|
||||
foreach (var player in groupedPlayers)
|
||||
{
|
||||
Console.WriteLine($"Player SteamID: {player.PlayerSteamId}, Name: {player.PlayerName}, Flags: {string.Join(", ", player.Flags)}, Immunity: {player.Immunity}, Ends: {player.Ends}");
|
||||
}
|
||||
*/
|
||||
|
||||
List<(string, string, List<string>, int, DateTime?)> filteredFlagsWithImmunity = [];
|
||||
var currentSteamId = string.Empty;
|
||||
var currentPlayerName = string.Empty;
|
||||
List<string> currentFlags = [];
|
||||
var immunityValue = 0;
|
||||
DateTime? ends = null;
|
||||
|
||||
foreach (var flagInfo in activeFlags)
|
||||
{
|
||||
if (flagInfo is not IDictionary<string, object> flagInfoDict)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!flagInfoDict.TryGetValue("player_steamid", out var steamIdObj) ||
|
||||
!flagInfoDict.TryGetValue("player_name", out var playerNameObj) ||
|
||||
!flagInfoDict.TryGetValue("flag", out var flagObj) ||
|
||||
!flagInfoDict.TryGetValue("immunity", out var immunityValueObj) ||
|
||||
!flagInfoDict.TryGetValue("ends", out var endsObj))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (steamIdObj is not string steamId ||
|
||||
playerNameObj is not string playerName ||
|
||||
flagObj is not string flag ||
|
||||
!int.TryParse(immunityValueObj.ToString(), out immunityValue))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ends != null)
|
||||
{
|
||||
if (DateTime.TryParse(endsObj.ToString(), out var parsedEnds))
|
||||
{
|
||||
ends = parsedEnds;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentSteamId != steamId && !string.IsNullOrEmpty(currentSteamId))
|
||||
{
|
||||
filteredFlagsWithImmunity.Add((currentSteamId, currentPlayerName, currentFlags, immunityValue, ends));
|
||||
currentFlags = [];
|
||||
}
|
||||
|
||||
currentSteamId = steamId;
|
||||
currentPlayerName = playerName;
|
||||
currentFlags.Add(flag);
|
||||
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(currentSteamId))
|
||||
{
|
||||
filteredFlagsWithImmunity.Add((currentSteamId, currentPlayerName, currentFlags, immunityValue, ends));
|
||||
}
|
||||
|
||||
// Add the grouped players to the list
|
||||
filteredFlagsWithImmunity.AddRange(groupedPlayers);
|
||||
|
||||
return filteredFlagsWithImmunity;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -343,22 +311,37 @@ public class PermissionManager(Database.Database database)
|
||||
public async Task CreateAdminsJsonFile()
|
||||
{
|
||||
List<(string identity, string name, List<string> flags, int immunity, DateTime? ends)> allPlayers = await GetAllPlayersFlags();
|
||||
var validPlayers = allPlayers
|
||||
.Where(player => SteamID.TryParse(player.identity, out _)) // Filter invalid SteamID
|
||||
.ToList();
|
||||
|
||||
var jsonData = allPlayers
|
||||
/*
|
||||
foreach (var player in allPlayers)
|
||||
{
|
||||
var (steamId, name, flags, immunity, ends) = player;
|
||||
|
||||
// Print or process each item
|
||||
Console.WriteLine($"Player SteamID: {steamId}");
|
||||
Console.WriteLine($"Player Name: {name}");
|
||||
Console.WriteLine($"Flags: {string.Join(", ", flags)}");
|
||||
Console.WriteLine($"Immunity: {immunity}");
|
||||
Console.WriteLine($"Ends: {(ends.HasValue ? ends.Value.ToString("yyyy-MM-dd HH:mm:ss") : "Never")}");
|
||||
Console.WriteLine(); // New line for better readability
|
||||
}
|
||||
*/
|
||||
|
||||
var jsonData = validPlayers
|
||||
.Select(player =>
|
||||
{
|
||||
SteamID? steamId = null;
|
||||
|
||||
if (!string.IsNullOrEmpty(player.identity) && SteamID.TryParse(player.identity, out var id) && id != null)
|
||||
{
|
||||
steamId = id;
|
||||
}
|
||||
|
||||
SteamID.TryParse(player.identity, out var steamId);
|
||||
|
||||
// Update cache if SteamID is valid and not already cached
|
||||
if (steamId != null && !AdminCache.ContainsKey(steamId))
|
||||
{
|
||||
AdminCache.TryAdd(steamId, player.ends);
|
||||
}
|
||||
|
||||
// Create an anonymous object with player data
|
||||
return new
|
||||
{
|
||||
playerName = player.name,
|
||||
@@ -366,14 +349,15 @@ public class PermissionManager(Database.Database database)
|
||||
{
|
||||
player.identity,
|
||||
player.immunity,
|
||||
flags = player.flags.Where(flag => flag.StartsWith($"@")).ToList(),
|
||||
groups = player.flags.Where(flag => flag.StartsWith($"#")).ToList()
|
||||
flags = player.flags.Where(flag => flag.StartsWith("@")).ToList(),
|
||||
groups = player.flags.Where(flag => flag.StartsWith("#")).ToList()
|
||||
}
|
||||
};
|
||||
})
|
||||
.ToDictionary(item => item.playerName, item => item.playerData);
|
||||
.ToDictionary(item => item.playerName, item => (object)item.playerData);
|
||||
|
||||
var json = JsonConvert.SerializeObject(jsonData, Formatting.Indented);
|
||||
|
||||
var filePath = Path.Combine(CS2_SimpleAdmin.Instance.ModuleDirectory, "data", "admins.json");
|
||||
await File.WriteAllTextAsync(filePath, json);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user