From 3bb10236542ab46934cf1e06ae428abed9a351d5 Mon Sep 17 00:00:00 2001 From: Kakarot <57848836+GhzGarage@users.noreply.github.com> Date: Mon, 28 Mar 2022 01:24:40 -0500 Subject: [PATCH 01/12] WIP permission system --- config.lua | 6 +--- server/commands.lua | 34 ++++++++++------------ server/events.lua | 26 ++--------------- server/functions.lua | 69 +++++++++----------------------------------- server/main.lua | 22 +------------- server/player.lua | 20 ------------- 6 files changed, 34 insertions(+), 143 deletions(-) diff --git a/config.lua b/config.lua index f18ac41..43de9d5 100644 --- a/config.lua +++ b/config.lua @@ -30,11 +30,7 @@ QBConfig.Server.WhitelistPermission = 'admin' -- Permission that's able to enter QBConfig.Server.PVP = true -- Enable or disable pvp on the server (Ability to shoot other players) QBConfig.Server.Discord = "" -- Discord invite link QBConfig.Server.CheckDuplicateLicense = true -- Check for duplicate rockstar license on join -QBConfig.Server.PermissionList = {} -- Permission list for old permission system -QBConfig.Server.UseOldPermissionSystem = false -- Use old permissions system from the database -QBConfig.Server.AllPermissions = { -- Table of permissions which have access to everything for the new permissions system - 'god', -} +QBConfig.Server.Permissions = {'god', 'admin', 'mod'} -- Add as many groups as you want here after creating them in your server.cfg QBConfig.Notify = {} diff --git a/server/commands.lua b/server/commands.lua index 7a68187..877236c 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -4,14 +4,10 @@ QBCore.Commands.List = {} -- Register & Refresh Commands function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission) - if type(permission) == 'string' then - permission = permission:lower() - else - permission = 'user' - end - QBCore.Commands.List[name:lower()] = { + RegisterCommand(name, callback, permission) + CommandList[name:lower()] = { name = name:lower(), - permission = permission, + permission = tostring(permission:lower()), help = help, arguments = arguments, argsrequired = argsrequired, @@ -20,20 +16,22 @@ function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, perm end function QBCore.Commands.Refresh(source) - local Player = QBCore.Functions.GetPlayer(source) + local src = source + local Player = GetPlayer(src) local suggestions = {} - if not Player then return end - for command, info in pairs(QBCore.Commands.List) do - local hasPerm = QBCore.Functions.HasPermission(source, QBCore.Commands.List[command].permission) - if hasPerm then - suggestions[#suggestions + 1] = { - name = '/' .. command, - help = info.help, - params = info.arguments - } + if Player then + for command, info in pairs(CommandList) do + local hasPerm = IsPlayerAceAllowed(tostring(src), info.permission) + if hasPerm then + suggestions[#suggestions + 1] = { + name = '/' .. command, + help = info.help, + params = info.arguments + } + end end + TriggerClientEvent('chat:addSuggestions', tonumber(src), suggestions) end - TriggerClientEvent('chat:addSuggestions', source, suggestions) end -- Teleport diff --git a/server/events.lua b/server/events.lua index 5a99f61..84bb425 100644 --- a/server/events.lua +++ b/server/events.lua @@ -10,28 +10,6 @@ AddEventHandler('playerDropped', function() QBCore.Players[src] = nil end) -AddEventHandler('chatMessage', function(source, _, message) - local src = source - if string.sub(message, 1, 1) ~= '/' then return end - local args = QBCore.Shared.SplitStr(message, ' ') - local command = string.gsub(args[1]:lower(), '/', '') - CancelEvent() - if not QBCore.Commands.List[command] then return end - local Player = QBCore.Functions.GetPlayer(src) - if not Player then return end - local hasPerm = QBCore.Functions.HasPermission(src, QBCore.Commands.List[command].permission) - table.remove(args, 1) - if hasPerm then - if QBCore.Commands.List[command].argsrequired and #QBCore.Commands.List[command].arguments ~= 0 and not args[#QBCore.Commands.List[command].arguments] then - TriggerClientEvent('QBCore:Notify', src, Lang:t('error.missing_args2'), 'error') - else - QBCore.Commands.List[command].callback(src, args) - end - else - TriggerClientEvent('QBCore:Notify', src, Lang:t('error.no_access'), 'error') - end -end) - -- Player Connecting local function onPlayerConnecting(name, setKickReason, deferrals) @@ -44,7 +22,9 @@ local function onPlayerConnecting(name, setKickReason, deferrals) Wait(0) if QBCore.Config.Server.Closed then - deferrals.done(QBCore.Config.Server.ClosedReason) + if not IsPlayerAceAllowed(src, 'qbadmin.join') then + deferrals.done(QBCore.Config.Server.ClosedReason) + end end deferrals.update(string.format('Hello %s. Validating Your Rockstar License', name)) diff --git a/server/functions.lua b/server/functions.lua index 2e89a2c..5802a27 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -265,76 +265,33 @@ end -- Setting & Removing Permissions function QBCore.Functions.AddPermission(source, permission) - local Player = QBCore.Functions.GetPlayer(source) - local plicense = Player.PlayerData.license - if not Player then return end - if QBCore.Config.Server.UseOldPermissionSystem then - QBCore.Config.Server.PermissionList[plicense] = { - license = plicense, - permission = permission:lower(), - } - MySQL.Async.execute('DELETE FROM permissions WHERE license = ?', { plicense }) - MySQL.Async.insert('INSERT INTO permissions (name, license, permission) VALUES (?, ?, ?)', { - GetPlayerName(source), - plicense, - permission:lower() - }) - Player.Functions.UpdatePlayerData() - TriggerClientEvent('QBCore:Client:OnPermissionUpdate', 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 - Player.Functions.SetPermission(permission) + TriggerClientEvent('QBCore:Notify', source, 'Invalid permission level', 'error') end end function QBCore.Functions.RemovePermission(source) - local Player = QBCore.Functions.GetPlayer(source) - local license = Player.PlayerData.license - if not Player then return end - if QBCore.Config.Server.UseOldPermissionSystem then - QBCore.Config.Server.PermissionList[license] = nil - MySQL.Async.execute('DELETE FROM permissions WHERE license = ?', { license }) - Player.Functions.UpdatePlayerData() - TriggerClientEvent('QBCore:Client:OnPermissionUpdate', source, 'user') - else - Player.Functions.SetPermission('user') + 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) + end end end -- Checking for Permission Level function QBCore.Functions.HasPermission(source, permission) - permission = tostring(permission:lower()) - local license = QBCore.Functions.GetIdentifier(source, 'license') - if QBCore.Config.Server.UseOldPermissionSystem then - if permission == 'user' then return true end - if not QBCore.Config.Server.PermissionList[license] or QBCore.Config.Server.PermissionList[license].license ~= license then return false end - if QBCore.Config.Server.PermissionList[license].permission ~= permission and QBCore.Config.Server.PermissionList[license].permission ~= 'god' then return false end - return true - else - local Player = QBCore.Functions.GetPlayer(source) - if next(QBCore.Config.Server.AllPermissions) then - for i = 1, #QBCore.Config.Server.AllPermissions do - if QBCore.Config.Server.AllPermissions[i] == Player.PlayerData.permission then - return true - end - end - end - return Player.PlayerData.permission == permission - end + local src = source + if IsPlayerAceAllowed(tostring(src), tostring(permission:lower())) then return true end return false end -function QBCore.Functions.GetPermission(source) - local license = QBCore.Functions.GetIdentifier(source, 'license') - if QBCore.Config.Server.UseOldPermissionSystem then - if not license or not QBCore.Config.Server.PermissionList[license] or QBCore.Config.Server.PermissionList[license].license ~= license then return 'user' end - return QBCore.Config.Server.PermissionList[license].permission - else - local Player = QBCore.Functions.GetPlayer(source) - return Player.PlayerData.permission - end -end - -- Opt in or out of admin reports function QBCore.Functions.IsOptin(source) diff --git a/server/main.lua b/server/main.lua index d6f3fad..41c0c43 100644 --- a/server/main.lua +++ b/server/main.lua @@ -10,24 +10,4 @@ end) -- To use this export in a script instead of manifest method -- Just put this line of code below at the very top of the script --- local QBCore = exports['qb-core']:GetCoreObject() - --- Get permissions on server start - -CreateThread(function() - if QBCore.Config.Server.UseOldPermissionSystem then - local result = MySQL.Sync.fetchAll('SELECT * FROM permissions', {}) - if not result then return end - for k, v in pairs(result) do - QBCore.Config.Server.PermissionList[v.license] = { - license = v.license, - permission = v.permission, - optin = true - } - end - else - for i = 1, #QBCore.Config.Server.AllPermissions do - ExecuteCommand(('add_principal group.%s group.admin'):format(QBCore.Config.Server.AllPermissions[i])) - end - end -end) +-- local QBCore = exports['qb-core']:GetCoreObject() \ No newline at end of file diff --git a/server/player.lua b/server/player.lua index 1d133be..b706e67 100644 --- a/server/player.lua +++ b/server/player.lua @@ -43,15 +43,6 @@ function QBCore.Player.CheckPlayerData(source, PlayerData) PlayerData.license = PlayerData.license or QBCore.Functions.GetIdentifier(source, 'license') PlayerData.name = GetPlayerName(source) PlayerData.cid = PlayerData.cid or 1 - if not QBCore.Config.Server.UseOldPermissionSystem then - if PlayerData.permission then ExecuteCommand(('remove_principal identifier.%s group.%s'):format(PlayerData.license, PlayerData.permission)) end - if not PlayerData.permission and IsPlayerAceAllowed(source, 'command') then -- if both aces are allowed then the person has group.admin and is a system admin - PlayerData.permission = QBCore.Config.Server.AllPermissions[1] or 'god' - end - PlayerData.permission = PlayerData.permission or 'user' - ExecuteCommand(('add_principal identifier.%s group.%s'):format(PlayerData.license, PlayerData.permission)) - PlayerData.optin = PlayerData.optin or true - end PlayerData.money = PlayerData.money or {} for moneytype, startamount in pairs(QBCore.Config.Money.MoneyTypes) do PlayerData.money[moneytype] = PlayerData.money[moneytype] or startamount @@ -168,17 +159,6 @@ function QBCore.Player.CreatePlayer(PlayerData) end end - if not QBCore.Config.Server.UseOldPermissionSystem then - function self.Functions.SetPermission(permission) - permission = permission:lower() - ExecuteCommand(('remove_principal identifier.%s group.%s'):format(self.PlayerData.license, self.PlayerData.permission)) - ExecuteCommand(('add_principal identifier.%s group.%s'):format(self.PlayerData.license, permission)) - self.PlayerData.permission = permission - self.Functions.UpdatePlayerData() - TriggerClientEvent('QBCore:Client:OnPermissionUpdate', self.PlayerData.source, permission) - end - end - function self.Functions.SetJob(job, grade) job = job:lower() grade = tostring(grade) or '0' From 581e7572a0fd140cb1e537bae102a56c6662a00d Mon Sep 17 00:00:00 2001 From: Kakarot <57848836+GhzGarage@users.noreply.github.com> Date: Mon, 28 Mar 2022 01:26:25 -0500 Subject: [PATCH 02/12] Remove optin (look into chat channels) --- server/functions.lua | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/server/functions.lua b/server/functions.lua index 5802a27..fb0cfa4 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -294,28 +294,28 @@ end -- Opt in or out of admin reports -function QBCore.Functions.IsOptin(source) - local license = QBCore.Functions.GetIdentifier(source, 'license') - if not license or not QBCore.Functions.HasPermission(source, 'admin') then return false end - if QBCore.Config.Server.UseOldPermissionSystem then - return QBCore.Config.Server.PermissionList[license].optin - else - local Player = QBCore.Functions.GetPlayer(source) - return Player.PlayerData.optin - end -end +-- function QBCore.Functions.IsOptin(source) +-- local license = QBCore.Functions.GetIdentifier(source, 'license') +-- if not license or not QBCore.Functions.HasPermission(source, 'admin') then return false end +-- if QBCore.Config.Server.UseOldPermissionSystem then +-- return QBCore.Config.Server.PermissionList[license].optin +-- else +-- local Player = QBCore.Functions.GetPlayer(source) +-- return Player.PlayerData.optin +-- end +-- end -function QBCore.Functions.ToggleOptin(source) - local license = QBCore.Functions.GetIdentifier(source, 'license') - if not license or not QBCore.Functions.HasPermission(source, 'admin') then return end - if QBCore.Config.Server.UseOldPermissionSystem then - QBCore.Config.Server.PermissionList[license].optin = not QBCore.Config.Server.PermissionList[license].optin - else - local Player = QBCore.Functions.GetPlayer(source) - Player.PlayerData.optin = not Player.PlayerData.optin - Player.Functions.SetMetaData('optin', Player.PlayerData.optin) - end -end +-- function QBCore.Functions.ToggleOptin(source) +-- local license = QBCore.Functions.GetIdentifier(source, 'license') +-- if not license or not QBCore.Functions.HasPermission(source, 'admin') then return end +-- if QBCore.Config.Server.UseOldPermissionSystem then +-- QBCore.Config.Server.PermissionList[license].optin = not QBCore.Config.Server.PermissionList[license].optin +-- else +-- local Player = QBCore.Functions.GetPlayer(source) +-- Player.PlayerData.optin = not Player.PlayerData.optin +-- Player.Functions.SetMetaData('optin', Player.PlayerData.optin) +-- end +-- end -- Check if player is banned From cc44840df40c220a552fac49ebbd1e7e52915dc5 Mon Sep 17 00:00:00 2001 From: Kakarot <57848836+GhzGarage@users.noreply.github.com> Date: Mon, 28 Mar 2022 21:37:53 -0500 Subject: [PATCH 03/12] GetPermission function --- server/functions.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/functions.lua b/server/functions.lua index fb0cfa4..fcad125 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -292,6 +292,16 @@ function QBCore.Functions.HasPermission(source, permission) 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 + return v + end + end + return 'user' +end + -- Opt in or out of admin reports -- function QBCore.Functions.IsOptin(source) From 94476fee2e3fa31b322f07526160d64fcc1c3ca9 Mon Sep 17 00:00:00 2001 From: Kakarot <57848836+GhzGarage@users.noreply.github.com> Date: Mon, 28 Mar 2022 22:00:56 -0500 Subject: [PATCH 04/12] old compat --- server/commands.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/commands.lua b/server/commands.lua index 877236c..376c9a9 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -4,8 +4,9 @@ QBCore.Commands.List = {} -- Register & Refresh Commands function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission) + if not permission then permission = 'user' end RegisterCommand(name, callback, permission) - CommandList[name:lower()] = { + QBCore.Commands.List[name:lower()] = { name = name:lower(), permission = tostring(permission:lower()), help = help, @@ -20,7 +21,7 @@ function QBCore.Commands.Refresh(source) local Player = GetPlayer(src) local suggestions = {} if Player then - for command, info in pairs(CommandList) do + for command, info in pairs(QBCore.Commands.List) do local hasPerm = IsPlayerAceAllowed(tostring(src), info.permission) if hasPerm then suggestions[#suggestions + 1] = { From a528a0b1272eb13dbc77449e1e5b70d8276a54d5 Mon Sep 17 00:00:00 2001 From: Kakarot Date: Tue, 29 Mar 2022 22:12:00 -0500 Subject: [PATCH 05/12] More updates --- server/commands.lua | 28 ++++++++++++++++++++++------ server/functions.lua | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/server/commands.lua b/server/commands.lua index 376c9a9..c32d5fd 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -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 diff --git a/server/functions.lua b/server/functions.lua index fcad125..b9e30db 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -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 From f5e22066fb79eb86383f29313fcc46adbdfff5a5 Mon Sep 17 00:00:00 2001 From: Kakarot Date: Tue, 29 Mar 2022 22:33:26 -0500 Subject: [PATCH 06/12] More changes --- server/commands.lua | 11 ++++------- server/functions.lua | 7 ++++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/server/commands.lua b/server/commands.lua index c32d5fd..254468f 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -89,11 +89,7 @@ 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 - if QBCore.Config.Server.Permissions[permission] then - QBCore.Functions.AddPermission(Player.PlayerData.source, permission) - else - TriggerClientEvent('QBCore:Notify', source, 'Invalid permission level', 'error') - end + QBCore.Functions.AddPermission(Player.PlayerData.source, permission) else TriggerClientEvent('QBCore:Notify', source, Lang:t('error.not_online'), 'error') end @@ -101,8 +97,9 @@ end, 'god') QBCore.Commands.Add('removepermission', 'Remove Players Permissions (God Only)', { { name = 'id', help = 'ID of player' } }, true, function(source, args) local Player = QBCore.Functions.GetPlayer(tonumber(args[1])) + local permission = tostring(args[2]):lower() if Player then - QBCore.Functions.RemovePermission(Player.PlayerData.source) + QBCore.Functions.RemovePermission(Player.PlayerData.source, permission) else TriggerClientEvent('QBCore:Notify', source, Lang:t('error.not_online'), 'error') end @@ -128,7 +125,7 @@ QBCore.Commands.Add('closeserver', 'Close the server for people without permissi return end if QBCore.Functions.HasPermission(source, 'admin') then - reason = args[1] or 'No reason specified' + local reason = args[1] or 'No reason specified' QBCore.Config.Server.Closed = true QBCore.Config.Server.ClosedReason = reason for k in pairs(QBCore.Players) do diff --git a/server/functions.lua b/server/functions.lua index b9e30db..cf21e7c 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -301,15 +301,16 @@ function QBCore.Functions.HasPermission(source, permission) return false end -function QBCore.Functions.GetPermission(source) +function QBCore.Functions.GetPermissions(source) local src = source + local perms = {} for k,v in pairs (QBCore.Config.Server.Permissions) do local group = ('group.%s'):format(v) if IsPlayerAceAllowed(src, group) then - return v + perms[v] = true end end - return 'user' + return perms end -- Opt in or out of admin reports From 46a2aae5ce673f90ab022b94265f5e03cd607502 Mon Sep 17 00:00:00 2001 From: Kakarot Date: Wed, 30 Mar 2022 00:45:31 -0500 Subject: [PATCH 07/12] More changes --- config.lua | 2 +- server/commands.lua | 8 +++++++- server/functions.lua | 14 ++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/config.lua b/config.lua index 43de9d5..9681f22 100644 --- a/config.lua +++ b/config.lua @@ -30,7 +30,7 @@ QBConfig.Server.WhitelistPermission = 'admin' -- Permission that's able to enter QBConfig.Server.PVP = true -- Enable or disable pvp on the server (Ability to shoot other players) QBConfig.Server.Discord = "" -- Discord invite link QBConfig.Server.CheckDuplicateLicense = true -- Check for duplicate rockstar license on join -QBConfig.Server.Permissions = {'god', 'admin', 'mod'} -- Add as many groups as you want here after creating them in your server.cfg +QBConfig.Server.Permissions = {'admin', 'mod'} -- Add as many groups as you want here after creating them in your server.cfg QBConfig.Notify = {} diff --git a/server/commands.lua b/server/commands.lua index 254468f..144eb2b 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -3,9 +3,15 @@ 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 + ['user'] = true -- We don't need to create an ace because builtin.everyone } +CreateThread(function() -- Add rank name to ace + for k,v in pairs(QBConfig.Server.Permissions) do + ExecuteCommand(('add_ace group.%s %s allow'):format(v, v)) + end +end) + -- Register & Refresh Commands function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission) diff --git a/server/functions.lua b/server/functions.lua index cf21e7c..7971c37 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -266,12 +266,8 @@ end function QBCore.Functions.AddPermission(source, permission) 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 + ExecuteCommand(('add_principal identifier.%s group.%s'):format(license, permission)) + QBCore.Commands.Refresh(src) end function QBCore.Functions.RemovePermission(source, permission) @@ -296,8 +292,7 @@ end function QBCore.Functions.HasPermission(source, permission) local src = source - local group = ('group.%s'):format(permission) - if IsPlayerAceAllowed(tostring(src), group) then return true end + if IsPlayerAceAllowed(src, permission) then return true end return false end @@ -305,8 +300,7 @@ function QBCore.Functions.GetPermissions(source) local src = source local perms = {} for k,v in pairs (QBCore.Config.Server.Permissions) do - local group = ('group.%s'):format(v) - if IsPlayerAceAllowed(src, group) then + if IsPlayerAceAllowed(src, v) then perms[v] = true end end From dd6c6c4a09c7afacbb9810465186c350f00a6d57 Mon Sep 17 00:00:00 2001 From: Kakarot Date: Wed, 30 Mar 2022 01:04:59 -0500 Subject: [PATCH 08/12] More changes --- config.lua | 2 +- server/commands.lua | 3 +-- server/functions.lua | 34 +++++++++++++--------------------- server/player.lua | 1 + 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/config.lua b/config.lua index 9681f22..43de9d5 100644 --- a/config.lua +++ b/config.lua @@ -30,7 +30,7 @@ QBConfig.Server.WhitelistPermission = 'admin' -- Permission that's able to enter QBConfig.Server.PVP = true -- Enable or disable pvp on the server (Ability to shoot other players) QBConfig.Server.Discord = "" -- Discord invite link QBConfig.Server.CheckDuplicateLicense = true -- Check for duplicate rockstar license on join -QBConfig.Server.Permissions = {'admin', 'mod'} -- Add as many groups as you want here after creating them in your server.cfg +QBConfig.Server.Permissions = {'god', 'admin', 'mod'} -- Add as many groups as you want here after creating them in your server.cfg QBConfig.Notify = {} diff --git a/server/commands.lua b/server/commands.lua index 144eb2b..667e7cb 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -1,8 +1,7 @@ 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 + ['god'] = true, -- We don't need to create an ace because group.god allows all commands ['user'] = true -- We don't need to create an ace because builtin.everyone } diff --git a/server/functions.lua b/server/functions.lua index 7971c37..2311b3d 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -309,28 +309,20 @@ end -- Opt in or out of admin reports --- function QBCore.Functions.IsOptin(source) --- local license = QBCore.Functions.GetIdentifier(source, 'license') --- if not license or not QBCore.Functions.HasPermission(source, 'admin') then return false end --- if QBCore.Config.Server.UseOldPermissionSystem then --- return QBCore.Config.Server.PermissionList[license].optin --- else --- local Player = QBCore.Functions.GetPlayer(source) --- return Player.PlayerData.optin --- end --- end +function QBCore.Functions.IsOptin(source) + local license = QBCore.Functions.GetIdentifier(source, 'license') + if not license or not QBCore.Functions.HasPermission(source, 'admin') then return false end + local Player = QBCore.Functions.GetPlayer(source) + return Player.PlayerData.optin +end --- function QBCore.Functions.ToggleOptin(source) --- local license = QBCore.Functions.GetIdentifier(source, 'license') --- if not license or not QBCore.Functions.HasPermission(source, 'admin') then return end --- if QBCore.Config.Server.UseOldPermissionSystem then --- QBCore.Config.Server.PermissionList[license].optin = not QBCore.Config.Server.PermissionList[license].optin --- else --- local Player = QBCore.Functions.GetPlayer(source) --- Player.PlayerData.optin = not Player.PlayerData.optin --- Player.Functions.SetMetaData('optin', Player.PlayerData.optin) --- end --- end +function QBCore.Functions.ToggleOptin(source) + local license = QBCore.Functions.GetIdentifier(source, 'license') + if not license or not QBCore.Functions.HasPermission(source, 'admin') then return end + local Player = QBCore.Functions.GetPlayer(source) + Player.PlayerData.optin = not Player.PlayerData.optin + Player.Functions.SetMetaData('optin', Player.PlayerData.optin) +end -- Check if player is banned diff --git a/server/player.lua b/server/player.lua index b706e67..542cf15 100644 --- a/server/player.lua +++ b/server/player.lua @@ -44,6 +44,7 @@ function QBCore.Player.CheckPlayerData(source, PlayerData) PlayerData.name = GetPlayerName(source) PlayerData.cid = PlayerData.cid or 1 PlayerData.money = PlayerData.money or {} + PlayerData.optin = PlayerData.optin or true for moneytype, startamount in pairs(QBCore.Config.Money.MoneyTypes) do PlayerData.money[moneytype] = PlayerData.money[moneytype] or startamount end From eb34e652041658761f094a7763edf1e8b1b79346 Mon Sep 17 00:00:00 2001 From: Kakarot Date: Wed, 30 Mar 2022 01:20:11 -0500 Subject: [PATCH 09/12] More changes --- server/commands.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/commands.lua b/server/commands.lua index 667e7cb..631e072 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -9,6 +9,7 @@ CreateThread(function() -- Add rank name to ace for k,v in pairs(QBConfig.Server.Permissions) do ExecuteCommand(('add_ace group.%s %s allow'):format(v, v)) end + ExecuteCommand('add_ace group.god command allow') end) -- Register & Refresh Commands @@ -100,7 +101,7 @@ QBCore.Commands.Add('addpermission', 'Give Player Permissions (God Only)', { { n end end, 'god') -QBCore.Commands.Add('removepermission', 'Remove Players Permissions (God Only)', { { name = 'id', help = 'ID of player' } }, true, function(source, args) +QBCore.Commands.Add('removepermission', 'Remove Players Permissions (God Only)', { { name = 'id', help = 'ID of player' }, { name = 'permission', help = 'Permission level' } }, true, function(source, args) local Player = QBCore.Functions.GetPlayer(tonumber(args[1])) local permission = tostring(args[2]):lower() if Player then From 2d6159345b39514683e980ab62296a9a9ccfe935 Mon Sep 17 00:00:00 2001 From: Kakarot Date: Wed, 30 Mar 2022 01:31:36 -0500 Subject: [PATCH 10/12] Remove --- server/commands.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/server/commands.lua b/server/commands.lua index 631e072..7fadb88 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -9,7 +9,6 @@ CreateThread(function() -- Add rank name to ace for k,v in pairs(QBConfig.Server.Permissions) do ExecuteCommand(('add_ace group.%s %s allow'):format(v, v)) end - ExecuteCommand('add_ace group.god command allow') end) -- Register & Refresh Commands From b04eb3f43af5c06ff94d13543e096e055abdfe51 Mon Sep 17 00:00:00 2001 From: Kakarot Date: Wed, 30 Mar 2022 17:05:07 -0500 Subject: [PATCH 11/12] Update to qbcore. --- server/commands.lua | 8 ++++---- server/functions.lua | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/server/commands.lua b/server/commands.lua index 7fadb88..457277d 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -1,13 +1,13 @@ 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.god allows all commands + ['god'] = true, -- We don't need to create an ace because god is allowed all commands ['user'] = true -- We don't need to create an ace because builtin.everyone } -CreateThread(function() -- Add rank name to ace +CreateThread(function() -- Add ace to node for perm checking for k,v in pairs(QBConfig.Server.Permissions) do - ExecuteCommand(('add_ace group.%s %s allow'):format(v, v)) + ExecuteCommand(('add_ace qbcore.%s %s allow'):format(v, v)) end end) @@ -19,7 +19,7 @@ function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, perm 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)) + ExecuteCommand(('add_ace qbcore.%s command.%s allow'):format(permission, name)) end QBCore.Commands.List[name:lower()] = { name = name:lower(), diff --git a/server/functions.lua b/server/functions.lua index 2311b3d..8b0bce6 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -266,7 +266,7 @@ end function QBCore.Functions.AddPermission(source, permission) local src = source local license = QBCore.Functions.GetIdentifier(src, 'license') - ExecuteCommand(('add_principal identifier.%s group.%s'):format(license, permission)) + ExecuteCommand(('add_principal identifier.%s qbcore.%s'):format(license, permission)) QBCore.Commands.Refresh(src) end @@ -275,13 +275,13 @@ function QBCore.Functions.RemovePermission(source, permission) 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)) + ExecuteCommand(('remove_principal identifier.%s qbcore.%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)) + ExecuteCommand(('remove_principal identifier.%s qbcore.%s'):format(license, v)) QBCore.Commands.Refresh(src) end end From ccbc6b216dd905fdb5f10fdf7cb7bdde9938bd03 Mon Sep 17 00:00:00 2001 From: Kakarot Date: Wed, 30 Mar 2022 17:25:20 -0500 Subject: [PATCH 12/12] Remove job check --- server/events.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/events.lua b/server/events.lua index 84bb425..c48160e 100644 --- a/server/events.lua +++ b/server/events.lua @@ -183,7 +183,7 @@ RegisterNetEvent('QBCore:CallCommand', function(command, args) local Player = QBCore.Functions.GetPlayer(src) if not Player then return end local hasPerm = QBCore.Functions.HasPermission(src, QBCore.Commands.List[command].permission) - if (QBCore.Commands.List[command].permission == Player.PlayerData.job.name) or hasPerm then + if hasPerm then if QBCore.Commands.List[command].argsrequired and #QBCore.Commands.List[command].arguments ~= 0 and not args[#QBCore.Commands.List[command].arguments] then TriggerClientEvent('QBCore:Notify', src, Lang:t('error.missing_args2'), 'error') else