Skip to content

Commit

Permalink
Merge pull request #855 from bitpredator/dev
Browse files Browse the repository at this point in the history
feat: feat in game system tickets
  • Loading branch information
bitpredator authored Oct 6, 2024
2 parents 2ffee79 + d2d58b8 commit c1ba5ec
Show file tree
Hide file tree
Showing 15 changed files with 2,630 additions and 0 deletions.
674 changes: 674 additions & 0 deletions server-data/resources/[esx_addons]/tickets/LICENSE

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions server-data/resources/[esx_addons]/tickets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Ticket Manager

In-game all-in-one solution for ticket management for both ESX & QB Core FiveM servers.

Features:

- All in-game based
- Webhook Configuration
- Theme is configurable
- Permissions are configurable
- Categories included & are configurable
- Statuses are configurable (Color, Replies allowed, Label)
- Configurable command
- Players can provide the position, title, message, and category for tickets
- Players & Staff members can reply to tickets
- Players receive notifications (if online) when a reply or status is changed on their tickets.

If you need any support, feel free to reach out to us via our Discord: https://discord.gg/7NATz2Yw5a

### Dependencies

- Supports both ESX and QBCore
- oxmysql
- ox_lib

### Installation

`NOTE: As of v1.1.0, permissions system has changed to run off of ace permissions in your server.cfg`

- 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`:
- Be sure to open `/shared/config.lua` and set your framework and any other settings you may need to alter.

```
# Ticket Administration Ace
add_ace group.admin ticket.admin allow
```

### Webhook Configuration

You can set your webhook configuration from server/main.lua at the top of the file.
26 changes: 26 additions & 0 deletions server-data/resources/[esx_addons]/tickets/__install/database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
create table ir8_ticket
(
id int auto_increment
primary key,
category varchar(255) null,
title varchar(255) null,
message longtext null,
name varchar(255) null,
identifier varchar(255) null,
position varchar(1000) null,
status varchar(50) null,
date timestamp default current_timestamp() not null,
updated timestamp default current_timestamp() not null on update current_timestamp()
);

create table ir8_ticket_message
(
id int auto_increment
primary key,
ticket_id int null,
message longtext null,
name varchar(255) null,
identifier varchar(255) null,
date timestamp default current_timestamp() not null
);

160 changes: 160 additions & 0 deletions server-data/resources/[esx_addons]/tickets/client/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
-------------------------------------------------
--
-- STATE
--
-------------------------------------------------
PlayerData = {}
PlayerLoaded = false

-------------------------------------------------
--
-- EVENTS
--
-------------------------------------------------

-- Init event on resource start
function init()
IR8.Utilities.DebugPrint("[Method] Init invoked")

-- Check for admin privs
local admin = lib.callback.await(IR8.Config.ServerCallbackPrefix .. "HasAdminPermissions", false)

SendNUIMessage({
action = "init",
debug = IR8.Config.Debugging,
admin = admin,
ticketConfiguration = IR8.Config.TicketConfiguration,
})
end

-- PlayerLoaded event handler based on framework
if IR8.Bridge.Client.EventPlayerLoaded then
RegisterNetEvent(IR8.Bridge.Client.EventPlayerLoaded)
AddEventHandler(IR8.Bridge.Client.EventPlayerLoaded, function()
if not PlayerLoaded then
init()
end
end)
else
if not PlayerLoaded then
init()
end
end

-- Show the NUI
RegisterNetEvent(IR8.Config.ClientCallbackPrefix .. "ShowNUI")
AddEventHandler(IR8.Config.ClientCallbackPrefix .. "ShowNUI", function(admin)
-- Loads the tickets on each show request
local tickets = lib.callback.await(IR8.Config.ServerCallbackPrefix .. "Tickets_Load", false)
SendNUIMessage({ action = "tickets", tickets = tickets })

-- Show UI
SendNUIMessage({ action = "show", admin = admin, theme = IR8.Config.Theme and IR8.Config.Theme or false })
SetNuiFocus(true, true)
end)

-------------------------------------------------
--
-- NUI EVENTS
--
-------------------------------------------------

-- Hide NUI
RegisterNUICallback("hide", function(_, cb)
SendNUIMessage({ action = "hide" })
SetNuiFocus(false, false)
cb({})
end)

-- Retrieve ticket information and send back
RegisterNUICallback("ticket", function(data, cb)
-- Get ticket information
local res = lib.callback.await(IR8.Config.ServerCallbackPrefix .. "Ticket_Load", false, data)

-- Send response
cb(res)
end)

-- Retrieve ticket information and send back
RegisterNUICallback("status", function(data, cb)
-- Update status
local res = lib.callback.await(IR8.Config.ServerCallbackPrefix .. "Ticket_UpdateStatus", false, data)

if res.success then
local tickets = lib.callback.await(IR8.Config.ServerCallbackPrefix .. "Tickets_Load", false)
SendNUIMessage({ action = "tickets", tickets = tickets })
end

-- Send response
cb({ success = true })
end)

-- Retrieve list of tickets and send back
RegisterNUICallback("tickets", function(_, cb)
-- Get list of tickets
local tickets = lib.callback.await(IR8.Config.ServerCallbackPrefix .. "Tickets_Load", false)
SendNUIMessage({ action = "tickets", tickets = tickets })

-- Send response
cb({ success = true })
end)

-- Ticket reply creation
RegisterNUICallback("reply", function(data, cb)
local res = lib.callback.await(IR8.Config.ServerCallbackPrefix .. "Ticket_CreateReply", false, data)
cb(res)
end)

-- Ticket creation
RegisterNUICallback("create", function(data, cb)
-- If position is included
if data.position then
local playerCoords = GetEntityCoords(PlayerPedId())
data.position = json.encode({
x = playerCoords.x,
y = playerCoords.y,
z = playerCoords.z,
})
end

local res = lib.callback.await(IR8.Config.ServerCallbackPrefix .. "Ticket_Create", false, data)

if res.success then
local tickets = lib.callback.await(IR8.Config.ServerCallbackPrefix .. "Tickets_Load", false)
SendNUIMessage({ action = "tickets", tickets = tickets })
end

cb(res)
end)

-- Teleport request
RegisterNUICallback("teleport", function(data, cb)
SetEntityCoords(PlayerPedId(), data.x, data.y, data.z)
cb({})
end)

-------------------------------------------------
--
-- ON RESOURCE START
--
-------------------------------------------------
AddEventHandler("onResourceStart", function(resource)
if resource == GetCurrentResourceName() then
if not PlayerLoaded then
PlayerLoaded = true
Wait(500)
init()
end
end
end)

-------------------------------------------------
--
-- CLEANUP ON RESOURCE STOP
--
-------------------------------------------------
AddEventHandler("onResourceStop", function(resource)
if resource == GetCurrentResourceName() then
-- Any cleanup if necessary.If not, remove this
end
end)
31 changes: 31 additions & 0 deletions server-data/resources/[esx_addons]/tickets/fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
fx_version 'cerulean'
game 'gta5'
author 'IR8 Scripts'
description 'Ticket Manager'
version '1.1.1'
lua54 'yes'

client_script 'client/main.lua'

server_script {
'@oxmysql/lib/MySQL.lua',
'server/main.lua'
}

shared_script {
"@ox_lib/init.lua",
"shared/config.lua",
"shared/bridge.lua",
"shared/utilities.lua",
"shared/database.lua"
}

ui_page {
'nui/index.html',
}

files {
'nui/index.html',
'nui/js/script.js',
'nui/css/style.css'
}
Loading

0 comments on commit c1ba5ec

Please sign in to comment.