Skip to content

Commit

Permalink
Merge branch 'TomGrobbe:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
NickReagan authored Aug 13, 2023
2 parents 7b510d4 + f2daf43 commit 0148559
Show file tree
Hide file tree
Showing 46 changed files with 4,815 additions and 4,072 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ csharp_style_conditional_delegate_call = true
csharp_prefer_static_local_function = true
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async
csharp_style_prefer_readonly_struct = true
csharp_style_prefer_readonly_struct_member = true

# Code-block preferences
csharp_prefer_braces = true:suggestion
Expand Down
10 changes: 0 additions & 10 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Tom Grobbe - https://www.vespura.com/

Copyright © 2017-2022
Copyright © 2017-2023

You can use and edit this code to your liking as long as you don't ever claim it to be your own code and always provide proper credit.
You're **not** allowed to sell vMenu or any code you take from it.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ vMenu v2.0.0 and earlier was [using a modified version of NativeUI](https://gith

Tom Grobbe - https://www.vespura.com/

Copyright © 2017-2022
Copyright © 2017-2023

You can use and edit this code to your liking as long as you don't ever claim it to be your own code and always provide proper credit.
You're **not** allowed to sell vMenu or any code you take from it.
Expand Down
17 changes: 11 additions & 6 deletions SharedClasses/ConfigManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System;
using System.Collections.Generic;

using CitizenFX.Core;

using Newtonsoft.Json;


using static CitizenFX.Core.Native.API;

namespace vMenuShared
Expand All @@ -28,11 +29,15 @@ public enum Setting
vmenu_disable_spawning_as_default_character,
vmenu_enable_animals_spawn_menu,
vmenu_pvp_mode,
keep_player_head_props,
vmenu_disable_server_info_convars,
vmenu_player_names_distance,
vmenu_disable_entity_outlines_tool,
vmenu_disable_player_stats_setup,

// Vehicle Chameleon Colours
vmenu_using_chameleon_colours,

// Kick & ban settings
vmenu_default_ban_message_information,
vmenu_auto_ban_cheaters,
Expand Down Expand Up @@ -75,10 +80,10 @@ public static bool GetSettingsBool(Setting setting)
/// <returns></returns>
public static int GetSettingsInt(Setting setting)
{
int convarInt = GetConvarInt(setting.ToString(), -1);
var convarInt = GetConvarInt(setting.ToString(), -1);
if (convarInt == -1)
{
if (int.TryParse(GetConvar(setting.ToString(), "-1"), out int convarIntAlt))
if (int.TryParse(GetConvar(setting.ToString(), "-1"), out var convarIntAlt))
{
return convarIntAlt;
}
Expand All @@ -93,7 +98,7 @@ public static int GetSettingsInt(Setting setting)
/// <returns></returns>
public static float GetSettingsFloat(Setting setting)
{
if (float.TryParse(GetConvar(setting.ToString(), "-1.0"), out float result))
if (float.TryParse(GetConvar(setting.ToString(), "-1.0"), out var result))
{
return result;
}
Expand Down Expand Up @@ -145,9 +150,9 @@ public static bool IsClientDebugModeEnabled()
/// <returns></returns>
public static Locations GetLocations()
{
Locations data = new Locations();
var data = new Locations();

string jsonFile = LoadResourceFile(GetCurrentResourceName(), "config/locations.json");
var jsonFile = LoadResourceFile(GetCurrentResourceName(), "config/locations.json");
try
{
if (string.IsNullOrEmpty(jsonFile))
Expand Down
33 changes: 20 additions & 13 deletions SharedClasses/PermissionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ public enum Permission
WPCandyCane,
WPRailgunXM3,
WPAcidPackage,
WPTecPistol,
#endregion

// Weapon Loadouts Menu
Expand Down Expand Up @@ -374,7 +375,7 @@ public enum Permission
/// <param name="source"></param>
/// <param name="checkAnyway">if true, then the permissions will be checked even if they aren't setup yet.</param>
/// <returns></returns>
public static bool IsAllowed(Permission permission, Player source, bool checkAnyway = false) => IsAllowedServer(permission, source);
public static bool IsAllowed(Permission permission, Player source) => IsAllowedServer(permission, source);
#endif

#if CLIENT
Expand All @@ -386,7 +387,7 @@ public enum Permission
/// <returns></returns>
public static bool IsAllowed(Permission permission, bool checkAnyway = false) => IsAllowedClient(permission, checkAnyway);

private static Dictionary<Permission, bool> allowedPerms = new Dictionary<Permission, bool>();
private static readonly Dictionary<Permission, bool> allowedPerms = new();
/// <summary>
/// Private function that handles client side permission requests.
/// </summary>
Expand All @@ -396,7 +397,7 @@ private static bool IsAllowedClient(Permission permission, bool checkAnyway)
{
if (ArePermissionsSetup || checkAnyway)
{
bool staffPermissionAllowed = (
var staffPermissionAllowed = (
Permissions.ContainsKey(Permission.Staff) && Permissions[Permission.Staff]
) || (
Permissions.ContainsKey(Permission.Everything) && Permissions[Permission.Everything]
Expand All @@ -408,12 +409,16 @@ private static bool IsAllowedClient(Permission permission, bool checkAnyway)
}

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);
var permissionsToCheck = GetPermissionAndParentPermissions(permission);

// Check if any of those permissions is allowed, if so, return true.
if (permissionsToCheck.Any(p => Permissions.ContainsKey(p) && Permissions[p]))
Expand Down Expand Up @@ -447,7 +452,7 @@ private static bool IsAllowedServer(Permission permission, Player source)
}
#endif

private static Dictionary<Permission, List<Permission>> parentPermissions = new Dictionary<Permission, List<Permission>>();
private static readonly Dictionary<Permission, List<Permission>> parentPermissions = new();

/// <summary>
/// Gets the current permission and all parent permissions.
Expand All @@ -463,12 +468,12 @@ public static List<Permission> GetPermissionAndParentPermissions(Permission perm
else
{
var list = new List<Permission>() { Permission.Everything, permission };
string permStr = permission.ToString();
var permStr = permission.ToString();

// if the first 2 characters are both uppercase
if (permStr.Substring(0, 2).ToUpper() == permStr.Substring(0, 2))
{
if (!(permStr.Substring(2) == "All" || permStr.Substring(2) == "Menu"))
if (permStr.Substring(2) is not ("All" or "Menu"))
{
list.AddRange(Enum.GetValues(typeof(Permission)).Cast<Permission>().Where(a => a.ToString() == permStr.Substring(0, 2) + "All"));
}
Expand All @@ -487,14 +492,14 @@ public static List<Permission> GetPermissionAndParentPermissions(Permission perm
/// Sets the permissions for a specific player (checks server side, sends event to client side).
/// </summary>
/// <param name="player"></param>
public static void SetPermissionsForPlayer([FromSource]Player player)
public static void SetPermissionsForPlayer([FromSource] Player player)
{
if (player == null)
{
return;
}

Dictionary<Permission, bool> perms = new Dictionary<Permission, bool>();
var perms = new Dictionary<Permission, bool>();

// If enabled in the permissions.cfg (disabled by default) then this will give me (only me) the option to trigger some debug commands and
// try out menu options. This only works if I'm in-game on your server, and you have enabled server debugging mode, this way I will never
Expand All @@ -508,7 +513,7 @@ public static void SetPermissionsForPlayer([FromSource]Player player)
{
foreach (var p in Enum.GetValues(typeof(Permission)))
{
Permission permission = (Permission)p;
var permission = (Permission)p;
switch (permission)
{
// don't allow any of the following permissions if perms are ignored.
Expand All @@ -534,9 +539,11 @@ public static void SetPermissionsForPlayer([FromSource]Player player)
// Loop through all permissions and check if they're allowed.
foreach (var p in Enum.GetValues(typeof(Permission)))
{
Permission permission = (Permission)p;
var permission = (Permission)p;
if (!perms.ContainsKey(permission))
{
perms.Add(permission, IsAllowed(permission, player)); // triggers IsAllowedServer
}
}
}

Expand Down Expand Up @@ -571,9 +578,9 @@ public static void SetPermissions(string permissions)
/// <returns></returns>
private static string GetAceName(Permission permission)
{
string name = permission.ToString();
var name = permission.ToString();

string prefix = "vMenu.";
var prefix = "vMenu.";

switch (name.Substring(0, 2))
{
Expand Down
Loading

0 comments on commit 0148559

Please sign in to comment.