mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-29 01:01:24 +00:00
More updates
This commit is contained in:
+22
-6
@@ -1,11 +1,21 @@
|
||||
QBCore.Commands = {}
|
||||
QBCore.Commands.List = {}
|
||||
QBCore.Commands.IgnoreList = { -- Ignore old perm levels while keeping backwards compatibility
|
||||
['god'] = true, -- We don't need to create an ace because group.admin allows all commands
|
||||
['admin'] = true, -- We don't need to create an ace because group.admin allows all commands
|
||||
['user'] = true, -- We don't need to create an ace because builtin.everyone
|
||||
}
|
||||
|
||||
-- Register & Refresh Commands
|
||||
|
||||
function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission)
|
||||
if not permission then permission = 'user' end
|
||||
RegisterCommand(name, 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
|
||||
if permission == 'user' then restricted = false end -- allow all users to use command
|
||||
RegisterCommand(name, callback, restricted) -- Register command within fivem
|
||||
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
|
||||
QBCore.Commands.List[name:lower()] = {
|
||||
name = name:lower(),
|
||||
permission = tostring(permission:lower()),
|
||||
@@ -18,20 +28,22 @@ end
|
||||
|
||||
function QBCore.Commands.Refresh(source)
|
||||
local src = source
|
||||
local Player = GetPlayer(src)
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
local suggestions = {}
|
||||
if Player then
|
||||
for command, info in pairs(QBCore.Commands.List) do
|
||||
local hasPerm = IsPlayerAceAllowed(tostring(src), info.permission)
|
||||
local hasPerm = IsPlayerAceAllowed(tostring(src), 'command.'..command)
|
||||
if hasPerm then
|
||||
suggestions[#suggestions + 1] = {
|
||||
name = '/' .. command,
|
||||
help = info.help,
|
||||
params = info.arguments
|
||||
}
|
||||
else
|
||||
TriggerClientEvent('chat:removeSuggestion', src, '/'..command)
|
||||
end
|
||||
end
|
||||
TriggerClientEvent('chat:addSuggestions', tonumber(src), suggestions)
|
||||
TriggerClientEvent('chat:addSuggestions', src, suggestions)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -77,7 +89,11 @@ QBCore.Commands.Add('addpermission', 'Give Player Permissions (God Only)', { { n
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
local permission = tostring(args[2]):lower()
|
||||
if Player then
|
||||
QBCore.Functions.AddPermission(Player.PlayerData.source, permission)
|
||||
if QBCore.Config.Server.Permissions[permission] then
|
||||
QBCore.Functions.AddPermission(Player.PlayerData.source, permission)
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, 'Invalid permission level', 'error')
|
||||
end
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, Lang:t('error.not_online'), 'error')
|
||||
end
|
||||
|
||||
+27
-17
@@ -14,7 +14,6 @@ function QBCore.Functions.GetCoords(entity)
|
||||
end
|
||||
|
||||
function QBCore.Functions.GetIdentifier(source, idtype)
|
||||
idtype = idtype or QBConfig.IdentifierType
|
||||
local identifiers = GetPlayerIdentifiers(source)
|
||||
for _, identifier in pairs(identifiers) do
|
||||
if string.find(identifier, idtype) then
|
||||
@@ -258,28 +257,37 @@ end
|
||||
|
||||
function QBCore.Functions.IsWhitelisted(source)
|
||||
if not QBCore.Config.Server.Whitelist then return true end
|
||||
if QBCore.Functions.HasPermission(source, QBConfig.Server.WhitelistPermission) then return true end
|
||||
if QBCore.Functions.HasPermission(source, QBCore.Config.Server.WhitelistPermission) then return true end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Setting & Removing Permissions
|
||||
|
||||
function QBCore.Functions.AddPermission(source, permission)
|
||||
local license = QBCore.Functions.GetIdentifier(source, 'license')
|
||||
if QBConfig.Server.Permissions[permission] then
|
||||
ExecuteCommand(('add_principal identifier.%s group.%s'):format(license, permission))
|
||||
QBCore.Commands.Refresh(source)
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, 'Invalid permission level', 'error')
|
||||
local src = source
|
||||
local license = QBCore.Functions.GetIdentifier(src, 'license')
|
||||
for k,v in pairs(QBCore.Config.Server.Permissions) do
|
||||
if permission == v then
|
||||
ExecuteCommand(('add_principal identifier.%s group.%s'):format(license, permission))
|
||||
QBCore.Commands.Refresh(src)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function QBCore.Functions.RemovePermission(source)
|
||||
local license = QBCore.Functions.GetIdentifier(source, 'license')
|
||||
for k,v in pairs(QBConfig.Server.Permissions) do
|
||||
if IsPlayerAceAllowed(source, v) then
|
||||
ExecuteCommand(('remove_principal identifier.%s group.%s'):format(license, v))
|
||||
QBCore.Commands.Refresh(source)
|
||||
function QBCore.Functions.RemovePermission(source, permission)
|
||||
local src = source
|
||||
local license = QBCore.Functions.GetIdentifier(src, 'license')
|
||||
if permission then
|
||||
if IsPlayerAceAllowed(src, permission) then
|
||||
ExecuteCommand(('remove_principal identifier.%s group.%s'):format(license, permission))
|
||||
QBCore.Commands.Refresh(src)
|
||||
end
|
||||
else
|
||||
for k,v in pairs(QBCore.Config.Server.Permissions) do
|
||||
if IsPlayerAceAllowed(src, v) then
|
||||
ExecuteCommand(('remove_principal identifier.%s group.%s'):format(license, v))
|
||||
QBCore.Commands.Refresh(src)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -288,14 +296,16 @@ end
|
||||
|
||||
function QBCore.Functions.HasPermission(source, permission)
|
||||
local src = source
|
||||
if IsPlayerAceAllowed(tostring(src), tostring(permission:lower())) then return true end
|
||||
local group = ('group.%s'):format(permission)
|
||||
if IsPlayerAceAllowed(tostring(src), group) then return true end
|
||||
return false
|
||||
end
|
||||
|
||||
function QBCore.Functions.GetPermission(source)
|
||||
local src = source
|
||||
for k,v in pairs (QBConfig.Server.Permissions) do
|
||||
if IsPlayerAceAllowed(src, 'group.'..v) then
|
||||
for k,v in pairs (QBCore.Config.Server.Permissions) do
|
||||
local group = ('group.%s'):format(v)
|
||||
if IsPlayerAceAllowed(src, group) then
|
||||
return v
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user