Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Persistent Ace-Hybrid Permissions via SQL #1118

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions qbcore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,13 @@ CREATE TABLE IF NOT EXISTS `player_contacts` (
PRIMARY KEY (`id`),
KEY `citizenid` (`citizenid`)
) ENGINE=InnoDB AUTO_INCREMENT=1;

CREATE TABLE IF NOT EXISTS `permissions` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_general_ci',
`license` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_general_ci',
`permission` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_general_ci',
PRIMARY KEY (`id`) USING BTREE,
INDEX `license` (`license`) USING BTREE
)
COLLATE='utf8mb4_general_ci' ENGINE=InnoDB AUTO_INCREMENT=1;
25 changes: 25 additions & 0 deletions server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ end
---@param permission string
function QBCore.Functions.AddPermission(source, permission)
if not IsPlayerAceAllowed(source, permission) then
local license = QBCore.Functions.GetIdentifier(source, 'license')
local name = GetPlayerName(source)
MySQL.insert.await('INSERT INTO `permissions` (name, license, permission) VALUES (?, ?, ?)', {
name, license, permission
})
ExecuteCommand(('add_principal player.%s qbcore.%s'):format(source, permission))
QBCore.Commands.Refresh(source)
end
Expand All @@ -540,21 +545,41 @@ end
---@param source any
---@param permission string
function QBCore.Functions.RemovePermission(source, permission)
local license = QBCore.Functions.GetIdentifier(source, 'license')
if permission then
if IsPlayerAceAllowed(source, permission) then
MySQL.query('DELETE FROM `permissions` WHERE `license` = ? AND `permission` = ?', {
license, permission
})
ExecuteCommand(('remove_principal player.%s qbcore.%s'):format(source, permission))
QBCore.Commands.Refresh(source)
end
else
for _, v in pairs(QBCore.Config.Server.Permissions) do
if IsPlayerAceAllowed(source, v) then
MySQL.query('DELETE FROM `permissions` WHERE `license` = ? AND `permission` = ?', {
license, v
})
ExecuteCommand(('remove_principal player.%s qbcore.%s'):format(source, v))
QBCore.Commands.Refresh(source)
end
end
end
end

---Dynamically assign ace permissions based on DB group
---@param source any
function QBCore.Functions.AssignPermissions(source)
local license = QBCore.Functions.GetIdentifier(source, 'license')
local permission = MySQL.query.await('SELECT `permission` FROM `permissions` WHERE `license` = ?', {
license
});
if not permission then return end
for i = 1, #permission do
ExecuteCommand(('add_principal player.%s qbcore.%s'):format(source, permission[i].permission))
end
end

-- Checking for Permission Level

---Check if player has permission
Expand Down
1 change: 1 addition & 0 deletions server/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function QBCore.Player.Login(source, citizenid, newData)
else
QBCore.Player.CheckPlayerData(source, newData)
end
QBCore.Functions.AssignPermissions(source)
return true
else
QBCore.ShowError(resourceName, 'ERROR QBCORE.PLAYER.LOGIN - NO SOURCE GIVEN!')
Expand Down
Loading