WIP Permissions System - #594
Conversation
|
I just scrolled over it as I don't have the time right now to go through it in detail. One thing I found though is that I will look into it in detail when I get back home this evening. Thanks for the really fast work though ;) |
|
Yeah permission player data was never a thing until introduced recently so no scripts from the GitHub use it, I can looking at adding it back though. Just seems useless because you just use the native checking ace instead of calling a function in the core |
|
Well it depends on the use-case. For a simple "Has-Permissions-Check" the native ace check does the trick but if you want to map something in the script to a specific group there is no native to get the string representation of this group (please correct me if I'm wrong). Here some examples pseudo code (using RegisterCommand('setModerationOutfit', function(src, args)
local permissionGroup = QBCore.Functions.GetPlayerData().permissionGroup
local outfitData = Config.OutfitData[permissionGroup] -- getting the configured outfit data matching the players permission group
ApplyPlayerOutfit(outfitData)
end)
function GetNotificationStringByGroup()
local permissionGroup = QBCore.Functions.GetPlayerData().permissionGroup
if permissionGroup == 'supporter'
return 'A supporter is on the way to your current location. Please do not panic!'
elseif ...
-- [...]
end |
|
I got 2 issue here:
|
|
Yeah I figured out a better way, I’ll be adding that here |
|
Oh and I just stumbled over another thing that is not working. The calls to |
|
I've tested your recent changes and they seem to work. Also because I finally understood your idea :D To add groups and players you would have to put the following into |
|
I got a suggestion for As this would break existing code single permission strings must be supported too. I wrote some code for this: function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission)
local restricted = true -- Default to restricted for all commands
if not permission then permission = 'user' end -- some commands don't pass permission level
local isMultiLevel = false
if type(permission) == 'table' then
-- a permission string table was passed
isMultiLevel = true
for k, v in pairs(permission) do
permission[k] = v:lower()
end
else
-- if permission is not table it must be string
permission = permission:lower()
end
if permission == 'user' then restricted = false end -- allow all users to use command
RegisterCommand(name, callback, restricted) -- Register command within fivem
if isMultiLevel then
for _, perm in pairs(permission) do
if not QBCore.Commands.IgnoreList[perm] then -- only create aces for extra perm levels
ExecuteCommand(('add_ace group.%s command.%s allow'):format(perm, name))
end
end
else
if not QBCore.Commands.IgnoreList[permission] then -- only create aces for extra perm levels
ExecuteCommand(('add_ace group.%s command.%s allow'):format(permission, name))
end
end
if not isMultiLevel then permission = { permission } end -- save permission in table format
QBCore.Commands.List[name:lower()] = {
name = name:lower(),
permission = permission,
help = help,
arguments = arguments,
argsrequired = argsrequired,
callback = callback
}
endfunction QBCore.Functions.HasPermission(source, permission)
local src = source
if type(permission) == 'table' then
for _, perm in pairs(permission) do
if IsPlayerAceAllowed(src, perm) then return true end
end
end
if IsPlayerAceAllowed(src, permission) then return true end
return false
end |
|
Also this does not seem to make a lot of sense: I checked the whole QBCore Framework build for any command that sets the permission to a job name and have not found one. Every job script I saw that registers commands checks for the job name itself. |
|
Was probably some weird attempt at locking commands to jobs but with the new system you can just assign an ace to players with a certain job |
This would replace the current permissions system and remove the database table by utilizing ace permissions
For example in your server.cfg: