Add permission override support for menus
Menus can now specify a command name for permission override checking, allowing server admins to control menu visibility via CounterStrikeSharp's admin system. Updated API, MenuManager, and FunCommands module to support this feature. Also updated slap command to emit a sound, fixed SQL migration for IP address type, and bumped version to 1.7.8-beta-2.
This commit is contained in:
parent
78318102fe
commit
206c18db66
12 changed files with 94 additions and 27 deletions
|
|
@ -206,9 +206,9 @@ public class CS2_SimpleAdminApi : ICS2_SimpleAdminApi
|
|||
}
|
||||
|
||||
public void RegisterMenu(string categoryId, string menuId, string menuName,
|
||||
Func<CCSPlayerController, object> menuFactory, string? permission = null)
|
||||
Func<CCSPlayerController, object> menuFactory, string? permission = null, string? commandName = null)
|
||||
{
|
||||
Menus.MenuManager.Instance.RegisterMenu(categoryId, menuId, menuName, BuilderFactory, permission);
|
||||
Menus.MenuManager.Instance.RegisterMenu(categoryId, menuId, menuName, BuilderFactory, permission, commandName);
|
||||
return;
|
||||
|
||||
MenuBuilder BuilderFactory(CCSPlayerController player)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,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.7.8-beta-1";
|
||||
public override string ModuleVersion => "1.7.8-beta-2";
|
||||
|
||||
public override void Load(bool hotReload)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ public partial class CS2_SimpleAdmin
|
|||
|
||||
// Apply slap damage to the player
|
||||
player.Pawn.Value?.Slap(damage);
|
||||
player.EmitSound("BaseGrenade.JumpThrowM");
|
||||
|
||||
// Log the command
|
||||
if (command == null)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
CREATE TABLE IF NOT EXISTS `sa_players_ips` (
|
||||
`steamid` INTEGER NOT NULL,
|
||||
`address` VARCHAR(64) NOT NULL,
|
||||
`address` INTEGER NOT NULL
|
||||
`used_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`steamid`, `address`)
|
||||
);
|
||||
|
|
@ -1,9 +1,4 @@
|
|||
DELETE FROM `sa_players_ips`
|
||||
WHERE `id` NOT IN (
|
||||
SELECT MIN(`id`)
|
||||
FROM `sa_players_ips`
|
||||
GROUP BY `steamid`
|
||||
);
|
||||
TRUNCATE TABLE `sa_players_ips`;
|
||||
|
||||
ALTER TABLE `sa_players_ips` ADD `name` VARCHAR(64) NULL DEFAULT NULL;
|
||||
CREATE INDEX IF NOT EXISTS `idx_sa_players_ips_used_at` ON `sa_players_ips` (`used_at` DESC);
|
||||
|
|
@ -46,7 +46,8 @@ public class MenuManager
|
|||
/// <param name="menuName">Display name of the menu.</param>
|
||||
/// <param name="menuFactory">Factory function that creates the menu for a player.</param>
|
||||
/// <param name="permission">Required permission to access this menu (optional).</param>
|
||||
public void RegisterMenu(string categoryId, string menuId, string menuName, Func<CCSPlayerController, MenuBuilder> menuFactory, string? permission = null)
|
||||
/// <param name="commandName">Command name for permission override checking (optional, e.g., "css_god").</param>
|
||||
public void RegisterMenu(string categoryId, string menuId, string menuName, Func<CCSPlayerController, MenuBuilder> menuFactory, string? permission = null, string? commandName = null)
|
||||
{
|
||||
if (!_menuCategories.ContainsKey(categoryId))
|
||||
{
|
||||
|
|
@ -59,6 +60,10 @@ public class MenuManager
|
|||
{
|
||||
_menuCategories[categoryId].MenuPermissions[menuId] = permission;
|
||||
}
|
||||
if (commandName != null)
|
||||
{
|
||||
_menuCategories[categoryId].MenuCommandNames[menuId] = commandName;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -72,6 +77,7 @@ public class MenuManager
|
|||
category.MenuFactories.Remove(menuId);
|
||||
_menuCategories[categoryId].MenuNames.Remove(menuId);
|
||||
_menuCategories[categoryId].MenuPermissions.Remove(menuId);
|
||||
_menuCategories[categoryId].MenuCommandNames.Remove(menuId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -116,11 +122,39 @@ public class MenuManager
|
|||
var menuFactory = kvp.Value;
|
||||
var menuName = category.MenuNames.TryGetValue(menuId, out var name) ? name : menuId;
|
||||
var permission = category.MenuPermissions.TryGetValue(menuId, out var perm) ? perm : null;
|
||||
var commandName = category.MenuCommandNames.TryGetValue(menuId, out var cmd) ? cmd : null;
|
||||
|
||||
// Check permissions
|
||||
if (!string.IsNullOrEmpty(permission))
|
||||
// Check permissions with command override support
|
||||
var steamId = new SteamID(player.SteamID);
|
||||
|
||||
// If commandName is provided, check for permission overrides
|
||||
if (!string.IsNullOrEmpty(commandName))
|
||||
{
|
||||
bool hasPermission;
|
||||
|
||||
// Check if command has overridden permissions
|
||||
if (AdminManager.CommandIsOverriden(commandName))
|
||||
{
|
||||
var overriddenPermission = AdminManager.GetPermissionOverrides(commandName);
|
||||
hasPermission = AdminManager.PlayerHasPermissions(steamId, overriddenPermission);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(permission))
|
||||
{
|
||||
// Use default permission if no override exists
|
||||
hasPermission = AdminManager.PlayerHasPermissions(steamId, permission);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No permission required
|
||||
hasPermission = true;
|
||||
}
|
||||
|
||||
if (!hasPermission)
|
||||
continue;
|
||||
}
|
||||
// Fallback to standard permission check if no commandName provided
|
||||
else if (!string.IsNullOrEmpty(permission))
|
||||
{
|
||||
var steamId = new SteamID(player.SteamID);
|
||||
if (!AdminManager.PlayerHasPermissions(steamId, permission))
|
||||
continue;
|
||||
}
|
||||
|
|
@ -187,4 +221,5 @@ public class MenuCategory
|
|||
public Dictionary<string, Func<CCSPlayerController, MenuBuilder>> MenuFactories { get; set; } = [];
|
||||
public Dictionary<string, string> MenuNames { get; set; } = [];
|
||||
public Dictionary<string, string> MenuPermissions { get; set; } = [];
|
||||
public Dictionary<string, string> MenuCommandNames { get; set; } = [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
1.7.8-beta-1
|
||||
1.7.8-beta-2
|
||||
Loading…
Add table
Add a link
Reference in a new issue