mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-17 18:39:07 +00:00
1.4.7a
- Fixed crash when using command on invalid player - Using banid command to reduce number of queries to database (only if unlock commands enabled in css config) - Minor changes
This commit is contained in:
@@ -18,12 +18,14 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
|
||||
public static IStringLocalizer? _localizer;
|
||||
public static readonly Dictionary<string, int> VoteAnswers = [];
|
||||
private static readonly ConcurrentBag<int> GodPlayers = [];
|
||||
private static readonly ConcurrentBag<int> SilentPlayers = [];
|
||||
private static readonly HashSet<int> GodPlayers = [];
|
||||
private static readonly HashSet<int> SilentPlayers = [];
|
||||
//private static readonly ConcurrentBag<int> SilentPlayers = [];
|
||||
private static readonly ConcurrentBag<string> BannedPlayers = [];
|
||||
private static bool _tagsDetected;
|
||||
public static bool VoteInProgress = false;
|
||||
public static int? ServerId = null;
|
||||
public static bool UnlockedCommands = CoreConfig.UnlockConCommands;
|
||||
|
||||
public static DiscordWebhookClient? DiscordWebhookClientLog;
|
||||
public static DiscordWebhookClient? DiscordWebhookClientPenalty;
|
||||
@@ -37,7 +39,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
public override string ModuleName => "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)");
|
||||
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
|
||||
public override string ModuleAuthor => "daffyy & Dliix66";
|
||||
public override string ModuleVersion => "1.4.6b";
|
||||
public override string ModuleVersion => "1.4.7a";
|
||||
|
||||
public CS2_SimpleAdminConfig Config { get; set; } = new();
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.243" />
|
||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.244" />
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="Discord.Net.Webhook" Version="3.15.0" />
|
||||
<PackageReference Include="Discord.Net.Webhook" Version="3.15.1" />
|
||||
<PackageReference Include="MySqlConnector" Version="2.3.7" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="*" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Core.Translations;
|
||||
using CounterStrikeSharp.API.Modules.Admin;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
using CounterStrikeSharp.API.Modules.Entities;
|
||||
using System.Text;
|
||||
|
||||
namespace CS2_SimpleAdmin
|
||||
@@ -22,7 +24,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
var targets = GetTarget(command);
|
||||
if (targets == null) return;
|
||||
var playersToTarget = targets.Players.Where(player => player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList();
|
||||
var playersToTarget = targets.Players.Where(player => player.IsValid && player.Connected == PlayerConnectedState.PlayerConnected && !player.IsHLTV).ToList();
|
||||
|
||||
if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0)
|
||||
{
|
||||
@@ -91,7 +93,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
if (time == 0)
|
||||
{
|
||||
if (!player.IsBot && !player.IsHLTV)
|
||||
if (player is { IsBot: false })
|
||||
using (new WithTemporaryCulture(player.GetLanguage()))
|
||||
{
|
||||
player.PrintToCenter(_localizer!["sa_player_ban_message_perm", reason, caller == null ? "Console" : caller.PlayerName]);
|
||||
@@ -112,7 +114,7 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!player.IsBot && !player.IsHLTV)
|
||||
if (!player.IsBot)
|
||||
using (new WithTemporaryCulture(player.GetLanguage()))
|
||||
{
|
||||
player.PrintToCenter(_localizer!["sa_player_ban_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]);
|
||||
@@ -131,6 +133,9 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
}
|
||||
|
||||
if (UnlockedCommands)
|
||||
Server.ExecuteCommand($"banid 2 {new SteamID(player.SteamID).SteamId3}");
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
Helper.LogCommand(caller, command);
|
||||
@@ -147,11 +152,11 @@ namespace CS2_SimpleAdmin
|
||||
if (_database == null) return;
|
||||
|
||||
var callerName = caller == null ? "Console" : caller.PlayerName;
|
||||
|
||||
if (command.ArgCount < 2)
|
||||
return;
|
||||
if (string.IsNullOrEmpty(command.GetArg(1))) return;
|
||||
|
||||
|
||||
if (!Helper.ValidateSteamId(command.GetArg(1), out var steamId) || steamId == null)
|
||||
{
|
||||
command.ReplyToCommand($"Invalid SteamID64.");
|
||||
@@ -248,6 +253,8 @@ 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}");
|
||||
|
||||
command.ReplyToCommand($"Banned player with steamid {steamid}.");
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
var targets = GetTarget(command);
|
||||
if (targets == null) return;
|
||||
var playersToTarget = targets.Players.Where(player => player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList();
|
||||
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, IsHLTV: false }).ToList();
|
||||
|
||||
//Helper.LogCommand(caller, command);
|
||||
|
||||
|
||||
@@ -345,7 +345,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
if (SilentPlayers.Contains(caller.Slot))
|
||||
{
|
||||
RemoveFromConcurrentBag(SilentPlayers, caller.Slot);
|
||||
SilentPlayers.Remove(caller.Slot);
|
||||
caller.PrintToChat($"You aren't hidden now!");
|
||||
caller.ChangeTeam(CsTeam.Spectator);
|
||||
}
|
||||
@@ -377,7 +377,7 @@ namespace CS2_SimpleAdmin
|
||||
Helper.LogCommand(caller, command);
|
||||
//Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer);
|
||||
|
||||
var playersToTarget = targets.Players.Where(player => player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList();
|
||||
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, IsHLTV: false }).ToList();
|
||||
|
||||
Database.Database database = new(_dbConnectionString);
|
||||
BanManager banManager = new(database, Config);
|
||||
@@ -410,7 +410,7 @@ namespace CS2_SimpleAdmin
|
||||
printMethod($"• UserID: \"{playerInfo.UserId}\"");
|
||||
if (playerInfo.SteamId != null)
|
||||
printMethod($"• SteamID64: \"{playerInfo.SteamId}\"");
|
||||
if (player.SteamID.ToString().Length == 17)
|
||||
if (player.Connected == PlayerConnectedState.PlayerConnected)
|
||||
{
|
||||
printMethod($"• SteamID2: \"{player.SteamID}\"");
|
||||
printMethod($"• Community link: \"{new SteamID(player.SteamID).ToCommunityUrl()}\"");
|
||||
@@ -418,7 +418,7 @@ namespace CS2_SimpleAdmin
|
||||
if (playerInfo.IpAddress != null && AdminManager.PlayerHasPermissions(caller, "@css/showip"))
|
||||
printMethod($"• IP Address: \"{playerInfo.IpAddress}\"");
|
||||
printMethod($"• Ping: \"{player.Ping}\"");
|
||||
if (player.SteamID.ToString().Length == 17)
|
||||
if (player.Connected == PlayerConnectedState.PlayerConnected)
|
||||
{
|
||||
printMethod($"• Total Bans: \"{totalBans}\"");
|
||||
printMethod($"• Total Mutes: \"{totalMutes}\"");
|
||||
@@ -508,9 +508,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
var targets = GetTarget(command);
|
||||
|
||||
if (targets == null)
|
||||
return;
|
||||
|
||||
if (targets == null) return;
|
||||
var playersToTarget = targets.Players
|
||||
.Where(player => player is { IsValid: true, IsHLTV: false }).ToList();
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
var targets = GetTarget(command);
|
||||
if (targets == null) return;
|
||||
var playersToTarget = targets.Players.Where(player => player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList();
|
||||
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, IsHLTV: false }).ToList();
|
||||
|
||||
if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0)
|
||||
{
|
||||
@@ -77,7 +77,7 @@ namespace CS2_SimpleAdmin
|
||||
PlayerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Gag, DateTime.Now.AddMinutes(time), time);
|
||||
if (time == 0)
|
||||
{
|
||||
if (!player.IsBot && !player.IsHLTV)
|
||||
if (!player.IsBot)
|
||||
{
|
||||
using (new WithTemporaryCulture(player.GetLanguage()))
|
||||
{
|
||||
@@ -100,7 +100,7 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!player.IsBot && !player.IsHLTV)
|
||||
if (!player.IsBot)
|
||||
{
|
||||
using (new WithTemporaryCulture(player.GetLanguage()))
|
||||
{
|
||||
@@ -179,7 +179,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
if (time == 0)
|
||||
{
|
||||
if (!player.IsBot && !player.IsHLTV)
|
||||
if (!player.IsBot)
|
||||
using (new WithTemporaryCulture(player.GetLanguage()))
|
||||
{
|
||||
player.PrintToCenter(_localizer!["sa_player_gag_message_perm", reason, caller == null ? "Console" : caller.PlayerName]);
|
||||
@@ -265,7 +265,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
var pattern = command.GetArg(1);
|
||||
MuteManager muteManager = new(_database);
|
||||
|
||||
|
||||
if (Helper.ValidateSteamId(pattern, out var steamId) && steamId != null)
|
||||
{
|
||||
var matches = Helper.GetPlayerFromSteamid64(steamId.SteamId64.ToString());
|
||||
@@ -321,7 +321,7 @@ namespace CS2_SimpleAdmin
|
||||
/*
|
||||
TargetResult? targets = GetTarget(command);
|
||||
if (targets == null) return;
|
||||
List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => player!= null && player.IsValid && player.SteamID.ToString().Length == 17 &&!player.IsHLTV).ToList();
|
||||
List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => player!= null && player.IsValid && player.Connected == PlayerConnectedState.PlayerConnected &&!player.IsHLTV).ToList();
|
||||
|
||||
if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0)
|
||||
{
|
||||
@@ -361,7 +361,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
var targets = GetTarget(command);
|
||||
if (targets == null) return;
|
||||
var playersToTarget = targets.Players.Where(player => player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList();
|
||||
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, IsHLTV: false }).ToList();
|
||||
|
||||
if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0)
|
||||
{
|
||||
@@ -416,7 +416,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
if (time == 0)
|
||||
{
|
||||
if (!player.IsBot && !player.IsHLTV)
|
||||
if (!player.IsBot)
|
||||
using (new WithTemporaryCulture(player.GetLanguage()))
|
||||
{
|
||||
player.PrintToCenter(_localizer!["sa_player_mute_message_perm", reason, caller == null ? "Console" : caller.PlayerName]);
|
||||
@@ -474,7 +474,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
if (command.ArgCount < 2)
|
||||
return;
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(command.GetArg(1))) return;
|
||||
|
||||
if (!Helper.ValidateSteamId(command.GetArg(1), out var steamId) || steamId == null)
|
||||
@@ -644,7 +644,7 @@ namespace CS2_SimpleAdmin
|
||||
/*
|
||||
TargetResult? targets = GetTarget(command);
|
||||
if (targets == null) return;
|
||||
List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => player!= null && player.IsValid && player.SteamID.ToString().Length == 17 &&!player.IsHLTV).ToList();
|
||||
List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => player!= null && player.IsValid && player.Connected == PlayerConnectedState.PlayerConnected &&!player.IsHLTV).ToList();
|
||||
|
||||
if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0)
|
||||
{
|
||||
@@ -655,7 +655,7 @@ namespace CS2_SimpleAdmin
|
||||
{
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
if (player.SteamID.ToString().Length == 17)
|
||||
if (player.Connected == PlayerConnectedState.PlayerConnected)
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await _muteManager.UnmutePlayer(player.SteamID.ToString(), 1); // Unmute by type 1 (mute)
|
||||
@@ -679,7 +679,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
var targets = GetTarget(command);
|
||||
if (targets == null) return;
|
||||
var playersToTarget = targets.Players.Where(player => player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList();
|
||||
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, IsHLTV: false }).ToList();
|
||||
|
||||
if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0)
|
||||
{
|
||||
@@ -759,7 +759,7 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!player.IsBot && !player.IsHLTV)
|
||||
if (!player.IsBot)
|
||||
{
|
||||
using (new WithTemporaryCulture(player.GetLanguage()))
|
||||
{
|
||||
@@ -782,7 +782,7 @@ 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);
|
||||
@@ -974,7 +974,7 @@ namespace CS2_SimpleAdmin
|
||||
/*
|
||||
TargetResult? targets = GetTarget(command);
|
||||
if (targets == null) return;
|
||||
List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => player!= null && player.IsValid && player.SteamID.ToString().Length == 17 &&!player.IsHLTV).ToList();
|
||||
List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => player!= null && player.IsValid && player.Connected == PlayerConnectedState.PlayerConnected &&!player.IsHLTV).ToList();
|
||||
|
||||
if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0)
|
||||
{
|
||||
@@ -985,7 +985,7 @@ namespace CS2_SimpleAdmin
|
||||
{
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
if (player.SteamID.ToString().Length == 17)
|
||||
if (player.Connected == PlayerConnectedState.PlayerConnected)
|
||||
Task.Run(async () => { await _muteManager.UnmutePlayer(player.SteamID.ToString(), 2); }); // Unmute by type 2 (silence)
|
||||
|
||||
if (TagsDetected)
|
||||
|
||||
@@ -17,9 +17,11 @@ namespace CS2_SimpleAdmin
|
||||
var callerName = caller == null ? "Console" : caller.PlayerName;
|
||||
|
||||
var targets = GetTarget(command);
|
||||
var playersToTarget = targets!.Players.Where(player =>
|
||||
player.IsValid && player.SteamID.ToString().Length == 17 &&
|
||||
player is { PawnIsAlive: true, IsHLTV: false }).ToList();
|
||||
if (targets == null) return;
|
||||
var playersToTarget = targets.Players.Where(player =>
|
||||
player is not null &&
|
||||
player.IsValid &&
|
||||
player is { PawnIsAlive: true, IsHLTV: false, Connected: PlayerConnectedState.PlayerConnected }).ToList();
|
||||
|
||||
Helper.SendDiscordLogMessage(caller, command, DiscordWebhookClientLog, _localizer);
|
||||
|
||||
@@ -60,13 +62,14 @@ namespace CS2_SimpleAdmin
|
||||
int.TryParse(command.GetArg(2), out var time);
|
||||
|
||||
var targets = GetTarget(command);
|
||||
var playersToTarget = targets!.Players.Where(player => player is { IsValid: true, PawnIsAlive: true, IsHLTV: false }).ToList();
|
||||
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 (!player.IsBot && player.SteamID.ToString().Length != 17)
|
||||
if (!player.IsBot && player.Connected == PlayerConnectedState.PlayerConnected)
|
||||
return;
|
||||
|
||||
if (caller!.CanTarget(player))
|
||||
@@ -107,11 +110,12 @@ namespace CS2_SimpleAdmin
|
||||
var callerName = caller == null ? "Console" : caller.PlayerName;
|
||||
|
||||
var targets = GetTarget(command);
|
||||
var playersToTarget = targets!.Players.Where(player => player is { IsValid: true, PawnIsAlive: true, IsHLTV: false }).ToList();
|
||||
if (targets == null) return;
|
||||
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, PawnIsAlive: true, IsHLTV: false }).ToList();
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
if (!player.IsBot && player.SteamID.ToString().Length != 17)
|
||||
if (!player.IsBot && player.Connected == PlayerConnectedState.PlayerConnected)
|
||||
return;
|
||||
|
||||
Unfreeze(caller, player, callerName, command);
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
public void Slay(CCSPlayerController? caller, CCSPlayerController? player, string? callerName = null, CommandInfo? command = null)
|
||||
{
|
||||
if (player != null && !player.IsBot && player.SteamID.ToString().Length != 17)
|
||||
if (player == null || !player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected)
|
||||
return;
|
||||
|
||||
callerName ??= caller == null ? "Console" : caller.PlayerName;
|
||||
@@ -94,7 +94,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
if (!player.IsBot && player.SteamID.ToString().Length != 17)
|
||||
if (player.Connected != PlayerConnectedState.PlayerConnected)
|
||||
return;
|
||||
|
||||
GiveWeapon(caller, player, weaponName, callerName, command);
|
||||
@@ -161,10 +161,10 @@ namespace CS2_SimpleAdmin
|
||||
{
|
||||
callerName ??= caller == null ? "Console" : caller.PlayerName;
|
||||
|
||||
if (player != null && !player.IsBot && player.SteamID.ToString().Length != 17)
|
||||
if (player == null || !player.IsValid || !player.PawnIsAlive || player.Connected != PlayerConnectedState.PlayerConnected)
|
||||
return;
|
||||
|
||||
player?.RemoveWeapons();
|
||||
player.RemoveWeapons();
|
||||
|
||||
if (command != null)
|
||||
{
|
||||
@@ -207,7 +207,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
public void SetHp(CCSPlayerController? caller, CCSPlayerController? player, int health, CommandInfo? command = null)
|
||||
{
|
||||
if (player != null && !player.IsBot && player.SteamID.ToString().Length != 17)
|
||||
if (player != null && !player.IsBot && player.Connected == PlayerConnectedState.PlayerConnected)
|
||||
return;
|
||||
|
||||
var callerName = caller == null ? "Console" : caller.PlayerName;
|
||||
@@ -247,7 +247,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
if (!player.IsBot && player.SteamID.ToString().Length != 17)
|
||||
if (player.Connected != PlayerConnectedState.PlayerConnected)
|
||||
return;
|
||||
|
||||
if (caller!.CanTarget(player))
|
||||
@@ -298,7 +298,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
if (!player.IsBot && player.SteamID.ToString().Length != 17)
|
||||
if (player.Connected != PlayerConnectedState.PlayerConnected)
|
||||
return;
|
||||
|
||||
if (caller!.CanTarget(player))
|
||||
@@ -347,7 +347,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
if (!player.IsBot && player.SteamID.ToString().Length != 17)
|
||||
if (player.Connected != PlayerConnectedState.PlayerConnected)
|
||||
return;
|
||||
|
||||
if (caller!.CanTarget(player))
|
||||
@@ -394,7 +394,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
if (!player.IsBot && player.SteamID.ToString().Length != 17)
|
||||
if (player.Connected != PlayerConnectedState.PlayerConnected)
|
||||
return;
|
||||
|
||||
if (caller!.CanTarget(player))
|
||||
@@ -421,7 +421,7 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveFromConcurrentBag(GodPlayers, player.Slot);
|
||||
GodPlayers.Remove(player.Slot);
|
||||
}
|
||||
|
||||
if (caller != null && SilentPlayers.Contains(caller.Slot)) return;
|
||||
@@ -455,7 +455,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
if (!player.IsBot && player.SteamID.ToString().Length != 17)
|
||||
if (player.Connected != PlayerConnectedState.PlayerConnected)
|
||||
return;
|
||||
|
||||
if (caller!.CanTarget(player))
|
||||
@@ -538,21 +538,21 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
public void ChangeTeam(CCSPlayerController? caller, CCSPlayerController? player, string teamName, CsTeam teamNum, bool kill, string? callerName = null, CommandInfo? command = null)
|
||||
{
|
||||
if (player != null && !player.IsBot && player.SteamID.ToString().Length != 17)
|
||||
if (player == null || !player.IsValid || player.Connected != PlayerConnectedState.PlayerConnected)
|
||||
return;
|
||||
|
||||
callerName ??= caller == null ? "Console" : caller.PlayerName;
|
||||
|
||||
if (!teamName.Equals("swap"))
|
||||
{
|
||||
if (player != null && player.PawnIsAlive && teamNum != CsTeam.Spectator && !kill && Config.TeamSwitchType == 1)
|
||||
if (player.PawnIsAlive && teamNum != CsTeam.Spectator && !kill && Config.TeamSwitchType == 1)
|
||||
player.SwitchTeam(teamNum);
|
||||
else
|
||||
player?.ChangeTeam(teamNum);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player != null && player.TeamNum != (byte)CsTeam.Spectator)
|
||||
if (player.TeamNum != (byte)CsTeam.Spectator)
|
||||
{
|
||||
var _teamNum = (CsTeam)player.TeamNum == CsTeam.Terrorist ? CsTeam.CounterTerrorist : CsTeam.Terrorist;
|
||||
teamName = _teamNum == CsTeam.Terrorist ? "TT" : "CT";
|
||||
@@ -597,14 +597,15 @@ namespace CS2_SimpleAdmin
|
||||
return;
|
||||
|
||||
var targets = GetTarget(command);
|
||||
var playersToTarget = targets!.Players.Where(player => player is { IsValid: true, IsHLTV: false }).ToList();
|
||||
if (targets == null) return;
|
||||
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 =>
|
||||
{
|
||||
if (!player.IsBot && player.SteamID.ToString().Length != 17)
|
||||
if (player.Connected != PlayerConnectedState.PlayerConnected)
|
||||
return;
|
||||
|
||||
if (!caller!.CanTarget(player)) return;
|
||||
@@ -633,11 +634,12 @@ namespace CS2_SimpleAdmin
|
||||
var callerName = caller == null ? "Console" : caller.PlayerName;
|
||||
|
||||
var targets = GetTarget(command);
|
||||
var playersToTarget = targets!.Players.Where(player => player is { IsValid: true, IsHLTV: false }).ToList();
|
||||
if (targets == null) return;
|
||||
var playersToTarget = targets.Players.Where(player => player is { IsValid: true, IsHLTV: false }).ToList();
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
if (!player.IsBot && player.SteamID.ToString().Length != 17)
|
||||
if (player.Connected != PlayerConnectedState.PlayerConnected)
|
||||
return;
|
||||
|
||||
if (caller!.CanTarget(player))
|
||||
@@ -697,7 +699,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
if (!player.IsBot && player.SteamID.ToString().Length != 17 || !player.PawnIsAlive)
|
||||
if (player.Connected != PlayerConnectedState.PlayerConnected || !player.PawnIsAlive)
|
||||
return;
|
||||
|
||||
if (!caller.CanTarget(player)) return;
|
||||
@@ -742,7 +744,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
if (!player.IsBot && player.SteamID.ToString().Length != 17 || !player.PawnIsAlive)
|
||||
if (player.Connected != PlayerConnectedState.PlayerConnected || !player.PawnIsAlive)
|
||||
return;
|
||||
|
||||
if (!caller.CanTarget(player)) return;
|
||||
|
||||
66
Events.cs
66
Events.cs
@@ -24,7 +24,7 @@ public partial class CS2_SimpleAdmin
|
||||
{
|
||||
AddTimer(8.5f, () =>
|
||||
{
|
||||
if (ServerId != null) return;
|
||||
if (ServerId != null || _database == null) return;
|
||||
|
||||
var ipAddress = ConVar.Find("ip")?.StringValue;
|
||||
|
||||
@@ -106,7 +106,7 @@ public partial class CS2_SimpleAdmin
|
||||
Logger.LogCritical("[OnClientDisconnect] Before");
|
||||
#endif
|
||||
|
||||
if (player == null || !player.IsValid || string.IsNullOrEmpty(player.IpAddress) || player.IsBot)
|
||||
if (player == null || !player.IsValid || player.IsBot)
|
||||
{
|
||||
return HookResult.Continue;
|
||||
}
|
||||
@@ -119,19 +119,10 @@ public partial class CS2_SimpleAdmin
|
||||
PlayerPenaltyManager.RemoveAllPenalties(player.Slot);
|
||||
|
||||
if (_tagsDetected)
|
||||
{
|
||||
Server.ExecuteCommand($"css_tag_unmute {player.SteamID}");
|
||||
}
|
||||
|
||||
if (SilentPlayers.Contains(player.Slot))
|
||||
{
|
||||
RemoveFromConcurrentBag(SilentPlayers, player.Slot);
|
||||
}
|
||||
|
||||
if (GodPlayers.Contains(player.Slot))
|
||||
{
|
||||
RemoveFromConcurrentBag(GodPlayers, player.Slot);
|
||||
}
|
||||
SilentPlayers.Remove(player.Slot);
|
||||
GodPlayers.Remove(player.Slot);
|
||||
|
||||
var authorizedSteamId = player.AuthorizedSteamID;
|
||||
if (authorizedSteamId == null || !PermissionManager.AdminCache.TryGetValue(authorizedSteamId,
|
||||
@@ -196,18 +187,27 @@ public partial class CS2_SimpleAdmin
|
||||
if (isBanned)
|
||||
{
|
||||
// Add player's IP and SteamID to bannedPlayers list if not already present
|
||||
if (Config.BanType > 0 && playerInfo.IpAddress != null && !BannedPlayers.Contains(playerInfo.IpAddress))
|
||||
if (Config.BanType > 0 && playerInfo.IpAddress != null &&
|
||||
!BannedPlayers.Contains(playerInfo.IpAddress))
|
||||
{
|
||||
BannedPlayers.Add(playerInfo.IpAddress);
|
||||
}
|
||||
|
||||
if (playerInfo.SteamId != null && !BannedPlayers.Contains(playerInfo.SteamId))
|
||||
{
|
||||
BannedPlayers.Add(playerInfo.SteamId);
|
||||
}
|
||||
|
||||
// Kick the player if banned
|
||||
await Server.NextFrameAsync(() =>
|
||||
{
|
||||
var victim = Utilities.GetPlayerFromUserid(playerInfo.UserId);
|
||||
|
||||
if (victim?.UserId != null)
|
||||
{
|
||||
if (UnlockedCommands)
|
||||
Server.ExecuteCommand($"banid 2 {playerInfo.UserId}");
|
||||
|
||||
Helper.KickPlayer(victim.UserId.Value, "Banned");
|
||||
}
|
||||
});
|
||||
@@ -281,7 +281,7 @@ public partial class CS2_SimpleAdmin
|
||||
|
||||
public HookResult OnCommandSay(CCSPlayerController? player, CommandInfo info)
|
||||
{
|
||||
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV)
|
||||
if (player is null || !player.IsValid || player.IsBot)
|
||||
return HookResult.Continue;
|
||||
|
||||
if (info.GetArg(1).StartsWith($"/")
|
||||
@@ -299,7 +299,7 @@ public partial class CS2_SimpleAdmin
|
||||
|
||||
public HookResult OnCommandTeamSay(CCSPlayerController? player, CommandInfo info)
|
||||
{
|
||||
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV)
|
||||
if (player is null || !player.IsValid || player.IsBot)
|
||||
return HookResult.Continue;
|
||||
|
||||
if (info.GetArg(1).StartsWith($"/")
|
||||
@@ -464,31 +464,35 @@ public partial class CS2_SimpleAdmin
|
||||
|
||||
await Server.NextFrameAsync(() =>
|
||||
{
|
||||
try
|
||||
if (onlinePlayers.Count > 0)
|
||||
{
|
||||
foreach (var player in players.Where(player => PlayerPenaltyManager.IsSlotInPenalties(player.Slot)))
|
||||
try
|
||||
{
|
||||
if (!PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) && !PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
||||
foreach (var player in players.Where(player => PlayerPenaltyManager.IsSlotInPenalties(player.Slot)))
|
||||
{
|
||||
if (!PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) && !PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
||||
player.VoiceFlags = VoiceFlags.Normal;
|
||||
|
||||
if (!PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) && !PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
||||
{
|
||||
if (_tagsDetected)
|
||||
Server.ExecuteCommand($"css_tag_unmute {player.SteamID}");
|
||||
}
|
||||
|
||||
if (PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence) ||
|
||||
PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) ||
|
||||
PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag)) continue;
|
||||
player.VoiceFlags = VoiceFlags.Normal;
|
||||
|
||||
if (!PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) && !PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
||||
{
|
||||
if (_tagsDetected)
|
||||
Server.ExecuteCommand($"css_tag_unmute {player.SteamID}");
|
||||
}
|
||||
|
||||
if (PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence) ||
|
||||
PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) ||
|
||||
PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag)) continue;
|
||||
player.VoiceFlags = VoiceFlags.Normal;
|
||||
|
||||
if (_tagsDetected)
|
||||
Server.ExecuteCommand($"css_tag_unmute {player.SteamID}");
|
||||
PlayerPenaltyManager.RemoveExpiredPenalties();
|
||||
}
|
||||
|
||||
PlayerPenaltyManager.RemoveExpiredPenalties();
|
||||
catch { }
|
||||
}
|
||||
catch { }
|
||||
|
||||
});
|
||||
});
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT | CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
|
||||
Reference in New Issue
Block a user