Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #93 from Jordan2139/master
Browse files Browse the repository at this point in the history
v2.9.31 - Add additional util functions to core, cache busting query parameter on cad URL
  • Loading branch information
Fireant456 authored Aug 30, 2024
2 parents 71d49c3 + 25bf893 commit 77cd951
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 17 deletions.
248 changes: 247 additions & 1 deletion sonorancad/core/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,250 @@ RegisterNetEvent('SonoranScripts::Call911', function(caller, location, descripti
call911(caller, location, description, postal, plate, function(response)
json.encode(response) -- Not, CB's can only be used on the server side, so we just print this here for you to see.
end, silenceAlert, useCallLocation)
end)
end)

-- Jordan - CAD Utils
dispatchOnline = false
ActiveDispatchers = {}

registerEndpoints = function()
exports['sonorancad']:registerApiType('MODIFY_BLIP', 'emergency')
exports['sonorancad']:registerApiType('ADD_BLIP', 'emergency')
exports['sonorancad']:registerApiType('REMOVE_BLIP', 'emergency')
exports['sonorancad']:registerApiType('GET_BLIPS', 'emergency')
exports['sonorancad']:registerApiType('MODIFY_BLIP', 'emergency')
exports['sonorancad']:registerApiType('CALL_911', 'emergency')
exports['sonorancad']:registerApiType('ADD_CALL_NOTE', 'emergency')
exports['sonorancad']:registerApiType('REMOVE_911', 'emergency')
exports['sonorancad']:registerApiType('LOOKUP', 'general')
exports['sonorancad']:registerApiType('SET_CALL_POSTAL', 'emergency')
exports['sonorancad']:registerApiType('GET_ACTIVE_UNITS', 'emergency')
end
addBlip = function(coords, colorHex, subType, toolTip, icon, dataTable, cb)
local data = {
{
['serverId'] = GetConvar('sonoran_serverId', 1),
['blip'] = {
['id'] = -1,
['subType'] = subType,
['coordinates'] = {
['x'] = coords.x,
['y'] = coords.y
},
['icon'] = icon,
['color'] = colorHex,
['tooltip'] = toolTip,
['data'] = dataTable
}
}
}
exports['sonorancad']:performApiRequest(data, 'ADD_BLIP', function(res)
if cb ~= nil then
cb(res)
end
end)
end
addBlips = function(blips, cb)
exports['sonorancad']:performApiRequest(blips, 'ADD_BLIP', function(res)
if cb ~= nil then
cb(res)
end
end)
end
removeBlip = function(ids, cb)
exports['sonorancad']:performApiRequest({
{
['ids'] = ids
}
}, 'REMOVE_BLIP', function(res)
if cb ~= nil then
cb(res)
end
end)
end
modifyBlipd = function(blipId, dataTable)
exports['sonorancad']:performApiRequest({
{
['id'] = blipId,
['data'] = dataTable
}
}, 'MODIFY_BLIP', function(_)
end)
end
getBlips = function(cb)
local data = {
{
['serverId'] = GetConvar('sonoran_serverId', 1)
}
}
exports['sonorancad']:performApiRequest(data, 'GET_BLIPS', function(res)
if cb ~= nil then
cb(res)
end
end)
end
removeWithSubtype = function(subType, cb)
getBlips(function(res)
local dres = json.decode(res)
local ids = {}
if type(dres) == 'table' then
for _, v in ipairs(dres) do
if v.subType == subType then
table.insert(ids, #ids + 1, v.id)
end
end
if #ids > 0 then
removeBlip(ids, cb)
end
else
warnLog('No blips were returned.')
end
end)
end
call911 = function(caller, location, description, postal, plate, cb)
exports['sonorancad']:performApiRequest({
{
['serverId'] = GetConvar('sonoran_serverId', 1),
['isEmergency'] = true,
['caller'] = caller,
['location'] = location,
['description'] = description,
['metaData'] = {
['plate'] = plate,
['postal'] = postal
}
}
}, 'CALL_911', cb)
end
addTempBlipData = function(blipId, blipData, waitSeconds, returnToData)
exports['sonorancad']:performApiRequest({
{
['id'] = blipId,
['data'] = blipData
}
}, 'MODIFY_BLIP', function(_)

end)

Citizen.CreateThread(function()
Citizen.Wait(waitSeconds * 1000)
exports['sonorancad']:performApiRequest({
{
['id'] = blipId,
['data'] = returnToData
}
}, 'MODIFY_BLIP', function(_)

end)
end)
end
addTempBlipColor = function(blipId, color, waitSeconds, returnToColor)
exports['sonorancad']:performApiRequest({
{
['id'] = blipId,
['color'] = color
}
}, 'MODIFY_BLIP', function(_)

end)

Citizen.CreateThread(function()
Citizen.Wait(waitSeconds * 1000)
exports['sonorancad']:performApiRequest({
{
['id'] = blipId,
['color'] = returnToColor
}
}, 'MODIFY_BLIP', function(_)

end)
end)
end
remove911 = function(callId)
exports['sonorancad']:performApiRequest({
{
['serverId'] = GetConvar('sonoran_serverId', 1),
['callId'] = callId
}
}, 'REMOVE_911', function(_)
end)
end
addCallNote = function(callId, caller)
exports['sonorancad']:performApiRequest({
{
['serverId'] = GetConvar('sonoran_serverId', 1),
['callId'] = callId,
['note'] = caller
}
}, 'ADD_CALL_NOTE', function(_)
end)
end
setCallPostal = function(callId, postal)
exports['sonorancad']:performApiRequest({
{
['serverId'] = GetConvar('sonoran_serverId', 1),
['callId'] = callId,
['postal'] = postal
}
}, 'SET_CALL_POSTAL', function(_)
end)
end
performLookup = function(plate, cb)
exports['sonorancad']:performApiRequest({
{
['types'] = {
2,
3
},
['plate'] = plate,
['partial'] = false,
['first'] = '',
['last'] = '',
['mi'] = ''
}
}, 'LOOKUP', function(res)
if cb ~= nil then
cb(res)
end
end)
end
checkCADSubscriptionType = function()
while exports['sonorancad']:getCadVersion() == nil or exports['sonorancad']:getCadVersion() == -1 do
Citizen.Wait(100)
end
local version = exports['sonorancad']:getCadVersion()
if version ~= 4 and version == 3 then
errorLog('The live map blip feature require the Pro plan for the CAD. It will be disabled for this run.'
.. ' We recommend either upgrading your plan or disabling this feature in the config file.')
Config.integration.SonoranCAD_integration.addLiveMapBlips = false
Config.modified = true
TriggerClientEvent(GetCurrentResourceName() .. '::ModifiedConfig', -1, Config)
elseif version ~= 4 and version ~= 3 and version ~= 5 and version ~= 6 then
errorLog('SonoranCAD integration with this script requires at least a Plus plan for the CAD. It will be'
.. ' disabled for this run. We recommend either upgrading your plan or disabling this' .. ' feature in the config file.')
Config.integration.SonoranCAD_integration.use = false
Config.modified = true
TriggerClientEvent(GetCurrentResourceName() .. '::ModifiedConfig', -1, Config)
end
end
getDispatchStatus = function(_)
return dispatchOnline
end

exports('registerEndpoints', registerEndpoints)
exports('addBlip', addBlip)
exports('addBlips', addBlips)
exports('removeBlip', removeBlip)
exports('modifyBlipd', modifyBlipd)
exports('getBlips', getBlips)
exports('removeWithSubtype', removeWithSubtype)
exports('call911', call911)
exports('addTempBlipData', addTempBlipData)
exports('addTempBlipColor', addTempBlipColor)
exports('remove911', remove911)
exports('addCallNote', addCallNote)
exports('setCallPostal', setCallPostal)
exports('performLookup', performLookup)
exports('checkCADSubscriptionType', checkCADSubscriptionType)
exports('getDispatchStatus', getDispatchStatus)
-- Jordan - CAD Utils
2 changes: 1 addition & 1 deletion sonorancad/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ games {'gta5'}

author 'Sonoran CAD'
description 'Sonoran CAD FiveM Integration'
version '2.9.29'
version '2.9.31'

server_scripts {
'core/http.js'
Expand Down
2 changes: 1 addition & 1 deletion sonorancad/version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"resource" : "2.9.29",
"resource" : "2.9.31",
"testedFxServerVersion": "5932"
}
19 changes: 10 additions & 9 deletions tablet/cl_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ Citizen.CreateThread(function()
InitModuleSize("cad")
InitModuleSize("hud")
InitModuleConfig("hud")

local comId = GetConvar("sonoran_communityID", "")
local convar = GetConvar("sonorantablet_cadUrl", 'https://sonorancad.com/')
local comId = convar:match("comid=(%w+)")
if comId ~= "" then
SetModuleUrl("cad", GetConvar("sonorantablet_cadUrl", 'https://sonorancad.com/login?comid='..comId))
SetModuleUrl("cad", GetConvar("sonorantablet_cadUrl", 'https://sonorancad.com/login?comid='..comId), true)
else
SetModuleUrl("cad", GetConvar("sonorantablet_cadUrl", 'https://sonorancad.com/'))
SetModuleUrl("cad", GetConvar("sonorantablet_cadUrl", 'https://sonorancad.com/'), false)
end

TriggerServerEvent("SonoranCAD::mini:CallSync_S")
Expand Down Expand Up @@ -124,12 +124,13 @@ function DisplayModule(module, show)
end

-- Set Module URL (for iframes)
function SetModuleUrl(module, url)
function SetModuleUrl(module, url, hasComID)
DebugMessage("sending url update message to nui", module)
SendNUIMessage({
type = "setUrl",
url = url,
module = module
module = module,
comId = hasComID
})
end

Expand Down Expand Up @@ -226,7 +227,7 @@ RegisterCommand("minicadrows", function(source, args, rawCommand)
if #args ~= 1 then
PrintChatMessage("Please specify a number of rows to display.")
return
else
else
SetModuleConfigValue("hud", "maxrows", tonumber(args[1]) - 1)
PrintChatMessage("Maximum Mini-CAD call notes set to " .. args[1])
end
Expand Down Expand Up @@ -322,11 +323,11 @@ AddEventHandler("SonoranCAD::mini:CallSync", function(CallCache, EmergencyCache)
})
end)

AddEventHandler('onClientResourceStart', function(resourceName) --When resource starts, stop the GUI showing.
AddEventHandler('onClientResourceStart', function(resourceName) --When resource starts, stop the GUI showing.
if(GetCurrentResourceName() ~= resourceName) then
return
end
SetFocused(false)
SetFocused(false)
TriggerServerEvent("sonoran:tablet:forceCheckApiId")
end)

Expand Down
15 changes: 10 additions & 5 deletions tablet/html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ function attach() {
// Don't reattach to the same call.
if (isAttached(CallCache.active[currCall])) {
for (const call of CallCache.active) {
// Detach from other calls.
// Detach from other calls.
if (isAttached(call)) {
console.log("Detaching from call #" + call.dispatch.callId);
$.post('https://tablet/DetachFromCall', JSON.stringify({callId: call.dispatch.callId}));
}
}
} else {
for (const call of CallCache.active) {
// Detach from other calls.
// Detach from other calls.
if (isAttached(call)) {
console.log("Detaching from call #" + call.dispatch.callId);
$.post('https://tablet/DetachFromCall', JSON.stringify({callId: call.dispatch.callId}));
Expand Down Expand Up @@ -259,7 +259,12 @@ $(function () {
}
else if (event.data.type == "setUrl") {
if (event.data.module == "cad") {
document.getElementById("cadFrame").src = event.data.url;
let date = Date.now()
if (event.data.comId) {
document.getElementById("cadFrame").src = event.data.url + "&cachebuster=" + date;
} else {
document.getElementById("cadFrame").src = event.data.url + "?cachebuster=" + date;
}
document.getElementById('cadFrame').setAttribute("name", Date.now())
}
}
Expand Down Expand Up @@ -304,7 +309,7 @@ $(function () {
switch (data.which) {
case 27:
$.post('https://tablet/NUIFocusOff', JSON.stringify({}));
break;
break;
default:
break;
}
Expand All @@ -322,7 +327,7 @@ function dragElement(elmnt) {
// if present, the header is where you move the DIV from:
document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
} else {
// otherwise, move the DIV from anywhere inside the DIV:
// otherwise, move the DIV from anywhere inside the DIV:
elmnt.onmousedown = dragMouseDown;
}

Expand Down

0 comments on commit 77cd951

Please sign in to comment.