Skip to content

Commit

Permalink
1.7.0a
Browse files Browse the repository at this point in the history
- Fixed css_warn (unfreeze player after 5s)
- Fixed server loading from database (reduced delay)
- Added checking the player in an earlier phase of the connection
- Fixed admin name when using action from menu
  • Loading branch information
daffyyyy committed Dec 16, 2024
1 parent 8c94a86 commit 8af8056
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 25 deletions.
4 changes: 2 additions & 2 deletions CS2-SimpleAdmin/CS2-SimpleAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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.6.9c";
public override string ModuleVersion => "1.7.0a";

public override void Load(bool hotReload)
{
Expand Down Expand Up @@ -94,7 +94,7 @@ public void OnConfigParsed(CS2_SimpleAdminConfig config)

DbConnectionString = builder.ConnectionString;
Database = new Database.Database(DbConnectionString);

if (!Database.CheckDatabaseConnection(out var exception))
{
if (exception != null)
Expand Down
9 changes: 7 additions & 2 deletions CS2-SimpleAdmin/Commands/basebans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ internal void Ban(CCSPlayerController? caller, CCSPlayerController player, int t
if (!CheckValidBan(caller, time)) return;

// Set default caller name if not provided
callerName ??= _localizer?["sa_console"] ?? "Console";
callerName = !string.IsNullOrEmpty(caller?.PlayerName)
? caller.PlayerName
: (_localizer?["sa_console"] ?? "Console");

// Freeze player pawn if alive
if (player.PawnIsAlive)
Expand Down Expand Up @@ -321,12 +323,15 @@ internal void Warn(CCSPlayerController? caller, CCSPlayerController player, int
if (!CheckValidBan(caller, time)) return;

// Set default caller name if not provided
callerName ??= _localizer?["sa_console"] ?? "Console";
callerName = !string.IsNullOrEmpty(caller?.PlayerName)
? caller.PlayerName
: (_localizer?["sa_console"] ?? "Console");

// Freeze player pawn if alive
if (player.PawnIsAlive)
{
player.Pawn.Value?.Freeze();
AddTimer(5.0f, () => player.Pawn.Value?.Unfreeze(), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}

// Get player and admin information
Expand Down
12 changes: 7 additions & 5 deletions CS2-SimpleAdmin/Commands/basecommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,18 +371,20 @@ public void ReloadAdmins(CCSPlayerController? caller)
{
await PermissionManager.CrateGroupsJsonFile();
await PermissionManager.CreateAdminsJsonFile();

var adminsFile = await File.ReadAllTextAsync(Instance.ModuleDirectory + "/data/admins.json");
var groupsFile = await File.ReadAllTextAsync(Instance.ModuleDirectory + "/data/groups.json");

await Server.NextWorldUpdateAsync(() =>
{
if (!string.IsNullOrEmpty(adminsFile))
AddTimer(0.5f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
AddTimer(1.8f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
if (!string.IsNullOrEmpty(groupsFile))
AddTimer(0.8f, () => AdminManager.LoadAdminGroups(ModuleDirectory + "/data/groups.json"));
AddTimer(2.5f, () => AdminManager.LoadAdminGroups(ModuleDirectory + "/data/groups.json"));
if (!string.IsNullOrEmpty(adminsFile))
AddTimer(1.1f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
AddTimer(3.0f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));

_logger?.LogInformation("Loaded admins!");
});
});

Expand Down
73 changes: 65 additions & 8 deletions CS2-SimpleAdmin/Commands/playercommands.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;
Expand Down Expand Up @@ -755,15 +756,43 @@ public void OnGotoCommand(CCSPlayerController? caller, CommandInfo command)
// Process each player to teleport
foreach (var player in playersToTarget.Where(player => player is { Connected: PlayerConnectedState.PlayerConnected, PawnIsAlive: true }).Where(caller.CanTarget))
{
if (caller.PlayerPawn.Value == null)
if (caller.PlayerPawn.Value == null || player.PlayerPawn.Value == null)
continue;

// Teleport the caller to the player and toggle noclip
caller.TeleportPlayer(player);
caller.PlayerPawn.Value.ToggleNoclip();
// caller.PlayerPawn.Value.ToggleNoclip();

// Set a timer to toggle noclip back after 3 seconds
AddTimer(3, () => caller.PlayerPawn.Value.ToggleNoclip());
caller.PlayerPawn.Value.Collision.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_DISSOLVING;
caller.PlayerPawn.Value.Collision.CollisionAttribute.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_DISSOLVING;

Utilities.SetStateChanged(caller, "CCollisionProperty", "m_CollisionGroup");
Utilities.SetStateChanged(caller, "VPhysicsCollisionAttribute_t", "m_nCollisionGroup");

player.PlayerPawn.Value.Collision.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_DISSOLVING;
player.PlayerPawn.Value.Collision.CollisionAttribute.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_DISSOLVING;

Utilities.SetStateChanged(player, "CCollisionProperty", "m_CollisionGroup");
Utilities.SetStateChanged(player, "VPhysicsCollisionAttribute_t", "m_nCollisionGroup");

// Set a timer to toggle collision back after 4 seconds
AddTimer(4, () =>
{
if (!caller.IsValid || !caller.PawnIsAlive)
return;

caller.PlayerPawn.Value.Collision.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_PLAYER;
caller.PlayerPawn.Value.Collision.CollisionAttribute.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_PLAYER;

Utilities.SetStateChanged(caller, "CCollisionProperty", "m_CollisionGroup");
Utilities.SetStateChanged(caller, "VPhysicsCollisionAttribute_t", "m_nCollisionGroup");

player.PlayerPawn.Value.Collision.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_PLAYER;
player.PlayerPawn.Value.Collision.CollisionAttribute.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_PLAYER;

Utilities.SetStateChanged(player, "CCollisionProperty", "m_CollisionGroup");
Utilities.SetStateChanged(player, "VPhysicsCollisionAttribute_t", "m_nCollisionGroup");
});

// Prepare message key and arguments for the teleport notification
var activityMessageKey = "sa_admin_tp_message";
Expand Down Expand Up @@ -798,15 +827,43 @@ public void OnBringCommand(CCSPlayerController? caller, CommandInfo command)
// Process each player to teleport
foreach (var player in playersToTarget.Where(player => player is { Connected: PlayerConnectedState.PlayerConnected, PawnIsAlive: true }).Where(caller.CanTarget))
{
if (caller.PlayerPawn.Value == null)
if (caller.PlayerPawn.Value == null || player.PlayerPawn.Value == null)
continue;

// Teleport the player to the caller and toggle noclip
player.TeleportPlayer(caller);
caller.PlayerPawn.Value.ToggleNoclip();
// caller.PlayerPawn.Value.ToggleNoclip();

caller.PlayerPawn.Value.Collision.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_DISSOLVING;
caller.PlayerPawn.Value.Collision.CollisionAttribute.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_DISSOLVING;

Utilities.SetStateChanged(caller, "CCollisionProperty", "m_CollisionGroup");
Utilities.SetStateChanged(caller, "VPhysicsCollisionAttribute_t", "m_nCollisionGroup");

player.PlayerPawn.Value.Collision.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_DISSOLVING;
player.PlayerPawn.Value.Collision.CollisionAttribute.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_DISSOLVING;

Utilities.SetStateChanged(player, "CCollisionProperty", "m_CollisionGroup");
Utilities.SetStateChanged(player, "VPhysicsCollisionAttribute_t", "m_nCollisionGroup");

// Set a timer to toggle noclip back after 3 seconds
AddTimer(3, () => caller.PlayerPawn.Value.ToggleNoclip());
// Set a timer to toggle collision back after 4 seconds
AddTimer(4, () =>
{
if (!player.IsValid || !player.PawnIsAlive)
return;

caller.PlayerPawn.Value.Collision.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_PLAYER;
caller.PlayerPawn.Value.Collision.CollisionAttribute.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_PLAYER;

Utilities.SetStateChanged(caller, "CCollisionProperty", "m_CollisionGroup");
Utilities.SetStateChanged(caller, "VPhysicsCollisionAttribute_t", "m_nCollisionGroup");

player.PlayerPawn.Value.Collision.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_PLAYER;
player.PlayerPawn.Value.Collision.CollisionAttribute.CollisionGroup = (byte)CollisionGroup.COLLISION_GROUP_PLAYER;

Utilities.SetStateChanged(player, "CCollisionProperty", "m_CollisionGroup");
Utilities.SetStateChanged(player, "VPhysicsCollisionAttribute_t", "m_nCollisionGroup");
});

// Prepare message key and arguments for the bring notification
var activityMessageKey = "sa_admin_bring_message";
Expand Down
22 changes: 22 additions & 0 deletions CS2-SimpleAdmin/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public partial class CS2_SimpleAdmin
private void RegisterEvents()
{
RegisterListener<Listeners.OnMapStart>(OnMapStart);
RegisterListener<Listeners.OnClientConnect>(OnClientConnect);
RegisterListener<Listeners.OnGameServerSteamAPIActivated>(OnGameServerSteamAPIActivated);
if (Config.OtherSettings.UserMessageGagChatType)
HookUserMessage(118, HookUmChat);
Expand Down Expand Up @@ -120,10 +121,31 @@ public HookResult OnClientDisconnect(EventPlayerDisconnect @event, GameEventInfo
return HookResult.Continue;
}
}

private void OnClientConnect(int playerslot, string name, string ipaddress)
{
#if DEBUG
Logger.LogCritical("[OnClientConnect]");
#endif

Server.NextFrame(() =>
{
var player = Utilities.GetPlayerFromSlot(playerslot);

if (player == null || !player.IsValid || player.IsBot)
return;

new PlayerManager().LoadPlayerData(player);
});
}

[GameEventHandler]
public HookResult OnPlayerFullConnect(EventPlayerConnectFull @event, GameEventInfo info)
{
#if DEBUG
Logger.LogCritical("[OnPlayerFullConnect]");
#endif

var player = @event.Userid;

if (player == null || !player.IsValid || player.IsBot)
Expand Down
2 changes: 1 addition & 1 deletion CS2-SimpleAdmin/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public static void ShowAdminActivity(string messageKey, string? callerName = nul
var arg = currentMessageArgs[i];
currentMessageArgs[i] = CS2_SimpleAdmin.Instance.Config.OtherSettings.ShowActivityType switch
{
1 => arg.Replace("CALLER", AdminManager.PlayerHasPermissions(controller, "@css/kick") || AdminManager.PlayerHasPermissions(controller, "@css/ban") ? callerName : CS2_SimpleAdmin._localizer["sa_admin"]),
1 => arg.Replace("CALLER", AdminManager.PlayerHasPermissions(new SteamID(controller.SteamID), "@css/kick") || AdminManager.PlayerHasPermissions(new SteamID(controller.SteamID), "@css/ban") ? callerName : CS2_SimpleAdmin._localizer["sa_admin"]),
2 => arg.Replace("CALLER", callerName ?? CS2_SimpleAdmin._localizer["sa_console"]),
_ => arg
};
Expand Down
2 changes: 1 addition & 1 deletion CS2-SimpleAdmin/Managers/PermissionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ ORDER BY sa_admins.player_steamid
// 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 = [];
List<(string, string, List<string>, int, DateTime?)> filteredFlagsWithImmunity = [];

// Add the grouped players to the list
filteredFlagsWithImmunity.AddRange(groupedPlayers);
Expand Down
2 changes: 1 addition & 1 deletion CS2-SimpleAdmin/Managers/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ await Server.NextFrameAsync(() =>
var victim = Utilities.GetPlayerFromUserid(userId);

if (victim == null || !victim.UserId.HasValue) return;

if (CS2_SimpleAdmin.UnlockedCommands)
Server.ExecuteCommand($"banid 1 {userId}");

Expand Down
2 changes: 1 addition & 1 deletion CS2-SimpleAdmin/Managers/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void LoadServerData()
{
ipAddress = Helper.GetServerIp();

if (_getIpTryCount <= 32)
if (_getIpTryCount <= 32 && (string.IsNullOrEmpty(ipAddress) || ipAddress.StartsWith("0.0.0")))
{
_getIpTryCount++;

Expand Down
6 changes: 3 additions & 3 deletions CS2-SimpleAdmin/Menus/ManagePlayersMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private static void Kick(CCSPlayerController admin, CCSPlayerController player,
{
if (player is not { IsValid: true }) return;

CS2_SimpleAdmin.Instance.Kick(admin, player, reason);
CS2_SimpleAdmin.Instance.Kick(admin, player, reason, admin.PlayerName);
}

internal static void BanMenu(CCSPlayerController admin, CCSPlayerController player, int duration)
Expand Down Expand Up @@ -180,7 +180,7 @@ private static void Ban(CCSPlayerController admin, CCSPlayerController player, i
{
if (player is not { IsValid: true }) return;

CS2_SimpleAdmin.Instance.Ban(admin, player, duration, reason);
CS2_SimpleAdmin.Instance.Ban(admin, player, duration, reason, admin.PlayerName);
}

private static void WarnMenu(CCSPlayerController admin, CCSPlayerController player, int duration)
Expand Down Expand Up @@ -210,7 +210,7 @@ private static void Warn(CCSPlayerController admin, CCSPlayerController player,
{
if (player is not { IsValid: true }) return;

CS2_SimpleAdmin.Instance.Warn(admin, player, duration, reason);
CS2_SimpleAdmin.Instance.Warn(admin, player, duration, reason, admin.PlayerName);
}

internal static void GagMenu(CCSPlayerController admin, CCSPlayerController player, int duration)
Expand Down
2 changes: 1 addition & 1 deletion CS2-SimpleAdmin/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.9c
1.7.0a

0 comments on commit 8af8056

Please sign in to comment.