From ee72f451f43d6e74e966a42eb0eb7ee1c7082bfa Mon Sep 17 00:00:00 2001 From: Vespura <31419184+TomGrobbe@users.noreply.github.com> Date: Sat, 4 Dec 2021 21:11:48 +0100 Subject: [PATCH] Fix Staff Only (cached) permission checks when setting up the initial menus. Also remove unnecessary if check --- SharedClasses/PermissionsManager.cs | 30 +++++++++++------------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/SharedClasses/PermissionsManager.cs b/SharedClasses/PermissionsManager.cs index f0f8d62e..1f2b6ced 100644 --- a/SharedClasses/PermissionsManager.cs +++ b/SharedClasses/PermissionsManager.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -379,9 +379,9 @@ private static bool IsAllowedClient(Permission permission, bool checkAnyway) if (ArePermissionsSetup || checkAnyway) { bool staffPermissionAllowed = ( - allowedPerms.ContainsKey(Permission.Staff) && allowedPerms[Permission.Staff] + Permissions.ContainsKey(Permission.Staff) && Permissions[Permission.Staff] ) || ( - allowedPerms.ContainsKey(Permission.Everything) && allowedPerms[Permission.Everything] + Permissions.ContainsKey(Permission.Everything) && Permissions[Permission.Everything] ); // Return false immediately if the staff only convar is set and the user is not a staff member. if (ConfigManager.GetSettingsBool(ConfigManager.Setting.vmenu_menu_staff_only) && !staffPermissionAllowed) @@ -389,12 +389,10 @@ private static bool IsAllowedClient(Permission permission, bool checkAnyway) return false; } - if (allowedPerms.ContainsKey(permission)) - { - return allowedPerms[permission]; - } - - allowedPerms[permission] = false; + if (allowedPerms.ContainsKey(permission) && allowedPerms[permission]) + return true; + else if (!allowedPerms.ContainsKey(permission)) + allowedPerms[permission] = false; // Get a list of all permissions that are (parents) of the current permission, including the current permission. List permissionsToCheck = GetPermissionAndParentPermissions(permission); @@ -406,8 +404,6 @@ private static bool IsAllowedClient(Permission permission, bool checkAnyway) return true; } } - - // Return false if nothing is allowed. return false; } #endif @@ -541,15 +537,11 @@ public static void SetPermissionsForPlayer([FromSource]Player player) /// public static void SetPermissions(string permissions) { - if (!IsDuplicityVersion()) + Permissions = Newtonsoft.Json.JsonConvert.DeserializeObject>(permissions); + // if debug logging. + if (GetResourceMetadata(GetCurrentResourceName(), "client_debug_mode", 0) == "true") { - Permissions = Newtonsoft.Json.JsonConvert.DeserializeObject>(permissions); - // if debug logging. - if (GetResourceMetadata(GetCurrentResourceName(), "client_debug_mode", 0) == "true") - { - Debug.WriteLine("[vMenu] [Permissions] " + Newtonsoft.Json.JsonConvert.SerializeObject(Permissions, Newtonsoft.Json.Formatting.None)); - } - + Debug.WriteLine("[vMenu] [Permissions] " + Newtonsoft.Json.JsonConvert.SerializeObject(Permissions, Newtonsoft.Json.Formatting.None)); } } #endif