Skip to content

Commit

Permalink
feat: acl support (#5)
Browse files Browse the repository at this point in the history
* feat: acl support

* readme: reflect changes
  • Loading branch information
MrGriefs committed Mar 20, 2023
1 parent 21f845c commit 401391b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -50,6 +50,7 @@ All config variables are client-side and only computed on a client's machine.
property | type | description
-- | -- | --
`CommandAccessHandling` | function | handling used to verify if the client should be able to enable AB3
`CommandAccessAce` | string\|nil | Use ACL to determine whether the client should be able to enable AB3
`CommandBinding ` | string\|nil | keybind to use for on/off command. can be nil for no keybind
`ThirdPersonMode` | boolean | whether the axon overlay is also visible in third person

Expand Down
21 changes: 21 additions & 0 deletions client.lua
Expand Up @@ -9,6 +9,27 @@ if GetConvar('tfnrp_framework_init', 'false') == 'true' then
Config.CommandAccessHandling = function ()
return exports.framework:GetLocalClientDuty() > 0
end

elseif Config.CommandAccessAce then
Config.CommandAccessAce = nil
local hasAce = false
local pass = false
local commandAccessHandling = Config.CommandAccessHandling

RegisterNetEvent('AB3:ServerHasAce', function (bool)
hasAce = bool
end)
TriggerServerEvent('AB3:ClientHasAce')

Config.CommandAccessHandling = function ()
if not pass then
pass = true
Citizen.SetTimeout(2.5e3, function () pass = false end)
TriggerServerEvent('AB3:ClientHasAce')
end

return hasAce and commandAccessHandling()
end
end

----------------------------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions config.lua
Expand Up @@ -2,12 +2,16 @@
--- @type table
Config = {
--- Handling used to verify if the client should be able to enable AB3.
--- @type function
--- @return boolean
--- @type function - a client-side implementation of custom framework logic, etc
--- @return boolean - whether client should have access
CommandAccessHandling = function ()
-- Add custom framework access handling here.
return true
end,
--- Use ACL to determine whether the client should be able to enable AB3.
--- ACL will be checked befored CommandAccessHandling, if it exists.
--- @type string|nil - string representation of the "root" ace
CommandAccessAce = 'ab3',
--- Keybind to use for on/off command. can be nil for no keybind.
--- @type string
CommandBinding = 'u',
Expand Down
6 changes: 2 additions & 4 deletions fxmanifest.lua
Expand Up @@ -5,10 +5,8 @@ repository 'https://github.com/TFNRP/axonbody3'
version '0.2.1'
author 'Reece Stokes <hagen@hyena.gay>'

client_script {
'config.lua',
'client.lua',
}
shared_script 'config.lua'
client_script 'client.lua'
server_script 'server.lua'
ui_page 'static/index.html'
file 'static/*'
11 changes: 10 additions & 1 deletion server.lua
@@ -1,3 +1,12 @@
RegisterNetEvent('AB3:ClientBeep', function()
TriggerClientEvent('AB3:ServerBeep', -1, source)
end)
end)

if Config.CommandAccessAce then
local ace = Config.CommandAccessAce
RegisterNetEvent('AB3:ClientHasAce', function()
TriggerClientEvent('AB3:ServerHasAce', source, IsPlayerAceAllowed(source, ace))
end)
end

Config = nil

0 comments on commit 401391b

Please sign in to comment.