From 0580862298d2586c2e4845250f59d568051523b2 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 6 Sep 2024 12:37:56 -0400 Subject: [PATCH] v1.1.0 --- README.md | 30 +++------ client/main.lua | 4 ++ fxmanifest.lua | 4 +- server/main.lua | 12 ++-- shared/bridge.lua | 144 +++++++++++++++++++++++++++++++++++++++++++ shared/config.lua | 9 +-- shared/core.lua | 137 ---------------------------------------- shared/utilities.lua | 29 ++++----- 8 files changed, 177 insertions(+), 192 deletions(-) create mode 100644 shared/bridge.lua delete mode 100644 shared/core.lua diff --git a/README.md b/README.md index ebde1cf..409d266 100644 --- a/README.md +++ b/README.md @@ -17,36 +17,24 @@ Features: If you need any support, feel free to reach out to us via our Discord: https://discord.gg/7NATz2Yw5a -### Version 1.0.4 -- Added support for fivemerr logs (Thanks simsonas86) - -### Version 1.0.3 - -- Restructured the Bridge table a bit better for frameworks -- Updated how init works for NUI. -- Comments for standalone framework setup - -### Version 1.0.2 - -- Fixed issue with debugging in NUI and NUI path if resource is renamed - -### Version 1.0.1 - -- Fixed issue with getting player source with ESX - ### Dependencies - Supports both ESX and QBCore - oxmysql - ox_lib -### Database +### Installation -Run the `__install/database.sql` file in your server's database. +`NOTE: As of v1.1.0, permissions system has changed to run off of ace permissions in your server.cfg` -### Drop the Resource +- Run the `__install/database.sql` file in your server's database. +- Download the main branch and drop the package into your resources folder and remember to `ensure ir8-tickets` after `ox_lib` and `oxmysql` +- Add the permissions principal to your `server.cfg`: -Download the main branch and drop the package into your resources folder and remember to `ensure ir8-tickets` after `ox_lib` and `oxmysql` +``` +# Ticket Administration Ace +add_ace group.admin ticket.admin allow +``` ### Configuration diff --git a/client/main.lua b/client/main.lua index e1cd8db..b98147d 100644 --- a/client/main.lua +++ b/client/main.lua @@ -35,6 +35,10 @@ if IR8.Bridge.Client.EventPlayerLoaded then init() end end) +else + if not PlayerLoaded then + init() + end end -- Show the NUI diff --git a/fxmanifest.lua b/fxmanifest.lua index c7cd5f1..aef451d 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -2,7 +2,7 @@ fx_version 'cerulean' game 'gta5' author 'IR8 Scripts' description 'Ticket Manager' -version '1.0.4' +version '1.1.0' lua54 'yes' client_script 'client/main.lua' @@ -15,7 +15,7 @@ server_script { shared_script { "@ox_lib/init.lua", "shared/config.lua", - "shared/core.lua", + "shared/bridge.lua", "shared/utilities.lua", "shared/database.lua" } diff --git a/server/main.lua b/server/main.lua index 8be2b65..eb41f5a 100644 --- a/server/main.lua +++ b/server/main.lua @@ -30,12 +30,8 @@ lib.addCommand(IR8.Config.Commands.Tickets, { help = IR8.Config.Commands.TicketsDescription, params = {} }, function(source, args, raw) - if type(IR8.Bridge.Server.GetPlayerPermission) == "function" then - local hasAdminPermission = IR8.Utilities.HasPermission(IR8.Config.AdminPermissions, IR8.Bridge.Server.GetPlayerPermission(source)) - TriggerClientEvent(IR8.Config.ClientCallbackPrefix .. "ShowNUI", source, hasAdminPermission) - else - print("[Error] Unable to call Bridge.Server.GetPlayerPermission") - end + local hasAdminPermission = IR8.Utilities.HasPermission(source) + TriggerClientEvent(IR8.Config.ClientCallbackPrefix .. "ShowNUI", source, hasAdminPermission) end) ------------------------------------------------- @@ -60,7 +56,7 @@ end -- Return admin privs (bool) lib.callback.register(IR8.Config.ServerCallbackPrefix .. "HasAdminPermissions", function (src) - return IR8.Utilities.HasPermission(IR8.Config.AdminPermissions, IR8.Bridge.Server.GetPlayerPermission(src)) + return IR8.Utilities.HasPermission(src) end) -- Load all tickets @@ -68,7 +64,7 @@ lib.callback.register(IR8.Config.ServerCallbackPrefix .. "Tickets_Load", functio IR8.Utilities.DebugPrint('[EVENT] ' .. IR8.Bridge.Server.GetPlayerIdentifier(src) .. ' loaded ticket list data.') -- Check if user has permissions and get their identifier - local hasAdminPermission = IR8.Utilities.HasPermission(IR8.Config.AdminPermissions, IR8.Bridge.Server.GetPlayerPermission(source)) + local hasAdminPermission = IR8.Utilities.HasPermission(src) local identifier = IR8.Bridge.Server.GetPlayerIdentifier(src) -- Pull tickets based on privelage diff --git a/shared/bridge.lua b/shared/bridge.lua new file mode 100644 index 0000000..96c1bab --- /dev/null +++ b/shared/bridge.lua @@ -0,0 +1,144 @@ +------------------------------------------------------------ +-- CORE BRIDGE DETERMINATION +------------------------------------------------------------ +IR8.Bridge = { + + Core = false, + + Client = { + EventPlayerLoaded = false + }, + + -- Get the core object based on framework provided + GetCoreObject = function() + if not IR8.Bridge.Core then + + -- If esx + if IR8.Config.Framework == 'esx' then + IR8.Bridge.Core = exports['es_extended']:getSharedObject() + IR8.Bridge.Client.EventPlayerLoaded = "esx:playerLoaded" + + -- If qb + elseif IR8.Config.Framework == 'qb' then + IR8.Bridge.Core = exports['qb-core']:GetCoreObject() + IR8.Bridge.Client.EventPlayerLoaded = "QBCore:Client:OnPlayerLoaded" + + -- If standalone + else + IR8.Bridge.Core = "none" + end + end + + return IR8.Bridge.Core + end, + + Server = { + + GetPlayerName = function(src) + + -- If esx + if IR8.Config.Framework == 'esx' and IR8.Bridge.Core then + local xPlayer = IR8.Bridge.Core.GetPlayerFromId(src) + if xPlayer == nil then + return nil + end + return xPlayer.getName() + + -- If qb + elseif IR8.Config.Framework == 'qb' and IR8.Bridge.Core then + local Player = IR8.Bridge.Core.Functions.GetPlayer(src) + return Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname + + -- If standalone + else + return nil + end + end, + + GetPlayerIdentifier = function(src) + + -- If esx + if IR8.Config.Framework == 'esx' and IR8.Bridge.Core then + local xPlayer = IR8.Bridge.Core.GetPlayerFromId(src) + if xPlayer == nil then + return nil + end + return xPlayer.getIdentifier() + + -- If qb + elseif IR8.Config.Framework == 'qb' and IR8.Bridge.Core then + local Player = IR8.Bridge.Core.Functions.GetPlayer(src) + return Player.PlayerData.citizenid + + -- If standalone + else + return nil + end + end, + + GetPlayerPermission = function(src) + local groups = {} + + -- If esx + if IR8.Config.Framework == 'esx' and IR8.Bridge.Core then + local xPlayer = IR8.Bridge.Core.GetPlayerFromId(src) + if xPlayer == nil then + return groups + end + local Group = xPlayer.getGroup() + table.insert(groups, Group) + + -- If qb + elseif IR8.Config.Framework == 'qb' and IR8.Bridge.Core then + local permissions = IR8.Bridge.Core.Functions.GetPermission(src) + + for g, hasPerm in pairs(permissions) do + if hasPerm == true then + table.insert(groups, g) + end + end + + -- If standalone + else + -- If standalone, you need to write logic here for adding permission to group table + -- Example: ["admin"] + -- table.insert(groups, "admin") + end + + return groups + end, + + GetPlayerSourceIfOnlineByIdentifier = function(identifier) + local src = nil + + -- Iterate through ESX online players and find the identifier that matches. + if IR8.Config.Framework == 'esx' and IR8.Bridge.Core then + local xPlayers = IR8.Bridge.Core.GetPlayers() + + for i = 1, #xPlayers, 1 do + local xPlayer = IR8.Bridge.Core.GetPlayerFromId(xPlayers[i]) + + if xPlayer.getIdentifier() == identifier then + src = xPlayer.source + end + end + + -- Find player by citizen id (only returns if online) + elseif IR8.Config.Framework == 'qb' and IR8.Bridge.Core then + local Player = IR8.Bridge.Core.Functions.GetPlayerByCitizenId(identifier) + if Player ~= nil then + src = Player.PlayerData.source + end + + -- If standalone + else + -- If standalone, you need to write logic here for returning player's source id and + -- set it to src variable + end + + return src + end + } +} + +IR8.Bridge.Core = IR8.Config.Framework ~= 'none' and IR8.Bridge.GetCoreObject() or nil diff --git a/shared/config.lua b/shared/config.lua index 1bf05f7..1e8c4b9 100644 --- a/shared/config.lua +++ b/shared/config.lua @@ -14,8 +14,8 @@ IR8.Config = { Framework = "qb", -- "esx" | "qb" | "none" -- Event related vars - ServerCallbackPrefix = "ir8-tickets:Server", -- Change this if you rename the resource folder - ClientCallbackPrefix = "ir8-tickets:Client", -- Change this if you rename the resource folder + ServerCallbackPrefix = GetCurrentResourceName() .. ":Server", + ClientCallbackPrefix = GetCurrentResourceName() .. ":Client", -- Ticket Configuration Variables TicketConfiguration = { @@ -65,10 +65,7 @@ IR8.Config = { }, -- The following groups will have access to ticket administration - -- This uses either ESX Groups or QB Core Permissions - AdminPermissions = { - 'admin' - }, + AdminPermissions = { "ticket.admin" }, -- Command information Commands = { diff --git a/shared/core.lua b/shared/core.lua deleted file mode 100644 index 56fd785..0000000 --- a/shared/core.lua +++ /dev/null @@ -1,137 +0,0 @@ ------------------------------------------------------------- --- CORE BRIDGE DETERMINATION ------------------------------------------------------------- - -IR8.Bridge = { - Core = false, - Client = { - EventPlayerLoaded = false - }, - Server = {} -} - --- Get the core object based on framework provided -function IR8.Bridge.GetCoreObject() - if not IR8.Bridge.Core then - if IR8.Config.Framework == 'esx' then - IR8.Bridge.Core = exports['es_extended']:getSharedObject() - IR8.Bridge.Client.EventPlayerLoaded = "esx:playerLoaded" - elseif IR8.Config.Framework == 'qb' then - IR8.Bridge.Core = exports['qb-core']:GetCoreObject() - IR8.Bridge.Client.EventPlayerLoaded = "QBCore:Client:OnPlayerLoaded" - else - IR8.Bridge.Core = "none" - end - end - - return IR8.Bridge.Core -end - -IR8.Bridge.Core = IR8.Config.Framework ~= 'none' and IR8.Bridge.GetCoreObject() or nil - ------------------------------------------------------------- --- CORE BRIDGE FUNCTIONS ------------------------------------------------------------- - --- Returns the player name based on framework -function IR8.Bridge.Server.GetPlayerName (src) - if IR8.Config.Framework == 'esx' and IR8.Bridge.Core then - local xPlayer = IR8.Bridge.Core.GetPlayerFromId(src) - if xPlayer == nil then return nil end - return xPlayer.getName() - elseif IR8.Config.Framework == 'qb' and IR8.Bridge.Core then - local Player = IR8.Bridge.Core.Functions.GetPlayer(src) - return Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname - - -- If standalone - else - - -- If standalone, you need to write logic here for returning player name - - return nil - end -end - --- Returns the player identifier based on framework -function IR8.Bridge.Server.GetPlayerIdentifier (src) - if IR8.Config.Framework == 'esx' and IR8.Bridge.Core then - local xPlayer = IR8.Bridge.Core.GetPlayerFromId(src) - if xPlayer == nil then return nil end - return xPlayer.getIdentifier() - elseif IR8.Config.Framework == 'qb' and IR8.Bridge.Core then - local Player = IR8.Bridge.Core.Functions.GetPlayer(src) - return Player.PlayerData.citizenid - - -- If standalone - else - - -- If standalone, you need to write logic here for returning player identifier - - return nil - end -end - --- Returns the player permission based on framework --- Returns array of groups player belongs to (Example: ["admin", "mod"]) -function IR8.Bridge.Server.GetPlayerPermission (src) - local groups = {} - - if IR8.Config.Framework == 'esx' and IR8.Bridge.Core then - local xPlayer = IR8.Bridge.Core.GetPlayerFromId(src) - if xPlayer == nil then return groups end - local Group = xPlayer.getGroup() - table.insert(groups, Group) - elseif IR8.Config.Framework == 'qb' and IR8.Bridge.Core then - local permissions = IR8.Bridge.Core.Functions.GetPermission(src) - - for g, hasPerm in pairs(permissions) do - if hasPerm == true then - table.insert(groups, g) - end - end - - -- If standalone - else - - -- If standalone, you need to write logic here for adding permission to group table - -- Example: ["admin"] - -- table.insert(groups, "admin") - - end - - return groups -end - --- Returns player source if they are online -function IR8.Bridge.Server.GetPlayerSourceIfOnlineByIdentifier (identifier) - local src = nil - - -- Iterate through ESX online players and find the identifier that matches. - if IR8.Config.Framework == 'esx' and IR8.Bridge.Core then - local xPlayers = IR8.Bridge.Core.GetPlayers() - - for i=1, #xPlayers, 1 do - local xPlayer = IR8.Bridge.Core.GetPlayerFromId(xPlayers[i]) - - if xPlayer.getIdentifier() == identifier then - src = xPlayer.source - end - end - - -- Find player by citizen id (only returns if online) - elseif IR8.Config.Framework == 'qb' and IR8.Bridge.Core then - local Player = IR8.Bridge.Core.Functions.GetPlayerByCitizenId(identifier) - if Player ~= nil then - src = Player.PlayerData.source - end - - -- If standalone - else - - -- If standalone, you need to write logic here for returning player's source id and - -- set it to src variable - - end - - return src -end \ No newline at end of file diff --git a/shared/utilities.lua b/shared/utilities.lua index bbe128e..3038349 100644 --- a/shared/utilities.lua +++ b/shared/utilities.lua @@ -29,29 +29,22 @@ IR8.Utilities = { -- --------------------------------------------------------- - HasPermission = function (checkAgainst, permission) + HasPermission = function (src) + if not src or src == '' then return false end + local permissions = IR8.Config.AdminPermissions + if not permissions then return false end - if type(checkAgainst) ~= "table" then return false end - - local hasPermission = false + if type(permissions) ~= "table" then + return IsPlayerAceAllowed(src, permissions) + end - if type(permission) == "table" then - for _, check in pairs(checkAgainst) do - for _, perm in pairs(permission) do - if check == perm then - hasPermission = true - end - end - end - else - for _, check in pairs(checkAgainst) do - if permission == check then - hasPermission = true - end + for _, permission in pairs(permissions) do + if IsPlayerAceAllowed(src, permission) then + return true end end - return hasPermission + return false end, ---------------------------------------------------------