upstream ~ v1.7.7-alpha

This commit is contained in:
Sachin 2025-05-25 13:17:22 +05:30
commit c586dd700c
43 changed files with 928 additions and 337 deletions

View file

@ -34,6 +34,7 @@ public static class RegisterCommands
new CommandMapping("css_addgroup", CS2_SimpleAdmin.Instance.OnAddGroup),
new CommandMapping("css_delgroup", CS2_SimpleAdmin.Instance.OnDelGroupCommand),
new CommandMapping("css_reloadadmins", CS2_SimpleAdmin.Instance.OnRelAdminCommand),
new CommandMapping("css_reloadbans", CS2_SimpleAdmin.Instance.OnRelBans),
new CommandMapping("css_hide", CS2_SimpleAdmin.Instance.OnHideCommand),
new CommandMapping("css_hidecomms", CS2_SimpleAdmin.Instance.OnHideCommsCommand),
new CommandMapping("css_who", CS2_SimpleAdmin.Instance.OnWhoCommand),
@ -122,6 +123,7 @@ public static class RegisterCommands
{ "css_addgroup", new Command { Aliases = ["css_addgroup"] } },
{ "css_delgroup", new Command { Aliases = ["css_delgroup"] } },
{ "css_reloadadmins", new Command { Aliases = ["css_reloadadmins"] } },
{ "css_reloadbans", new Command { Aliases = ["css_reloadbans"] } },
{ "css_hide", new Command { Aliases = ["css_hide", "css_stealth"] } },
{ "css_hidecomms", new Command { Aliases = ["css_hidecomms"] } },
{ "css_who", new Command { Aliases = ["css_who"] } },

View file

@ -73,12 +73,6 @@ public partial class CS2_SimpleAdmin
SimpleAdminApi?.OnPlayerPenaltiedEvent(playerInfo, adminInfo, PenaltyType.Ban, reason, time, penaltyId);
});
// Update banned players list
if (playerInfo.IpAddress != null && !BannedPlayers.Contains(playerInfo.IpAddress))
BannedPlayers.Add(playerInfo.IpAddress);
if (!BannedPlayers.Contains(player.SteamID.ToString()))
BannedPlayers.Add(player.SteamID.ToString());
// Determine message keys and arguments based on ban time
var (messageKey, activityMessageKey, centerArgs, adminActivityArgs) = time == 0
? ("sa_player_ban_message_perm", "sa_admin_ban_message_perm",
@ -129,8 +123,7 @@ public partial class CS2_SimpleAdmin
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
var matches = Helper.GetPlayerFromSteamid64(steamid.SteamId64.ToString());
var player = matches.Count == 1 ? matches.FirstOrDefault() : null;
var player = Helper.GetPlayerFromSteamid64(steamid.SteamId64.ToString());
if (player != null && player.IsValid)
{
@ -184,8 +177,7 @@ public partial class CS2_SimpleAdmin
? PlayersInfo[caller.UserId.Value]
: null;
var matches = Helper.GetPlayerFromSteamid64(steamid);
var player = matches.Count == 1 ? matches.FirstOrDefault() : null;
var player = Helper.GetPlayerFromSteamid64(steamid);
if (player != null && player.IsValid)
{
@ -247,8 +239,7 @@ public partial class CS2_SimpleAdmin
? PlayersInfo[caller.UserId.Value]
: null;
var matches = Helper.GetPlayerFromIp(ipAddress);
var player = matches.Count == 1 ? matches.FirstOrDefault() : null;
var player = Helper.GetPlayerFromIp(ipAddress);
if (player != null && player.IsValid)
{
@ -366,10 +357,10 @@ public partial class CS2_SimpleAdmin
: (_localizer?["sa_console"] ?? "Console");
// Freeze player pawn if alive
if (player.PawnIsAlive)
if (player.PlayerPawn?.Value?.LifeState == (int)LifeState_t.LIFE_ALIVE)
{
player.Pawn.Value?.Freeze();
AddTimer(5.0f, () => player.Pawn.Value?.Unfreeze(), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
player.PlayerPawn?.Value?.Freeze();
AddTimer(5.0f, () => player.PlayerPawn?.Value?.Unfreeze(), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
// Get player and admin information
@ -442,8 +433,7 @@ public partial class CS2_SimpleAdmin
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
var matches = Helper.GetPlayerFromSteamid64(steamid.SteamId64.ToString());
var player = matches.Count == 1 ? matches.FirstOrDefault() : null;
var player = Helper.GetPlayerFromSteamid64(steamid.SteamId64.ToString());
if (player != null && player.IsValid)
{

View file

@ -100,7 +100,6 @@ public partial class CS2_SimpleAdmin
var utf8String = Encoding.UTF8.GetString(utf8BytesString);
Helper.LogCommand(caller, command);
Helper.PrintToCenterAll(utf8String.ReplaceColorTags());
}

View file

@ -386,20 +386,21 @@ public partial class CS2_SimpleAdmin
command.ReplyToCommand("Reloaded sql admins and groups");
}
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
[RequiresPermissions("@css/root")]
public void OnRelBans(CCSPlayerController? caller, CommandInfo command)
{
if (Database == null) return;
_ = Instance.CacheManager?.ForceReInitializeCacheAsync();
command.ReplyToCommand("Reloaded bans");
}
public void ReloadAdmins(CCSPlayerController? caller)
{
if (Database == null) return;
for (var index = 0; index < PermissionManager.AdminCache.Keys.ToList().Count; index++)
{
var steamId = PermissionManager.AdminCache.Keys.ToList()[index];
if (!PermissionManager.AdminCache.TryRemove(steamId, out _)) continue;
AdminManager.ClearPlayerPermissions(steamId);
AdminManager.RemovePlayerAdminData(steamId);
}
if(!Config.IsCSSPanel)
{
Task.Run(async () =>
@ -413,11 +414,11 @@ public partial class CS2_SimpleAdmin
await Server.NextWorldUpdateAsync(() =>
{
if (!string.IsNullOrEmpty(adminsFile))
AddTimer(1.8f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
AddTimer(1.3f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
if (!string.IsNullOrEmpty(groupsFile))
AddTimer(2.5f, () => AdminManager.LoadAdminGroups(ModuleDirectory + "/data/groups.json"));
if (!string.IsNullOrEmpty(adminsFile))
AddTimer(3.0f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
AddTimer(3.5f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
_logger?.LogInformation("Loaded admins!");
});
@ -445,8 +446,8 @@ public partial class CS2_SimpleAdmin
{
Server.ExecuteCommand("sv_disable_teamselect_menu 1");
if (caller.PlayerPawn.Value != null && caller.PawnIsAlive)
caller.PlayerPawn.Value.CommitSuicide(true, false);
if (caller.PlayerPawn?.Value?.LifeState == (int)LifeState_t.LIFE_ALIVE)
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);
@ -520,6 +521,10 @@ public partial class CS2_SimpleAdmin
printMethod($"• Total Mutes: \"{playerInfo.TotalMutes}\"");
printMethod($"• Total Silences: \"{playerInfo.TotalSilences}\"");
printMethod($"• Total Warns: \"{playerInfo.TotalWarns}\"");
var chunkedAccounts = playerInfo.AccountsAssociated.ChunkBy(3).ToList();
foreach (var chunk in chunkedAccounts)
printMethod($"• Associated Accounts: \"{string.Join(", ", chunk.Select(a => $"{a.PlayerName} ({a.SteamId})"))}\"");
}
printMethod($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------");
@ -661,7 +666,6 @@ public partial class CS2_SimpleAdmin
Helper.LogCommand(caller, command);
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, IsBot: false }).ToList();
if (playersToTarget.Count > 1)
return;
@ -719,20 +723,20 @@ public partial class CS2_SimpleAdmin
if (caller != null)
{
caller.PrintToConsole("--------- PLAYER LIST ---------");
playersToTarget.ForEach(player =>
foreach (var player in playersToTarget)
{
caller.PrintToConsole(
$"• [#{player.UserId}] \"{player.PlayerName}\" (IP Address: \"{(AdminManager.PlayerHasPermissions(new SteamID(caller.SteamID), "@css/showip") ? player.IpAddress?.Split(":")[0] : "Unknown")}\" SteamID64: \"{player.SteamID}\")");
});
};
caller.PrintToConsole("--------- END PLAYER LIST ---------");
}
else
{
Server.PrintToConsole("--------- PLAYER LIST ---------");
playersToTarget.ForEach(player =>
foreach (var player in playersToTarget)
{
Server.PrintToConsole($"• [#{player.UserId}] \"{player.PlayerName}\" (IP Address: \"{player.IpAddress?.Split(":")[0]}\" SteamID64: \"{player.SteamID}\")");
});
};
Server.PrintToConsole("--------- END PLAYER LIST ---------");
}
}
@ -800,6 +804,8 @@ public partial class CS2_SimpleAdmin
Kick(caller, player, reason, callerName, command);
}
});
Helper.LogCommand(caller, command);
}
public void Kick(CCSPlayerController? caller, CCSPlayerController player, string? reason = "Unknown", string? callerName = null, CommandInfo? command = null)
@ -839,8 +845,6 @@ public partial class CS2_SimpleAdmin
// Log the command and send Discord notification
if (command == null)
Helper.LogCommand(caller, $"css_kick {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)} {reason}");
else
Helper.LogCommand(caller, command);
SimpleAdminApi?.OnPlayerPenaltiedEvent(playerInfo, adminInfo, PenaltyType.Kick, reason, -1, null);
}

View file

@ -114,8 +114,7 @@ public partial class CS2_SimpleAdmin
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
var matches = Helper.GetPlayerFromSteamid64(steamid.SteamId64.ToString());
var player = matches.Count == 1 ? matches.FirstOrDefault() : null;
var player = Helper.GetPlayerFromSteamid64(steamid.SteamId64.ToString());
if (player != null && player.IsValid)
{
@ -173,8 +172,7 @@ public partial class CS2_SimpleAdmin
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
// Attempt to match player based on SteamID
var matches = Helper.GetPlayerFromSteamid64(steamid);
var player = matches.Count == 1 ? matches.FirstOrDefault() : null;
var player = Helper.GetPlayerFromSteamid64(steamid);
if (player != null && player.IsValid)
{
@ -230,8 +228,7 @@ public partial class CS2_SimpleAdmin
// Check if pattern is a valid SteamID64
if (Helper.ValidateSteamId(pattern, out var steamId) && steamId != null)
{
var matches = Helper.GetPlayerFromSteamid64(steamId.SteamId64.ToString());
var player = matches.Count == 1 ? matches.FirstOrDefault() : null;
var player = Helper.GetPlayerFromSteamid64(steamId.SteamId64.ToString());
if (player != null && player.IsValid)
{
@ -407,8 +404,7 @@ public partial class CS2_SimpleAdmin
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
// Attempt to match player based on SteamID
var matches = Helper.GetPlayerFromSteamid64(steamid);
var player = matches.Count == 1 ? matches.FirstOrDefault() : null;
var player = Helper.GetPlayerFromSteamid64(steamid);
if (player != null && player.IsValid)
{
@ -448,8 +444,7 @@ public partial class CS2_SimpleAdmin
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
var matches = Helper.GetPlayerFromSteamid64(steamid.SteamId64.ToString());
var player = matches.Count == 1 ? matches.FirstOrDefault() : null;
var player = Helper.GetPlayerFromSteamid64(steamid.SteamId64.ToString());
if (player != null && player.IsValid)
{
@ -499,8 +494,7 @@ public partial class CS2_SimpleAdmin
// Check if pattern is a valid SteamID64
if (Helper.ValidateSteamId(pattern, out var steamId) && steamId != null)
{
var matches = Helper.GetPlayerFromSteamid64(steamId.SteamId64.ToString());
var player = matches.Count == 1 ? matches.FirstOrDefault() : null;
var player = Helper.GetPlayerFromSteamid64(steamId.SteamId64.ToString());
if (player != null && player.IsValid)
{
@ -681,8 +675,7 @@ public partial class CS2_SimpleAdmin
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
// Attempt to match player based on SteamID
var matches = Helper.GetPlayerFromSteamid64(steamid);
var player = matches.Count == 1 ? matches.FirstOrDefault() : null;
var player = Helper.GetPlayerFromSteamid64(steamid);
if (player != null && player.IsValid)
{
@ -722,8 +715,7 @@ public partial class CS2_SimpleAdmin
var adminInfo = caller != null && caller.UserId.HasValue ? PlayersInfo[caller.UserId.Value] : null;
var matches = Helper.GetPlayerFromSteamid64(steamid.SteamId64.ToString());
var player = matches.Count == 1 ? matches.FirstOrDefault() : null;
var player = Helper.GetPlayerFromSteamid64(steamid.SteamId64.ToString());
if (player != null && player.IsValid)
{
@ -773,8 +765,7 @@ public partial class CS2_SimpleAdmin
// Check if pattern is a valid SteamID64
if (Helper.ValidateSteamId(pattern, out var steamId) && steamId != null)
{
var matches = Helper.GetPlayerFromSteamid64(steamId.SteamId64.ToString());
var player = matches.Count == 1 ? matches.FirstOrDefault() : null;
var player = Helper.GetPlayerFromSteamid64(steamId.SteamId64.ToString());
if (player != null && player.IsValid)
{

View file

@ -18,7 +18,7 @@ public partial class CS2_SimpleAdmin
if (targets == null) return;
var playersToTarget = targets.Players.Where(player =>
player.IsValid &&
player is { PawnIsAlive: true, IsHLTV: false, Connected: PlayerConnectedState.PlayerConnected }).ToList();
player is { IsHLTV: false, Connected: PlayerConnectedState.PlayerConnected, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).ToList();
playersToTarget.ForEach(player =>
{
@ -27,6 +27,8 @@ public partial class CS2_SimpleAdmin
NoClip(caller, player, callerName);
}
});
Helper.LogCommand(caller, command);
}
internal static void NoClip(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null, CommandInfo? command = null)
@ -53,13 +55,7 @@ public partial class CS2_SimpleAdmin
// Log the command
if (command == null)
{
Helper.LogCommand(caller, $"css_noclip {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)}");
}
else
{
Helper.LogCommand(caller, command);
}
}
[RequiresPermissions("@css/cheats")]
@ -70,7 +66,7 @@ public partial class CS2_SimpleAdmin
var targets = GetTarget(command);
if (targets == null) return;
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { PawnIsAlive: true, IsHLTV: false }).ToList();
var playersToTarget = targets.Players.Where(player => player.IsValid && player is {IsHLTV: false, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).ToList();
playersToTarget.ForEach(player =>
{
@ -82,6 +78,8 @@ public partial class CS2_SimpleAdmin
God(caller, player, command);
}
});
Helper.LogCommand(caller, command);
}
internal static void God(CCSPlayerController? caller, CCSPlayerController player, CommandInfo? command = null)
@ -100,8 +98,6 @@ public partial class CS2_SimpleAdmin
// Log the command
if (command == null)
Helper.LogCommand(caller, $"css_god {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)}");
else
Helper.LogCommand(caller, command);
// Determine message key and arguments for the god mode notification
var (activityMessageKey, adminActivityArgs) =
@ -124,7 +120,7 @@ public partial class 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();
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, IsHLTV: false, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).ToList();
playersToTarget.ForEach(player =>
{
@ -133,6 +129,8 @@ public partial class CS2_SimpleAdmin
Freeze(caller, player, time, callerName, command);
}
});
Helper.LogCommand(caller, command);
}
[CommandHelper(1, "<#userid or name> [size]")]
@ -144,7 +142,7 @@ public partial class 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();
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, IsHLTV: false, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).ToList();
playersToTarget.ForEach(player =>
{
@ -206,8 +204,6 @@ public partial class CS2_SimpleAdmin
// Log the command and send Discord notification
if (command == null)
Helper.LogCommand(caller, $"css_freeze {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)} {time}");
else
Helper.LogCommand(caller, command);
}
[CommandHelper(1, "<#userid or name>")]
@ -218,12 +214,14 @@ public partial class 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();
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, IsHLTV: false, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).ToList();
playersToTarget.ForEach(player =>
{
Unfreeze(caller, player, callerName, command);
});
Helper.LogCommand(caller, command);
}
internal static void Unfreeze(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null, CommandInfo? command = null)
@ -251,7 +249,5 @@ public partial class CS2_SimpleAdmin
// Log the command and send Discord notification
if (command == null)
Helper.LogCommand(caller, $"css_unfreeze {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)}");
else
Helper.LogCommand(caller, command);
}
}

View file

@ -22,12 +22,14 @@ public partial class CS2_SimpleAdmin
var targets = GetTarget(command);
if (targets == null) return;
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { PawnIsAlive: true, IsHLTV: false }).ToList();
var playersToTarget = targets.Players.Where(player => player.IsValid && player is {IsHLTV: false, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).ToList();
playersToTarget.ForEach(player =>
{
Slay(caller, player, callerName, command);
});
Helper.LogCommand(caller, command);
}
internal static void Slay(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null, CommandInfo? command = null)
@ -55,8 +57,6 @@ public partial class CS2_SimpleAdmin
// Log the command and send Discord notification
if (command == null)
Helper.LogCommand(caller, $"css_slay {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)}");
else
Helper.LogCommand(caller, command);
}
[RequiresPermissions("@css/cheats")]
@ -67,7 +67,7 @@ public partial class CS2_SimpleAdmin
var targets = GetTarget(command);
if (targets == null) return;
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { PawnIsAlive: true, IsHLTV: false }).ToList();
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { IsHLTV: false, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).ToList();
var weaponName = command.GetArg(2);
// check if item is typed
@ -94,6 +94,8 @@ public partial class CS2_SimpleAdmin
GiveWeapon(caller, player, weaponName, callerName, command);
});
Helper.LogCommand(caller, command);
}
private static void GiveWeapon(CCSPlayerController? caller, CCSPlayerController player, string weaponName, string? callerName = null, CommandInfo? command = null)
@ -122,8 +124,6 @@ public partial class CS2_SimpleAdmin
// Log the command
if (command == null)
Helper.LogCommand(caller, $"css_giveweapon {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)} {weaponName}");
else
Helper.LogCommand(caller, command);
// Determine message keys and arguments for the weapon give notification
var (activityMessageKey, adminActivityArgs) =
@ -150,8 +150,6 @@ public partial class CS2_SimpleAdmin
// Log the command
if (command == null)
Helper.LogCommand(caller, $"css_giveweapon {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)} {weapon.ToString()}");
else
Helper.LogCommand(caller, command);
// Determine message keys and arguments for the weapon give notification
var (activityMessageKey, adminActivityArgs) =
@ -173,7 +171,7 @@ public partial class CS2_SimpleAdmin
var targets = GetTarget(command);
if (targets == null) return;
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { PawnIsAlive: true, IsHLTV: false }).ToList();
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { IsHLTV: false, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).ToList();
playersToTarget.ForEach(player =>
{
@ -182,6 +180,8 @@ public partial class CS2_SimpleAdmin
StripWeapons(caller, player, callerName, command);
}
});
Helper.LogCommand(caller, command);
}
internal static void StripWeapons(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null, CommandInfo? command = null)
@ -192,7 +192,7 @@ public partial class CS2_SimpleAdmin
callerName ??= caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console";
// Check if player is valid, alive, and connected
if (!player.IsValid || !player.PawnIsAlive || player.Connected != PlayerConnectedState.PlayerConnected)
if (!player.IsValid || player.PlayerPawn?.Value?.LifeState != (int)LifeState_t.LIFE_ALIVE || player.Connected != PlayerConnectedState.PlayerConnected)
return;
// Strip weapons from the player
@ -201,8 +201,6 @@ public partial class CS2_SimpleAdmin
// Log the command
if (command == null)
Helper.LogCommand(caller, $"css_strip {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)}");
else
Helper.LogCommand(caller, command);
// Determine message keys and arguments for the weapon strip notification
var (activityMessageKey, adminActivityArgs) =
@ -225,7 +223,7 @@ public partial class CS2_SimpleAdmin
var targets = GetTarget(command);
if (targets == null) return;
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { PawnIsAlive: true, IsHLTV: false }).ToList();
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { IsHLTV: false, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).ToList();
playersToTarget.ForEach(player =>
{
@ -234,6 +232,8 @@ public partial class CS2_SimpleAdmin
SetHp(caller, player, health, command);
}
});
Helper.LogCommand(caller, command);
}
internal static void SetHp(CCSPlayerController? caller, CCSPlayerController player, int health, CommandInfo? command = null)
@ -250,8 +250,6 @@ public partial class CS2_SimpleAdmin
// Log the command
if (command == null)
Helper.LogCommand(caller, $"css_hp {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)} {health}");
else
Helper.LogCommand(caller, command);
// Determine message keys and arguments for the HP set notification
var (activityMessageKey, adminActivityArgs) =
@ -274,7 +272,7 @@ public partial class CS2_SimpleAdmin
var targets = GetTarget(command);
if (targets == null) return;
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { PawnIsAlive: true, IsHLTV: false }).ToList();
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { IsHLTV: false, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).ToList();
playersToTarget.ForEach(player =>
{
@ -286,6 +284,8 @@ public partial class CS2_SimpleAdmin
SetSpeed(caller, player, speed, command);
}
});
Helper.LogCommand(caller, command);
}
internal static void SetSpeed(CCSPlayerController? caller, CCSPlayerController player, float speed, CommandInfo? command = null)
@ -306,8 +306,6 @@ public partial class CS2_SimpleAdmin
// Log the command
if (command == null)
Helper.LogCommand(caller, $"css_speed {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)} {speed}");
else
Helper.LogCommand(caller, command);
// Determine message keys and arguments for the speed set notification
var (activityMessageKey, adminActivityArgs) =
@ -330,7 +328,7 @@ public partial class CS2_SimpleAdmin
var targets = GetTarget(command);
if (targets == null) return;
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { PawnIsAlive: true, IsHLTV: false }).ToList();
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { IsHLTV: false, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).ToList();
playersToTarget.ForEach(player =>
{
@ -342,6 +340,8 @@ public partial class CS2_SimpleAdmin
SetGravity(caller, player, gravity, command);
}
});
Helper.LogCommand(caller, command);
}
internal static void SetGravity(CCSPlayerController? caller, CCSPlayerController player, float gravity, CommandInfo? command = null)
@ -362,8 +362,6 @@ public partial class CS2_SimpleAdmin
// Log the command
if (command == null)
Helper.LogCommand(caller, $"css_gravity {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)} {gravity}");
else
Helper.LogCommand(caller, command);
// Determine message keys and arguments for the gravity set notification
var (activityMessageKey, adminActivityArgs) =
@ -387,7 +385,7 @@ public partial class CS2_SimpleAdmin
var targets = GetTarget(command);
if (targets == null) return;
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { PawnIsAlive: true, IsHLTV: false }).ToList();
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { IsHLTV: false, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).ToList();
playersToTarget.ForEach(player =>
{
@ -399,6 +397,8 @@ public partial class CS2_SimpleAdmin
SetMoney(caller, player, money, command);
}
});
Helper.LogCommand(caller, command);
}
internal static void SetMoney(CCSPlayerController? caller, CCSPlayerController player, int money, CommandInfo? command = null)
@ -414,8 +414,6 @@ public partial class CS2_SimpleAdmin
// Log the command
if (command == null)
Helper.LogCommand(caller, $"css_money {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)} {money}");
else
Helper.LogCommand(caller, command);
// Determine message keys and arguments for the money set notification
var (activityMessageKey, adminActivityArgs) =
@ -438,7 +436,7 @@ public partial class CS2_SimpleAdmin
var targets = GetTarget(command);
if (targets == null) return;
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { PawnIsAlive: true, IsHLTV: false }).ToList();
var playersToTarget = targets.Players.Where(player => player.IsValid && player is { IsHLTV: false, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).ToList();
if (command.ArgCount >= 2)
{
@ -455,6 +453,8 @@ public partial class CS2_SimpleAdmin
Slap(caller, player, damage, command);
}
});
Helper.LogCommand(caller, command);
}
internal static void Slap(CCSPlayerController? caller, CCSPlayerController player, int damage, CommandInfo? command = null)
@ -470,9 +470,7 @@ public partial class CS2_SimpleAdmin
// Log the command
if (command == null)
Helper.LogCommand(caller, $"css_slap {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)} {damage}");
else
Helper.LogCommand(caller, command);
// Determine message key and arguments for the slap notification
var (activityMessageKey, adminActivityArgs) =
("sa_admin_slap_message",
@ -532,6 +530,8 @@ public partial class CS2_SimpleAdmin
{
ChangeTeam(caller, player, _teamName, teamNum, kill, command);
});
Helper.LogCommand(caller, command);
}
internal static void ChangeTeam(CCSPlayerController? caller, CCSPlayerController player, string teamName, CsTeam teamNum, bool kill, CommandInfo? command = null)
@ -549,7 +549,7 @@ public partial class CS2_SimpleAdmin
// Change team based on the provided teamName and conditions
if (!teamName.Equals("swap", StringComparison.OrdinalIgnoreCase))
{
if (player.PawnIsAlive && teamNum != CsTeam.Spectator && !kill && Instance.Config.OtherSettings.TeamSwitchType == 1)
if (player.PlayerPawn?.Value?.LifeState == (int)LifeState_t.LIFE_ALIVE && teamNum != CsTeam.Spectator && !kill && Instance.Config.OtherSettings.TeamSwitchType == 1)
player.SwitchTeam(teamNum);
else
player.ChangeTeam(teamNum);
@ -560,7 +560,7 @@ public partial class CS2_SimpleAdmin
{
var _teamNum = (CsTeam)player.TeamNum == CsTeam.Terrorist ? CsTeam.CounterTerrorist : CsTeam.Terrorist;
teamName = _teamNum == CsTeam.Terrorist ? "TT" : "CT";
if (player.PawnIsAlive && !kill && Instance.Config.OtherSettings.TeamSwitchType == 1)
if (player.PlayerPawn?.Value?.LifeState == (int)LifeState_t.LIFE_ALIVE && !kill && Instance.Config.OtherSettings.TeamSwitchType == 1)
player.SwitchTeam(_teamNum);
else
player.ChangeTeam(_teamNum);
@ -570,8 +570,6 @@ public partial class CS2_SimpleAdmin
// Log the command
if (command == null)
Helper.LogCommand(caller, $"css_team {player.PlayerName} {teamName}");
else
Helper.LogCommand(caller, command);
// Determine message key and arguments for the team change notification
var activityMessageKey = "sa_admin_team_message";
@ -698,6 +696,8 @@ public partial class CS2_SimpleAdmin
Respawn(caller, player, callerName, command);
}
});
Helper.LogCommand(caller, command);
}
internal static void Respawn(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null, CommandInfo? command = null)
@ -722,8 +722,6 @@ public partial class CS2_SimpleAdmin
// Log the command
if (command == null)
Helper.LogCommand(caller, $"css_respawn {(string.IsNullOrEmpty(player.PlayerName) ? player.SteamID.ToString() : player.PlayerName)}");
else
Helper.LogCommand(caller, command);
// Determine message key and arguments for the respawn notification
var activityMessageKey = "sa_admin_respawn_message";
@ -740,7 +738,7 @@ public partial class CS2_SimpleAdmin
public void OnGotoCommand(CCSPlayerController? caller, CommandInfo command)
{
// Check if the caller is valid and has a live pawn
if (caller == null || !caller.PawnIsAlive) return;
if (caller == null || caller.PlayerPawn?.Value?.LifeState != (int)LifeState_t.LIFE_ALIVE) return;
// Get the target players
var targets = GetTarget(command);
@ -754,7 +752,7 @@ public partial class CS2_SimpleAdmin
Helper.LogCommand(caller, command);
// Process each player to teleport
foreach (var player in playersToTarget.Where(player => player is { Connected: PlayerConnectedState.PlayerConnected, PawnIsAlive: true }).Where(caller.CanTarget))
foreach (var player in playersToTarget.Where(player => player is { Connected: PlayerConnectedState.PlayerConnected, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).Where(caller.CanTarget))
{
if (caller.PlayerPawn.Value == null || player.PlayerPawn.Value == null)
continue;
@ -778,7 +776,7 @@ public partial class CS2_SimpleAdmin
// Set a timer to toggle collision back after 4 seconds
AddTimer(4, () =>
{
if (!caller.IsValid || !caller.PawnIsAlive)
if (!caller.IsValid || caller.PlayerPawn?.Value?.LifeState != (int)LifeState_t.LIFE_ALIVE)
return;
caller.PlayerPawn.Value.Collision.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_PLAYER;
@ -811,7 +809,8 @@ public partial class CS2_SimpleAdmin
public void OnBringCommand(CCSPlayerController? caller, CommandInfo command)
{
// Check if the caller is valid and has a live pawn
if (caller == null || !caller.PawnIsAlive) return;
if (caller == null || caller.PlayerPawn?.Value?.LifeState != (int)LifeState_t.LIFE_ALIVE)
return;
// Get the target players
var targets = GetTarget(command);
@ -825,7 +824,7 @@ public partial class CS2_SimpleAdmin
Helper.LogCommand(caller, command);
// Process each player to teleport
foreach (var player in playersToTarget.Where(player => player is { Connected: PlayerConnectedState.PlayerConnected, PawnIsAlive: true }).Where(caller.CanTarget))
foreach (var player in playersToTarget.Where(player => player is { Connected: PlayerConnectedState.PlayerConnected, PlayerPawn.Value.LifeState: (int)LifeState_t.LIFE_ALIVE }).Where(caller.CanTarget))
{
if (caller.PlayerPawn.Value == null || player.PlayerPawn.Value == null)
continue;
@ -849,7 +848,7 @@ public partial class CS2_SimpleAdmin
// Set a timer to toggle collision back after 4 seconds
AddTimer(4, () =>
{
if (!player.IsValid || !player.PawnIsAlive)
if (!player.IsValid || player.PlayerPawn?.Value?.LifeState != (int)LifeState_t.LIFE_ALIVE)
return;
caller.PlayerPawn.Value.Collision.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_PLAYER;