Skip to content

Commit

Permalink
Merge pull request #41 from Jordan2139/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Fireant456 authored Jun 26, 2024
2 parents 597e475 + ec90ab4 commit c8185df
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 43 deletions.
2 changes: 1 addition & 1 deletion sonorancms/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ games {'gta5'}
author 'Sonoran Software Systems'
real_name 'Sonoran CMS FiveM Integration'
description 'Sonoran CMS to FiveM translation layer'
version '1.5.8'
version '1.5.9'
lua54 'yes'

server_scripts {'server/*.lua', 'config.lua', 'server/util/unzip.js', 'server/util/http.js', 'server/util/sonoran.js', 'server/util/utils.js', '@oxmysql/lib/MySQL.lua', 'server/util/imageHandler.js', 'server/modules/**/*_sv.js', 'server/modules/**/*_sv.lua'}
Expand Down
103 changes: 62 additions & 41 deletions sonorancms/server/pushEvents.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ end
---@param inputString string
---@return string
local function escapeQuotes(inputString)
inputString = inputString.gsub(inputString, "([%c%z\\\"'])", {
["\\"] = "\\\\",
["\""] = "\\\"",
["'"] = "\\'",
["\b"] = "\\b",
["\f"] = "\\f",
["\n"] = "\\n",
["\r"] = "\\r",
["\t"] = "\\t",
["\0"] = "\\0",
inputString = inputString.gsub(inputString, '([%c%z\\"\'])', {
['\\'] = '\\\\',
['"'] = '\\"',
['\''] = '\\\'',
['\b'] = '\\b',
['\f'] = '\\f',
['\n'] = '\\n',
['\r'] = '\\r',
['\t'] = '\\t',
['\0'] = '\\0'
})
return inputString
return inputString
end

--- Encodes the combinale array for items to be correct
Expand Down Expand Up @@ -234,16 +234,17 @@ local function shiftToHour(hour)
end

-- Function to determine whether a table is a string_literal_key table or a plain_identifier_key table
function checkKeyTypes(tbl)
local keyTypes = {}
for key, _ in pairs(tbl) do
if type(key) == "string" and key:match("^[%a_][%w_]*$") then
keyTypes[key] = "plain"
else
keyTypes[key] = "string"
end
end
return keyTypes
local function checkObjType(data)
local jobs = {};
local quoted_pattern = '%[\'(.-)\'%]'
local unquoted_pattern = '%s(%a[%w_]*)%s*=%s*{'
for job_id in data:gmatch(quoted_pattern) do
jobs[job_id] = 'quoted'
end
for job_id in data:gmatch(unquoted_pattern) do
jobs[job_id] = 'unquoted'
end
return jobs
end

CreateThread(function()
Expand Down Expand Up @@ -595,7 +596,7 @@ CreateThread(function()
print('Error: QBShared.Gangs table is missing or empty.')
return
end
local tableType = checkKeyTypes(loadedGangs)
local jobTypes = checkObjType(originalData)
validGangs = filterGangs(loadedGangs)
if not validGangs[data.data.gangId] then
TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Error: Gang ' .. data.data.gangId .. ' does not exist.')
Expand All @@ -608,7 +609,7 @@ CreateThread(function()
}
table.insert(lines, 'QBShared.Gangs = {')
for gangName, gangData in pairs(gangsTable) do
if tableType.gangName == 'string' then
if jobTypes[gangName] == 'quoted' then
local gangLine = '\t[\'' .. gangName .. '\'] = {'
table.insert(lines, gangLine)
else
Expand Down Expand Up @@ -668,7 +669,7 @@ CreateThread(function()
print('Error: QBShared.Gangs table is missing or empty.')
return
end
local tableType = checkKeyTypes(loadedGangs)
local jobTypes = checkObjType(originalData)
validGangs = filterGangs(loadedGangs)
if not validGangs[data.data.id] then
TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Error: Gang ' .. data.data.id .. ' does not exist.')
Expand Down Expand Up @@ -697,7 +698,7 @@ CreateThread(function()
}
table.insert(lines, 'QBShared.Gangs = {')
for gangName, gangData in pairs(gangsTable) do
if tableType.gangName == 'string' then
if jobTypes[gangName] == 'quoted' then
local gangLine = '\t[\'' .. gangName .. '\'] = {'
table.insert(lines, gangLine)
else
Expand Down Expand Up @@ -757,7 +758,7 @@ CreateThread(function()
print('Error: QBShared.Gangs table is missing or empty.')
return
end
local tableType = checkKeyTypes(loadedGangs)
local jobTypes = checkObjType(originalData)
validGangs = filterGangs(loadedGangs)
if validGangs[data.data.id] then
TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Error: Gang ' .. data.data.id .. ' already exists.')
Expand Down Expand Up @@ -790,7 +791,7 @@ CreateThread(function()
}
table.insert(lines, 'QBShared.Gangs = {')
for gangName, gangData in pairs(gangsTable) do
if tableType.gangName == 'string' then
if jobTypes[gangName] == 'quoted' then
local gangLine = '\t[\'' .. gangName .. '\'] = {'
table.insert(lines, gangLine)
else
Expand Down Expand Up @@ -850,7 +851,7 @@ CreateThread(function()
print('Error: QBShared.Jobs table is missing or empty.')
return
end
local tableType = checkKeyTypes(loadedJobs)
local jobTypes = checkObjType(originalData)
validJobs = filterJobs(loadedJobs)
if not validJobs[data.data.jobId] then
TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Error: Job ' .. data.data.jobId .. ' does not exist.')
Expand All @@ -864,7 +865,7 @@ CreateThread(function()
table.insert(lines, 'QBShared.ForceJobDefaultDutyAtLogin = true -- true: Force duty state to jobdefaultDuty | false: set duty state from database last saved')
table.insert(lines, 'QBShared.Jobs = {')
for jobName, jobData in pairs(jobTable) do
if tableType.jobName == 'string' then
if jobTypes[jobName] == 'quoted' then
local gangLine = '\t[\'' .. jobName .. '\'] = {'
table.insert(lines, gangLine)
else
Expand Down Expand Up @@ -931,12 +932,12 @@ CreateThread(function()
return
end
func()
local jobTypes = checkObjType(originalData)
local loadedJobs = tempEnv.QBShared and tempEnv.QBShared.Jobs
if not loadedJobs or next(loadedJobs) == nil then
print('Error: QBShared.Jobs table is missing or empty.')
return
end
local tableType = checkKeyTypes(loadedJobs)
validJobs = filterJobs(loadedJobs)
if not validJobs[data.data.id] then
TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Error: Job ' .. data.data.id .. ' does not exist.')
Expand Down Expand Up @@ -971,7 +972,7 @@ CreateThread(function()
table.insert(lines, 'QBShared.ForceJobDefaultDutyAtLogin = true -- true: Force duty state to jobdefaultDuty | false: set duty state from database last saved')
table.insert(lines, 'QBShared.Jobs = {')
for jobName, jobData in pairs(jobTable) do
if tableType.jobName == 'string' then
if jobTypes[jobName] == 'quoted' then
local gangLine = '\t[\'' .. jobName .. '\'] = {'
table.insert(lines, gangLine)
else
Expand Down Expand Up @@ -1043,7 +1044,7 @@ CreateThread(function()
print('Error: QBShared.Jobs table is missing or empty.')
return
end
local tableType = checkKeyTypes(loadedJobs)
local jobTypes = checkObjType(originalData)
validJobs = filterJobs(loadedJobs)
if validJobs[data.data.id] then
TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Error: Job ' .. data.data.id .. ' already exist.')
Expand Down Expand Up @@ -1084,7 +1085,7 @@ CreateThread(function()
table.insert(lines, 'QBShared.ForceJobDefaultDutyAtLogin = true -- true: Force duty state to jobdefaultDuty | false: set duty state from database last saved')
table.insert(lines, 'QBShared.Jobs = {')
for jobName, jobData in pairs(jobTable) do
if tableType.jobName == 'string' then
if jobTypes[jobName] == 'quoted' then
local gangLine = '\t[\'' .. jobName .. '\'] = {'
table.insert(lines, gangLine)
else
Expand Down Expand Up @@ -1172,6 +1173,7 @@ CreateThread(function()
print('Error: QBShared.Items table is missing or empty.')
return
end
local itemTypes = checkObjType(originalData)
validItems = filterJobs(loadedItems)
if validItems[data.data.name] then
TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Error: Item ' .. data.data.name .. ' already exist.')
Expand All @@ -1196,8 +1198,13 @@ CreateThread(function()
}
table.insert(lines, 'QBShared.Items = {')
for itemName, itemData in pairs(itemTable) do
local itemLine = '\t[\'' .. itemName .. '\'] = {'
table.insert(lines, itemLine)
if itemTypes[itemName] == 'quoted' then
local itemLine = '\t[\'' .. itemName .. '\'] = {'
table.insert(lines, itemLine)
else
local itemLine = '\t' .. itemName .. ' = {'
table.insert(lines, itemLine)
end
local labelLine = '\t\tlabel = ' .. string.format('\'%s\',', itemData.label)
table.insert(lines, labelLine)
if itemData.type and itemData.type ~= nil then
Expand Down Expand Up @@ -1275,6 +1282,7 @@ CreateThread(function()
print('Error: QBShared.Items table is missing or empty.')
return
end
local itemTypes = checkObjType(originalData)
validItems = filterJobs(loadedItems)
if not validItems[data.data.name] then
TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Error: Item ' .. data.data.name .. ' does not exist.')
Expand All @@ -1299,7 +1307,13 @@ CreateThread(function()
}
table.insert(lines, 'QBShared.Items = {')
for itemName, itemData in pairs(itemTable) do
local itemLine = '\t[\'' .. itemName .. '\'] = {'
if itemTypes[itemName] == 'quoted' then
local itemLine = '\t[\'' .. itemName .. '\'] = {'
table.insert(lines, itemLine)
else
local itemLine = '\t' .. itemName .. ' = {'
table.insert(lines, itemLine)
end
table.insert(lines, itemLine)
local labelLine = '\t\tlabel = ' .. string.format('\'%s\',', itemData.label)
table.insert(lines, labelLine)
Expand Down Expand Up @@ -1379,6 +1393,7 @@ CreateThread(function()
print('Error: QBShared.Items table is missing or empty.')
return
end
local itemTypes = checkObjType(originalData)
validItems = filterJobs(loadedItems)
if not validItems[data.data.itemName] then
TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'Error: Item ' .. data.data.itemName .. ' does not exist.')
Expand All @@ -1391,7 +1406,13 @@ CreateThread(function()
}
table.insert(lines, 'QBShared.Items = {')
for itemName, itemData in pairs(itemTable) do
local itemLine = '\t[\'' .. itemName .. '\'] = {'
if itemTypes[itemName] == 'quoted' then
local itemLine = '\t[\'' .. itemName .. '\'] = {'
table.insert(lines, itemLine)
else
local itemLine = '\t' .. itemName .. ' = {'
table.insert(lines, itemLine)
end
table.insert(lines, itemLine)
local labelLine = '\t\tlabel = ' .. string.format('\'%s\',', itemData.label)
table.insert(lines, labelLine)
Expand Down Expand Up @@ -2165,7 +2186,7 @@ local function requestGarageData()
TriggerEvent('SonoranCMS::core:writeLog', 'error', 'Error getting garage data from jg-advancedgarages, the export getAllGarages() is not available. Please update your jg-advancedgarages resource.')
end
elseif GetResourceState('ak47_qb_garage') == 'started' then
local sqlData = MySQL.query('SELECT * FROM `ak47_qb_garage', function(row)
local sqlData = MySQL.query('SELECT * FROM `ak47_qb_garage`', function(row)
if not row then
TriggerEvent('SonoranCMS::core:writeLog', 'debug', 'No garages found in ak47_qb_garage')
else
Expand All @@ -2182,7 +2203,7 @@ local function requestGarageData()
spawnPoint = {
spawns[1].x,
spawns[1].y,
spawns[1].z,
spawns[1].z
},
putVehicle = {
spawns[1].x,
Expand Down Expand Up @@ -2369,9 +2390,9 @@ function handleDataRequest(data)
return
end
if GetResourceState('qb-garages') ~= 'started' and GetResourceState('cd_garage') ~= 'started' and GetResourceState('qs-advancedgarages') ~= 'started' and GetResourceState('jg-advancedgarages')
~= 'started' then
~= 'started' and GetResourceState('ak47_qb_garage') ~= 'started' then
TriggerEvent('SonoranCMS::core:writeLog', 'warn',
'qb-garages, qs-advancedgarages, jg-advancedgarages and cd_garage are not started. The garage data will be sent as empty currently. If you do not use the SonoranCMS Game Panel you can ignore this.')
'qb-garages, qs-advancedgarages, jg-advancedgarages, ak47_qb_garage and cd_garage are not started. The garage data will be sent as empty currently. If you do not use the SonoranCMS Game Panel you can ignore this.')
table.insert(errors, {
code = 'ERR_GARAGE_NOT_STARTED',
message = 'qb-garages, qs-advancedgarages, jg-advancedgarages and cd_garage are not started. The garage data will be sent as empty currently.'
Expand Down
2 changes: 1 addition & 1 deletion sonorancms/version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"resource": "1.5.8",
"resource": "1.5.9",
"testedFxServerVersion": "7290"
}

0 comments on commit c8185df

Please sign in to comment.