- Fixed godmode
- Added logging commands to simpleadmin logs file
- Fixed votes?
- Added updating player_ip and player_name after connect with ban issued by css_addban
This commit is contained in:
Dawid Bepierszcz
2024-02-21 13:14:46 +01:00
parent 619bdfbb14
commit 5bf966f9cd
16 changed files with 213 additions and 88 deletions

View File

@@ -58,6 +58,7 @@ namespace CS2_SimpleAdmin
internal void Ban(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, BanManager? banManager = null)
{
if (_database == null) return;
callerName ??= caller == null ? "Console" : caller.PlayerName;
banManager ??= new BanManager(_database, Config);
@@ -80,6 +81,8 @@ namespace CS2_SimpleAdmin
IpAddress = caller?.IpAddress?.Split(":")[0]
};
Helper.LogCommand(caller, $"css_ban {player?.SteamID} {time} {reason}");
Task.Run(async () =>
{
await banManager.BanPlayer(playerInfo, adminInfo, reason, time);
@@ -177,6 +180,8 @@ namespace CS2_SimpleAdmin
IpAddress = caller?.IpAddress?.Split(":")[0]
};
Helper.LogCommand(caller, command);
List<CCSPlayerController> matches = Helper.GetPlayerFromSteamid64(steamid);
if (matches.Count == 1)
{
@@ -281,6 +286,8 @@ namespace CS2_SimpleAdmin
IpAddress = caller?.IpAddress?.Split(":")[0]
};
Helper.LogCommand(caller, command);
int.TryParse(command.GetArg(2), out int time);
if (command.ArgCount >= 3 && command.GetArg(3).Length > 0)
@@ -375,6 +382,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
string pattern = command.GetArg(1);
Database database = new Database(dbConnectionString);

View File

@@ -27,6 +27,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]);
string utf8String = Encoding.UTF8.GetString(utf8BytesString);
@@ -58,6 +60,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
foreach (CCSPlayerController _player in Helper.GetValidPlayers())
{
using (new WithTemporaryCulture(_player.GetLanguage()))
@@ -78,6 +82,8 @@ namespace CS2_SimpleAdmin
if (targets == null) return;
List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList();
Helper.LogCommand(caller, command);
int range = command.GetArg(0).Length + command.GetArg(1).Length + 2;
string message = command.GetCommandString[range..];
@@ -107,6 +113,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
Helper.PrintToCenterAll(Helper.ReplaceTags(utf8String));
}
@@ -125,6 +133,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
VirtualFunctions.ClientPrintAll(
HudDestination.Alert,
Helper.ReplaceTags(utf8String),

View File

@@ -116,6 +116,8 @@ namespace CS2_SimpleAdmin
AdminSQLManager _adminManager = new(_database);
_ = _adminManager.AddAdminBySteamId(steamid, name, flags, immunity, time, globalAdmin);
Helper.LogCommand(caller, $"css_addadmin {steamid} {name} {flags} {immunity} {time}");
string msg = $"Added '{flags}' flags to '{name}' ({steamid})";
if (command != null)
command.ReplyToCommand(msg);
@@ -171,6 +173,8 @@ namespace CS2_SimpleAdmin
}
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
Helper.LogCommand(caller, $"css_deladmin {steamid}");
string msg = $"Removed flags from '{steamid}'";
if (command != null)
command.ReplyToCommand(msg);
@@ -195,6 +199,7 @@ namespace CS2_SimpleAdmin
public void ReloadAdmins()
{
if (_database == null) return;
foreach (SteamID steamId in AdminSQLManager._adminCache.Keys.ToList())
{
if (AdminSQLManager._adminCache.TryRemove(steamId, out _))
@@ -216,6 +221,8 @@ namespace CS2_SimpleAdmin
{
if (caller == null) return;
Helper.LogCommand(caller, command);
if (silentPlayers.Contains(caller.Slot))
{
RemoveFromConcurrentBag(silentPlayers, caller.Slot);
@@ -226,16 +233,14 @@ namespace CS2_SimpleAdmin
{
silentPlayers.Add(caller.Slot);
Server.ExecuteCommand("sv_disable_teamselect_menu 1");
Server.NextFrame(() =>
{
if (caller.PlayerPawn.Value != null && caller.PawnIsAlive)
caller.PlayerPawn.Value.CommitSuicide(true, false);
AddTimer(1.0f, () => { caller.ChangeTeam(CsTeam.Spectator); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
AddTimer(1.15f, () => { caller.ChangeTeam(CsTeam.None); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
caller.PrintToChat($"You are hidden now!");
AddTimer(1.22f, () => { Server.ExecuteCommand("sv_disable_teamselect_menu 0"); });
});
if (caller.PlayerPawn.Value != null && caller.PawnIsAlive)
caller.PlayerPawn.Value.CommitSuicide(true, false);
AddTimer(1.0f, () => { Server.NextFrame(() => caller.ChangeTeam(CsTeam.Spectator)); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
AddTimer(1.4f, () => { Server.NextFrame(() => caller.ChangeTeam(CsTeam.None)); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
caller.PrintToChat($"You are hidden now!");
AddTimer(2.0f, () => { Server.NextFrame(() => Server.ExecuteCommand("sv_disable_teamselect_menu 0")); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
}
@@ -390,6 +395,8 @@ namespace CS2_SimpleAdmin
player.Pawn.Value!.Freeze();
}
Helper.LogCommand(caller, $"css_kick {player.PlayerName} {reason}");
if (string.IsNullOrEmpty(reason) == false)
{
if (!player.IsBot && !player.IsHLTV)
@@ -450,6 +457,8 @@ namespace CS2_SimpleAdmin
string commandName = command?.GetCommandString ?? "css_changemap";
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandName]));
}
if (command is not null)
Helper.LogCommand(caller, command);
AddTimer(2.0f, () =>
{
@@ -537,6 +546,8 @@ namespace CS2_SimpleAdmin
string commandName = command?.GetCommandString ?? "css_changewsmap";
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandName]));
}
if (command is not null)
Helper.LogCommand(caller, command);
AddTimer(2.0f, () =>
{
@@ -570,6 +581,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
var value = command.GetArg(2);
Server.ExecuteCommand($"{cvar.Name} {value}");
@@ -591,6 +604,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
Server.ExecuteCommand(command.ArgString);
command.ReplyToCommand($"{callerName} executed command {command.ArgString}.");
Logger.LogInformation($"{callerName} executed command ({command.ArgString}).");
@@ -609,9 +624,11 @@ namespace CS2_SimpleAdmin
public static void RestartGame(CCSPlayerController? admin)
{
Helper.LogCommand(admin, "css_restartgame");
// TODO: Localize
var name = admin == null ? "Console" : admin.PlayerName;
Server.PrintToChatAll($"[SimpleAdmin] {name}: Restarting game...");
Server.PrintToChatAll($"[SA] {name}: Restarting game...");
Server.ExecuteCommand("mp_restartgame 2");
}
}

View File

@@ -76,6 +76,8 @@ namespace CS2_SimpleAdmin
IpAddress = caller?.IpAddress?.Split(":")[0]
};
Helper.LogCommand(caller, $"css_gag {player?.SteamID} {time} {reason}");
Task.Run(async () =>
{
await muteManager.MutePlayer(playerInfo, adminInfo, reason, time);
@@ -179,6 +181,8 @@ namespace CS2_SimpleAdmin
IpAddress = caller?.IpAddress?.Split(":")[0]
};
Helper.LogCommand(caller, command);
List<CCSPlayerController> matches = Helper.GetPlayerFromSteamid64(steamid);
if (matches.Count == 1)
{
@@ -264,6 +268,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
bool found = false;
string pattern = command.GetArg(1);
@@ -405,6 +411,8 @@ namespace CS2_SimpleAdmin
IpAddress = caller?.IpAddress?.Split(":")[0]
};
Helper.LogCommand(caller, $"css_mute {player?.SteamID} {time} {reason}");
player!.VoiceFlags = VoiceFlags.Muted;
Task.Run(async () =>
@@ -483,6 +491,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
int time = 0;
string reason = "Unknown";
@@ -581,6 +591,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
string pattern = command.GetArg(1);
bool found = false;
MuteManager _muteManager = new(_database);
@@ -711,6 +723,8 @@ namespace CS2_SimpleAdmin
IpAddress = caller?.IpAddress?.Split(":")[0]
};
Helper.LogCommand(caller, $"css_silence {player?.SteamID} {time} {reason}");
Task.Run(async () =>
{
await muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 2);
@@ -797,6 +811,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
int time = 0;
string reason = "Unknown";
@@ -898,6 +914,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
string pattern = command.GetArg(1);
bool found = false;
MuteManager _muteManager = new(_database);

View File

@@ -26,6 +26,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
voteAnswers.Clear();
string question = command.GetArg(1);
@@ -33,25 +35,30 @@ namespace CS2_SimpleAdmin
if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot))
{
ChatMenu voteMenu = new(_localizer!["sa_admin_vote_menu_title", question]);
for (int i = 2; i <= answersCount - 1; i++)
{
voteAnswers.Add(command.GetArg(i), 0);
voteMenu.AddMenuOption(command.GetArg(i), Helper.HandleVotes);
}
foreach (CCSPlayerController _player in Helper.GetValidPlayers())
{
using (new WithTemporaryCulture(_player.GetLanguage()))
{
ChatMenu voteMenu = new(_localizer!["sa_admin_vote_menu_title", question]);
for (int i = 2; i <= answersCount - 1; i++)
{
voteMenu.AddMenuOption(command.GetArg(i), Helper.HandleVotes);
}
voteMenu.PostSelectAction = PostSelectAction.Close;
MenuManager.OpenChatMenu(_player, voteMenu);
Helper.PrintToCenterAll(_localizer!["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]);
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]);
_player.PrintToChat(sb.ToString());
}
MenuManager.OpenChatMenu(_player, voteMenu);
}
voteInProgress = true;
@@ -84,7 +91,6 @@ namespace CS2_SimpleAdmin
}
}
voteAnswers.Clear();
votePlayers.Clear();
voteInProgress = false;
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}

View File

@@ -41,6 +41,8 @@ namespace CS2_SimpleAdmin
callerName ??= caller == null ? "Console" : caller.PlayerName;
player!.Pawn.Value!.ToggleNoclip();
Helper.LogCommand(caller, $"css_noclip {player?.PlayerName}");
if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot))
{
foreach (CCSPlayerController _player in Helper.GetValidPlayers())
@@ -90,6 +92,8 @@ namespace CS2_SimpleAdmin
player!.Pawn.Value!.Freeze();
Helper.LogCommand(caller, $"css_freeze {player?.PlayerName}");
if (time > 0)
AddTimer(time, () => player.Pawn.Value!.Unfreeze(), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
@@ -138,6 +142,8 @@ namespace CS2_SimpleAdmin
player!.Pawn.Value!.Unfreeze();
Helper.LogCommand(caller, $"css_unfreeze {player?.PlayerName}");
if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot))
{
foreach (CCSPlayerController _player in Helper.GetValidPlayers())

View File

@@ -8,7 +8,6 @@ using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Utils;
using System.Collections.Concurrent;
using System.Text;
namespace CS2_SimpleAdmin
@@ -47,6 +46,8 @@ namespace CS2_SimpleAdmin
player.CommitSuicide(false, true);
Helper.LogCommand(caller, $"css_slay {player?.PlayerName}");
if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot))
{
foreach (CCSPlayerController _player in Helper.GetValidPlayers())
@@ -114,14 +115,18 @@ namespace CS2_SimpleAdmin
public void GiveWeapon(CCSPlayerController? caller, CCSPlayerController player, CsItem weapon, string? callerName = null)
{
player.GiveNamedItem(weapon);
SubGiveWeapon(caller, player, weapon.ToString(), callerName);
Helper.LogCommand(caller, $"css_give {player?.PlayerName} {weapon.ToString()}");
player?.GiveNamedItem(weapon);
SubGiveWeapon(caller, player!, weapon.ToString(), callerName);
}
public void GiveWeapon(CCSPlayerController? caller, CCSPlayerController player, string weaponName, string? callerName = null)
{
player.GiveNamedItem(weaponName);
SubGiveWeapon(caller, player, weaponName, callerName);
Helper.LogCommand(caller, $"css_give {player?.PlayerName} {weaponName}");
player?.GiveNamedItem(weaponName);
SubGiveWeapon(caller, player!, weaponName, callerName);
}
public void SubGiveWeapon(CCSPlayerController? caller, CCSPlayerController player, string weaponName, string? callerName = null)
@@ -177,6 +182,8 @@ namespace CS2_SimpleAdmin
player.RemoveWeapons();
Helper.LogCommand(caller, $"css_strip {player?.PlayerName}");
if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot))
{
foreach (CCSPlayerController _player in Helper.GetValidPlayers())
@@ -229,6 +236,8 @@ namespace CS2_SimpleAdmin
player.SetHp(health);
Helper.LogCommand(caller, $"css_hp {player?.PlayerName} {health}");
if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot))
{
foreach (CCSPlayerController _player in Helper.GetValidPlayers())
@@ -281,6 +290,8 @@ namespace CS2_SimpleAdmin
player.SetSpeed((float)speed);
Helper.LogCommand(caller, $"css_speed {player?.PlayerName} {speed}");
if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot))
{
foreach (CCSPlayerController _player in Helper.GetValidPlayers())
@@ -288,7 +299,7 @@ namespace CS2_SimpleAdmin
using (new WithTemporaryCulture(_player.GetLanguage()))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_speed_message", callerName, player.PlayerName]);
sb.Append(_localizer["sa_admin_speed_message", callerName, player!.PlayerName]);
_player.PrintToChat(sb.ToString());
}
}
@@ -330,13 +341,15 @@ namespace CS2_SimpleAdmin
if (player != null)
{
Helper.LogCommand(caller, $"css_god {player.PlayerName}");
if (!godPlayers.Contains(player.Slot))
{
godPlayers.Add(player.Slot);
}
else
{
godPlayers = new ConcurrentBag<int>(godPlayers.Where(item => item != player.Slot));
RemoveFromConcurrentBag(godPlayers, player.Slot);
}
if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot))
@@ -395,6 +408,8 @@ namespace CS2_SimpleAdmin
callerName ??= caller == null ? "Console" : caller.PlayerName;
player!.Pawn.Value!.Slap(damage);
Helper.LogCommand(caller, $"css_slap {player?.PlayerName} {damage}");
if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot))
{
foreach (CCSPlayerController _player in Helper.GetValidPlayers())
@@ -456,9 +471,12 @@ namespace CS2_SimpleAdmin
}
bool kill = command.GetArg(3).ToLower().Equals("-k");
Helper.LogCommand(caller, command);
playersToTarget.ForEach(player =>
{
ChangeTeam(caller, player, _teamName.ToLower(), teamNum, kill, callerName);
ChangeTeam(caller, player, _teamName, teamNum, kill, callerName);
});
}
@@ -527,6 +545,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
playersToTarget.ForEach(player =>
{
if (!player.IsBot && player.SteamID.ToString().Length != 17)
@@ -591,6 +611,8 @@ namespace CS2_SimpleAdmin
VirtualFunction.CreateVoid<CCSPlayerController>(player.Handle,
GameData.GetOffset("CCSPlayerController_Respawn"))(player);
Helper.LogCommand(caller, $"css_respawn {player.PlayerName}");
if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot))
{
foreach (CCSPlayerController _player in Helper.GetValidPlayers())
@@ -629,6 +651,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
playersToTarget.ForEach(player =>
{
if (!player.IsBot && player.SteamID.ToString().Length != 17 || !player.PawnIsAlive)
@@ -683,6 +707,8 @@ namespace CS2_SimpleAdmin
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
Helper.LogCommand(caller, command);
playersToTarget.ForEach(player =>
{
if (!player.IsBot && player.SteamID.ToString().Length != 17 || !player.PawnIsAlive)