From ae639c94cc035be9e15c9b1dc98c7d59eb6ed59c Mon Sep 17 00:00:00 2001 From: Cocodrulo <142546774+Cocodrulo@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:10:40 +0100 Subject: [PATCH 01/12] =?UTF-8?q?=F0=9F=93=BB=20Moved=20radio=20checks=20t?= =?UTF-8?q?o=20the=20connect=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.lua | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/client.lua b/client.lua index 87e049b..baf78ec 100644 --- a/client.lua +++ b/client.lua @@ -29,6 +29,12 @@ local function SplitStr(inputstr, sep) end local function connecttoradio(channel) + if Config.RestrictedChannels[channel] ~= nil then + if not Config.RestrictedChannels[channel][PlayerData.job.name] and PlayerData.job.onduty then + QBCore.Functions.Notify(Lang:t('restricted_channel_error'), 'error') + return false + end + end RadioChannel = channel if onRadio then exports["pma-voice"]:setRadioChannel(0) @@ -42,6 +48,7 @@ local function connecttoradio(channel) else QBCore.Functions.Notify(Lang:t('joined_to_radio', {channel = channel .. '.00 MHz'}), 'success') end + return true end local function closeEvent() @@ -151,15 +158,7 @@ RegisterNUICallback('joinRadio', function(data, cb) if rchannel ~= nil then if rchannel <= Config.MaxFrequency and rchannel ~= 0 then if rchannel ~= RadioChannel then - if Config.RestrictedChannels[rchannel] ~= nil then - if Config.RestrictedChannels[rchannel][PlayerData.job.name] and PlayerData.job.onduty then - connecttoradio(rchannel) - else - QBCore.Functions.Notify(Lang:t('restricted_channel_error'), 'error') - end - else - connecttoradio(rchannel) - end + connecttoradio(rchannel) else QBCore.Functions.Notify(Lang:t('you_on_radio') , 'error') end @@ -205,18 +204,24 @@ end) RegisterNUICallback("increaseradiochannel", function(_, cb) local newChannel = RadioChannel + 1 - connecttoradio(newChannel) - QBCore.Functions.Notify(Lang:t("increase_decrease_radio_channel", {value = newChannel}), "success") - cb("ok") + local canaccess = connecttoradio(newChannel) + if canaccess then QBCore.Functions.Notify(Lang:t("increase_decrease_radio_channel", {value = newChannel}), "success") end + cb({ + canaccess = canaccess, + channel = newChannel + }) end) RegisterNUICallback("decreaseradiochannel", function(_, cb) if not onRadio then return end local newChannel = RadioChannel - 1 if newChannel >= 1 then - connecttoradio(newChannel) - QBCore.Functions.Notify(Lang:t("increase_decrease_radio_channel", {value = newChannel}), "success") - cb("ok") + local canaccess = connecttoradio(newChannel) + if canaccess then QBCore.Functions.Notify(Lang:t("increase_decrease_radio_channel", {value = newChannel}), "success") end + cb({ + canaccess = canaccess, + channel = newChannel + }) end end) From 99be7f2f1b391af4060ccb5985de2d2c331337cd Mon Sep 17 00:00:00 2001 From: Cocodrulo <142546774+Cocodrulo@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:11:31 +0100 Subject: [PATCH 02/12] =?UTF-8?q?=F0=9F=92=BB=20Fix=20radio=20channel=20no?= =?UTF-8?q?t=20updating=20after=20increasing=20or=20decreasing=20radio=20c?= =?UTF-8?q?hannel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- html/js/script.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/html/js/script.js b/html/js/script.js index 8b900ee..153bf22 100644 --- a/html/js/script.js +++ b/html/js/script.js @@ -41,7 +41,7 @@ $(document).on('click', '#volumeUp', function(e){ $.post('https://qb-radio/volumeUp', JSON.stringify({ channel: $("#channel").val() - })); + })) }); $(document).on('click', '#volumeDown', function(e){ @@ -57,7 +57,11 @@ $(document).on('click', '#decreaseradiochannel', function(e){ $.post('https://qb-radio/decreaseradiochannel', JSON.stringify({ channel: $("#channel").val() - })); + })).then((data) => { + if (data.canacces) { + $("#channel").val(data.channel) + } + }); }); $(document).on('click', '#increaseradiochannel', function(e){ @@ -65,7 +69,11 @@ $(document).on('click', '#increaseradiochannel', function(e){ $.post('https://qb-radio/increaseradiochannel', JSON.stringify({ channel: $("#channel").val() - })); + })).then((data) => { + if (data.canacces) { + $("#channel").val(data.channel) + } + }); }); $(document).on('click', '#poweredOff', function(e){ From f35247706f9fb622848a8ce578f2e3cb40f5b11e Mon Sep 17 00:00:00 2001 From: Cocodrulo <142546774+Cocodrulo@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:51:53 +0100 Subject: [PATCH 03/12] =?UTF-8?q?=F0=9F=94=81=20Done=20same=20changes=20wh?= =?UTF-8?q?en=20join=20in=20radio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.lua | 11 +++++++++-- html/js/script.js | 12 ++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/client.lua b/client.lua index baf78ec..781b82d 100644 --- a/client.lua +++ b/client.lua @@ -158,7 +158,11 @@ RegisterNUICallback('joinRadio', function(data, cb) if rchannel ~= nil then if rchannel <= Config.MaxFrequency and rchannel ~= 0 then if rchannel ~= RadioChannel then - connecttoradio(rchannel) + local canaccess = connecttoradio(rchannel) + cb({ + canaccess = canaccess, + channel = RadioChannel + }) else QBCore.Functions.Notify(Lang:t('you_on_radio') , 'error') end @@ -168,7 +172,10 @@ RegisterNUICallback('joinRadio', function(data, cb) else QBCore.Functions.Notify(Lang:t('invalid_radio') , 'error') end - cb("ok") + cb({ + canaccess = false, + channel = RadioChannel + }) end) RegisterNUICallback('leaveRadio', function(_, cb) diff --git a/html/js/script.js b/html/js/script.js index 153bf22..2ba05ec 100644 --- a/html/js/script.js +++ b/html/js/script.js @@ -15,7 +15,11 @@ $(function() { } else if (data.key == "Enter") { // Enter key $.post('https://qb-radio/joinRadio', JSON.stringify({ channel: $("#channel").val() - })); + })).then((data) => { + if (data.canacces) { + $("#channel").val(data.channel) + } + }); } }; }); @@ -27,7 +31,11 @@ $(document).on('click', '#submit', function(e){ $.post('https://qb-radio/joinRadio', JSON.stringify({ channel: $("#channel").val() - })); + })).then((data) => { + if (data.canacces) { + $("#channel").val(data.channel) + } + }); }); $(document).on('click', '#disconnect', function(e){ From ea5a2abd63e1e6b9e5dd1cc7baa456485295860e Mon Sep 17 00:00:00 2001 From: Cocodrulo <142546774+Cocodrulo@users.noreply.github.com> Date: Sun, 10 Nov 2024 13:08:49 +0000 Subject: [PATCH 04/12] Fixed typo error --- html/js/script.js | 125 +++++++++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 51 deletions(-) diff --git a/html/js/script.js b/html/js/script.js index 2ba05ec..06ebd99 100644 --- a/html/js/script.js +++ b/html/js/script.js @@ -1,104 +1,127 @@ -$(function() { - window.addEventListener('message', function(event) { +$(function () { + window.addEventListener("message", function (event) { if (event.data.type == "open") { - QBRadio.SlideUp() + QBRadio.SlideUp(); } if (event.data.type == "close") { - QBRadio.SlideDown() + QBRadio.SlideDown(); } }); document.onkeyup = function (data) { - if (data.key == "Escape") { // Escape key - $.post('https://qb-radio/escape', JSON.stringify({})); - } else if (data.key == "Enter") { // Enter key - $.post('https://qb-radio/joinRadio', JSON.stringify({ - channel: $("#channel").val() - })).then((data) => { - if (data.canacces) { - $("#channel").val(data.channel) + if (data.key == "Escape") { + // Escape key + $.post("https://qb-radio/escape", JSON.stringify({})); + } else if (data.key == "Enter") { + // Enter key + $.post( + "https://qb-radio/joinRadio", + JSON.stringify({ + channel: $("#channel").val(), + }) + ).then((data) => { + if (data.canaccess) { + $("#channel").val(data.channel); } }); } }; }); -QBRadio = {} +QBRadio = {}; -$(document).on('click', '#submit', function(e){ +$(document).on("click", "#submit", function (e) { e.preventDefault(); - $.post('https://qb-radio/joinRadio', JSON.stringify({ - channel: $("#channel").val() - })).then((data) => { - if (data.canacces) { - $("#channel").val(data.channel) + $.post( + "https://qb-radio/joinRadio", + JSON.stringify({ + channel: $("#channel").val(), + }) + ).then((data) => { + if (data.canaccess) { + $("#channel").val(data.channel); } }); }); -$(document).on('click', '#disconnect', function(e){ +$(document).on("click", "#disconnect", function (e) { e.preventDefault(); - $.post('https://qb-radio/leaveRadio'); + $.post("https://qb-radio/leaveRadio"); }); -$(document).on('click', '#volumeUp', function(e){ +$(document).on("click", "#volumeUp", function (e) { e.preventDefault(); - $.post('https://qb-radio/volumeUp', JSON.stringify({ - channel: $("#channel").val() - })) + $.post( + "https://qb-radio/volumeUp", + JSON.stringify({ + channel: $("#channel").val(), + }) + ); }); -$(document).on('click', '#volumeDown', function(e){ +$(document).on("click", "#volumeDown", function (e) { e.preventDefault(); - $.post('https://qb-radio/volumeDown', JSON.stringify({ - channel: $("#channel").val() - })); + $.post( + "https://qb-radio/volumeDown", + JSON.stringify({ + channel: $("#channel").val(), + }) + ); }); -$(document).on('click', '#decreaseradiochannel', function(e){ +$(document).on("click", "#decreaseradiochannel", function (e) { e.preventDefault(); - $.post('https://qb-radio/decreaseradiochannel', JSON.stringify({ - channel: $("#channel").val() - })).then((data) => { - if (data.canacces) { - $("#channel").val(data.channel) + $.post( + "https://qb-radio/decreaseradiochannel", + JSON.stringify({ + channel: $("#channel").val(), + }) + ).then((data) => { + if (data.canaccess) { + $("#channel").val(data.channel); } }); }); -$(document).on('click', '#increaseradiochannel', function(e){ +$(document).on("click", "#increaseradiochannel", function (e) { e.preventDefault(); - $.post('https://qb-radio/increaseradiochannel', JSON.stringify({ - channel: $("#channel").val() - })).then((data) => { - if (data.canacces) { - $("#channel").val(data.channel) + $.post( + "https://qb-radio/increaseradiochannel", + JSON.stringify({ + channel: $("#channel").val(), + }) + ).then((data) => { + if (data.canaccess) { + $("#channel").val(data.channel); } }); }); -$(document).on('click', '#poweredOff', function(e){ +$(document).on("click", "#poweredOff", function (e) { e.preventDefault(); - $.post('https://qb-radio/poweredOff', JSON.stringify({ - channel: $("#channel").val() - })); + $.post( + "https://qb-radio/poweredOff", + JSON.stringify({ + channel: $("#channel").val(), + }) + ); }); -QBRadio.SlideUp = function() { +QBRadio.SlideUp = function () { $(".container").css("display", "block"); - $(".radio-container").animate({bottom: "6vh",}, 250); -} + $(".radio-container").animate({ bottom: "6vh" }, 250); +}; -QBRadio.SlideDown = function() { - $(".radio-container").animate({bottom: "-110vh",}, 400, function(){ +QBRadio.SlideDown = function () { + $(".radio-container").animate({ bottom: "-110vh" }, 400, function () { $(".container").css("display", "none"); }); -} +}; From 80b314e8a00ec9266740f0ad246bd256b7dbe2bf Mon Sep 17 00:00:00 2001 From: Cocodrulo <142546774+Cocodrulo@users.noreply.github.com> Date: Sun, 10 Nov 2024 13:09:13 +0000 Subject: [PATCH 05/12] Removed double notifications and checked min/max frequencies --- client.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client.lua b/client.lua index 781b82d..a7ddf9c 100644 --- a/client.lua +++ b/client.lua @@ -29,6 +29,7 @@ local function SplitStr(inputstr, sep) end local function connecttoradio(channel) + if channel > Config.MaxFrequency or channel <= 0 then QBCore.Functions.Notify(Lang:t('restricted_channel_error'), 'error') return false end if Config.RestrictedChannels[channel] ~= nil then if not Config.RestrictedChannels[channel][PlayerData.job.name] and PlayerData.job.onduty then QBCore.Functions.Notify(Lang:t('restricted_channel_error'), 'error') @@ -212,7 +213,6 @@ end) RegisterNUICallback("increaseradiochannel", function(_, cb) local newChannel = RadioChannel + 1 local canaccess = connecttoradio(newChannel) - if canaccess then QBCore.Functions.Notify(Lang:t("increase_decrease_radio_channel", {value = newChannel}), "success") end cb({ canaccess = canaccess, channel = newChannel @@ -224,7 +224,6 @@ RegisterNUICallback("decreaseradiochannel", function(_, cb) local newChannel = RadioChannel - 1 if newChannel >= 1 then local canaccess = connecttoradio(newChannel) - if canaccess then QBCore.Functions.Notify(Lang:t("increase_decrease_radio_channel", {value = newChannel}), "success") end cb({ canaccess = canaccess, channel = newChannel From b3e7d1fa2d4aa3de2a0fbbdba5acda17e5afaf29 Mon Sep 17 00:00:00 2001 From: Cocodrulo Date: Sun, 10 Nov 2024 21:45:29 +0000 Subject: [PATCH 06/12] Add all radio images --- fxmanifest.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fxmanifest.lua b/fxmanifest.lua index 980272c..55358ff 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -23,7 +23,7 @@ files { 'html/ui.html', 'html/js/script.js', 'html/css/style.css', - 'html/img/radio.png' + 'html/img/radio*.png' } dependency 'pma-voice' From 86ff76c2b96b14cc2f3be3a7e6a868cacc0eed82 Mon Sep 17 00:00:00 2001 From: Cocodrulo Date: Sun, 10 Nov 2024 21:46:48 +0000 Subject: [PATCH 07/12] Removed increase_decrease_radio_channed locale entry since is not longer use --- locales/en.lua | 1 - locales/pt-br.lua | 1 - 2 files changed, 2 deletions(-) diff --git a/locales/en.lua b/locales/en.lua index f3066d5..634e50a 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -9,7 +9,6 @@ local Translations ={ ['volume_radio'] = 'New volume %{value}', ['decrease_radio_volume'] = 'The radio is already set to maximum volume', ['increase_radio_volume'] = 'The radio is already set to the lowest volume', - ['increase_decrease_radio_channel'] = 'New channel %{value}', } Lang = Lang or Locale:new({ diff --git a/locales/pt-br.lua b/locales/pt-br.lua index af3fd97..dc506ab 100644 --- a/locales/pt-br.lua +++ b/locales/pt-br.lua @@ -9,7 +9,6 @@ local Translations = { ['volume_radio'] = 'Novo volume %{value}', ['decrease_radio_volume'] = 'O rádio já está ajustado para o volume máximo', ['increase_radio_volume'] = 'O rádio já está ajustado para o volume mais baixo', - ['increase_decrease_radio_channel'] = 'Novo canal %{value}', } if GetConvar('qb_locale', 'en') == 'pt-br' then From 3611b0ecaf506061e1ee59b89d02b30c17fc5127 Mon Sep 17 00:00:00 2001 From: Cocodrulo Date: Sun, 10 Nov 2024 21:47:42 +0000 Subject: [PATCH 08/12] Force channel to be greater than 0 --- client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.lua b/client.lua index a7ddf9c..dbb0063 100644 --- a/client.lua +++ b/client.lua @@ -157,7 +157,7 @@ end) RegisterNUICallback('joinRadio', function(data, cb) local rchannel = tonumber(data.channel) if rchannel ~= nil then - if rchannel <= Config.MaxFrequency and rchannel ~= 0 then + if rchannel <= Config.MaxFrequency and rchannel > 0 then if rchannel ~= RadioChannel then local canaccess = connecttoradio(rchannel) cb({ From fc12620b787b0c724b42f8a6d64a96fdffcfefe3 Mon Sep 17 00:00:00 2001 From: Cocodrulo Date: Sun, 10 Nov 2024 21:48:41 +0000 Subject: [PATCH 09/12] Change number values to boolean values to match better the natives docs --- client.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client.lua b/client.lua index dbb0063..f3ae0c2 100644 --- a/client.lua +++ b/client.lua @@ -69,9 +69,9 @@ local function toggleRadioAnimation(pState) LoadAnimDic("cellphone@") if pState then TriggerEvent("attachItemRadio","radio01") - TaskPlayAnim(PlayerPedId(), "cellphone@", "cellphone_text_read_base", 2.0, 3.0, -1, 49, 0, 0, 0, 0) - radioProp = CreateObject(`prop_cs_hand_radio`, 1.0, 1.0, 1.0, 1, 1, 0) - AttachEntityToEntity(radioProp, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), 57005), 0.14, 0.01, -0.02, 110.0, 120.0, -15.0, 1, 0, 0, 0, 2, 1) + TaskPlayAnim(PlayerPedId(), "cellphone@", "cellphone_text_read_base", 2.0, 3.0, -1, 49, 0, false, false, false) + radioProp = CreateObject(`prop_cs_hand_radio`, 1.0, 1.0, 1.0, true, true, false) + AttachEntityToEntity(radioProp, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), 57005), 0.14, 0.01, -0.02, 110.0, 120.0, -15.0, true, false, false, false, 2, true) else StopAnimTask(PlayerPedId(), "cellphone@", "cellphone_text_read_base", 1.0) ClearPedTasks(PlayerPedId()) From 4198ef8fc9b18a8e095c5fb7e6735f8c77ebc606 Mon Sep 17 00:00:00 2001 From: Cocodrulo <142546774+Cocodrulo@users.noreply.github.com> Date: Tue, 12 Nov 2024 19:20:35 +0000 Subject: [PATCH 10/12] Solved vulnerability of `offduty not whitelisted` connection --- client.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client.lua b/client.lua index f3ae0c2..8c1fdcf 100644 --- a/client.lua +++ b/client.lua @@ -31,7 +31,8 @@ end local function connecttoradio(channel) if channel > Config.MaxFrequency or channel <= 0 then QBCore.Functions.Notify(Lang:t('restricted_channel_error'), 'error') return false end if Config.RestrictedChannels[channel] ~= nil then - if not Config.RestrictedChannels[channel][PlayerData.job.name] and PlayerData.job.onduty then + local isJobWhitelisted = Config.RestrictedChannels[channel][PlayerData.job.name] + if (not isJobWhitelisted) or (isJobWhitelisted and not PlayerData.job.onduty) then QBCore.Functions.Notify(Lang:t('restricted_channel_error'), 'error') return false end From 2d859c8b50bb63dbdba98fdc56060539003c7fc4 Mon Sep 17 00:00:00 2001 From: Cocodrulo <142546774+Cocodrulo@users.noreply.github.com> Date: Tue, 12 Nov 2024 21:41:22 +0000 Subject: [PATCH 11/12] Fixed stupid conditional --- client.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client.lua b/client.lua index 8c1fdcf..22592a9 100644 --- a/client.lua +++ b/client.lua @@ -31,8 +31,7 @@ end local function connecttoradio(channel) if channel > Config.MaxFrequency or channel <= 0 then QBCore.Functions.Notify(Lang:t('restricted_channel_error'), 'error') return false end if Config.RestrictedChannels[channel] ~= nil then - local isJobWhitelisted = Config.RestrictedChannels[channel][PlayerData.job.name] - if (not isJobWhitelisted) or (isJobWhitelisted and not PlayerData.job.onduty) then + if not Config.RestrictedChannels[channel][PlayerData.job.name] or not PlayerData.job.onduty then QBCore.Functions.Notify(Lang:t('restricted_channel_error'), 'error') return false end From 7e0dee3961231163f569a5d9f55b61730ab462b8 Mon Sep 17 00:00:00 2001 From: Cocodrulo <142546774+Cocodrulo@users.noreply.github.com> Date: Tue, 12 Nov 2024 21:58:49 +0000 Subject: [PATCH 12/12] Removed unused translation in de.lua --- locales/de.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/locales/de.lua b/locales/de.lua index 003ebd2..4af8be4 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -9,7 +9,6 @@ local Translations ={ ['volume_radio'] = 'Neue Lautstärke %{value}', ['decrease_radio_volume'] = 'Das Radio ist bereits auf maximaler Lautstärke eingestellt', ['increase_radio_volume'] = 'Das Radio ist bereits auf der niedrigsten Lautstärke eingestellt', - ['increase_decrease_radio_channel'] = 'Neuer Kanal %{value}', } if GetConvar('qb_locale', 'en') == 'de' then