Skip to content

Commit

Permalink
Fix Staff Only (cached) permission checks when setting up the initial…
Browse files Browse the repository at this point in the history
… menus.

Also remove unnecessary if check
  • Loading branch information
TomGrobbe committed Dec 4, 2021
1 parent 9b658c8 commit ee72f45
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions SharedClasses/PermissionsManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -379,22 +379,20 @@ 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)
{
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<Permission> permissionsToCheck = GetPermissionAndParentPermissions(permission);
Expand All @@ -406,8 +404,6 @@ private static bool IsAllowedClient(Permission permission, bool checkAnyway)
return true;
}
}

// Return false if nothing is allowed.
return false;
}
#endif
Expand Down Expand Up @@ -541,15 +537,11 @@ public static void SetPermissionsForPlayer([FromSource]Player player)
/// <param name="permissions"></param>
public static void SetPermissions(string permissions)
{
if (!IsDuplicityVersion())
Permissions = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<Permission, bool>>(permissions);
// if debug logging.
if (GetResourceMetadata(GetCurrentResourceName(), "client_debug_mode", 0) == "true")
{
Permissions = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<Permission, bool>>(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
Expand Down

0 comments on commit ee72f45

Please sign in to comment.