From f2da85660da307003a4f7c3feaf7970526140093 Mon Sep 17 00:00:00 2001 From: sl1ki0 <126953670+sl1ki0@users.noreply.github.com> Date: Sun, 16 Jun 2024 16:23:26 +0300 Subject: [PATCH 1/9] added AutoPostalOnAttach event --- src/types/events.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/types/events.ts b/src/types/events.ts index 69e3979..aa81db7 100644 --- a/src/types/events.ts +++ b/src/types/events.ts @@ -99,6 +99,8 @@ export enum ClientEvents { RequestTrafficStopFlow = "sna-sync:request-traffic-stop-flow", CreateNotification = "sna-sync:create-notification", + + AutoPostalOnAttach = "sna-sync:attach-postal" } export enum NuiEvents { From 5438e5ffc26d82c92091a05c06979628cea65b88 Mon Sep 17 00:00:00 2001 From: sl1ki0 <126953670+sl1ki0@users.noreply.github.com> Date: Sun, 16 Jun 2024 16:25:13 +0300 Subject: [PATCH 2/9] Triggering event for 911 postal --- integrations/sync/server/flows/911-call-attach.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/integrations/sync/server/flows/911-call-attach.ts b/integrations/sync/server/flows/911-call-attach.ts index 2c460cd..0440710 100644 --- a/integrations/sync/server/flows/911-call-attach.ts +++ b/integrations/sync/server/flows/911-call-attach.ts @@ -109,6 +109,7 @@ onNet( ), ], }); + emitNet("sna-sync:attach-postal", source2, updatedCall.postal); } else { emitNet("chat:addMessage", source, { args: [ From c1d4b0fb34d157c7e012dfbdc12c158ad44fd965 Mon Sep 17 00:00:00 2001 From: sl1ki0 <126953670+sl1ki0@users.noreply.github.com> Date: Sun, 16 Jun 2024 16:38:02 +0300 Subject: [PATCH 3/9] Route to postal when attached to a call --- .../sync/client/flows/911-call-attach.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/integrations/sync/client/flows/911-call-attach.ts b/integrations/sync/client/flows/911-call-attach.ts index 4289c36..5b2fca5 100644 --- a/integrations/sync/client/flows/911-call-attach.ts +++ b/integrations/sync/client/flows/911-call-attach.ts @@ -28,3 +28,31 @@ onNet( SetNuiFocus(true, true); }, ); + +var POSTAL_COMMAND_DEFAULT = GetConvar("postal_command", "null"); +onNet("sna-sync:attach-postal", ( + postal: string +) => { + const PostalCode = Number(postal); + + if (POSTAL_COMMAND_DEFAULT === "null") { + console.error(` + --------------------------------------- + + [${GetCurrentResourceName()}] Failed to find the "postal_command" convar in your server.cfg. Please make sure you are using \`setr\` and not \`set\`: + + \`setr postal_command "" \` + + ---------------------------------------`); + }; + + if (PostalCode != null && PostalCode > 0){ + ExecuteCommand(`${POSTAL_COMMAND_DEFAULT} ${PostalCode}`); + } else { + emit('chat:addMessage', { + color: [255, 0, 0], + multiline: true, + args: ['SnailyCAD', 'An error occured while making route to call postal'] + }); + }; +}) From 70d650f3c957446909c79e309007fddd44a058a7 Mon Sep 17 00:00:00 2001 From: sl1ki0 <126953670+sl1ki0@users.noreply.github.com> Date: Sun, 16 Jun 2024 16:56:59 +0300 Subject: [PATCH 4/9] Added client event from types --- integrations/sync/client/flows/911-call-attach.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/integrations/sync/client/flows/911-call-attach.ts b/integrations/sync/client/flows/911-call-attach.ts index 5b2fca5..53d7470 100644 --- a/integrations/sync/client/flows/911-call-attach.ts +++ b/integrations/sync/client/flows/911-call-attach.ts @@ -29,10 +29,12 @@ onNet( }, ); -var POSTAL_COMMAND_DEFAULT = GetConvar("postal_command", "null"); -onNet("sna-sync:attach-postal", ( - postal: string -) => { +const POSTAL_COMMAND_DEFAULT = GetConvar("postal_command", "null"); +onNet( + ClientEvents.AutoPostalOnAttach, + ( + postal: string + ) => { const PostalCode = Number(postal); if (POSTAL_COMMAND_DEFAULT === "null") { @@ -52,7 +54,7 @@ onNet("sna-sync:attach-postal", ( emit('chat:addMessage', { color: [255, 0, 0], multiline: true, - args: ['SnailyCAD', 'An error occured while making route to call postal'] + args: ["SnailyCAD", "An error occured while making route to call postal"] }); }; }) From 310bdcbba7ce53e60dc6f9fcae38f333457274f4 Mon Sep 17 00:00:00 2001 From: sl1ki0 <126953670+sl1ki0@users.noreply.github.com> Date: Sun, 16 Jun 2024 17:45:52 +0300 Subject: [PATCH 5/9] Event name changed to ClientEvents.AutoPostalOnAttach --- integrations/sync/server/flows/911-call-attach.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/sync/server/flows/911-call-attach.ts b/integrations/sync/server/flows/911-call-attach.ts index 0440710..5cd2961 100644 --- a/integrations/sync/server/flows/911-call-attach.ts +++ b/integrations/sync/server/flows/911-call-attach.ts @@ -109,7 +109,7 @@ onNet( ), ], }); - emitNet("sna-sync:attach-postal", source2, updatedCall.postal); + emitNet(ClientEvents.AutoPostalOnAttach, source2, updatedCall.postal); } else { emitNet("chat:addMessage", source, { args: [ From 5fb908e5dfbbed4e84833f1f92abf4127b9e3a0c Mon Sep 17 00:00:00 2001 From: sl1ki0 <126953670+sl1ki0@users.noreply.github.com> Date: Sun, 16 Jun 2024 17:46:51 +0300 Subject: [PATCH 6/9] missing "," fix --- src/types/events.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/events.ts b/src/types/events.ts index aa81db7..d15e555 100644 --- a/src/types/events.ts +++ b/src/types/events.ts @@ -100,7 +100,7 @@ export enum ClientEvents { CreateNotification = "sna-sync:create-notification", - AutoPostalOnAttach = "sna-sync:attach-postal" + AutoPostalOnAttach = "sna-sync:attach-postal", } export enum NuiEvents { From 06972bc4eabd22f4cc7f3ef742aae5f64adab6b3 Mon Sep 17 00:00:00 2001 From: casperiv0 <53900565+casperiv0@users.noreply.github.com> Date: Sun, 16 Jun 2024 16:58:00 +0200 Subject: [PATCH 7/9] fix: format code --- .../sync/client/flows/911-call-attach.ts | 18 +++++++----------- package.json | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/integrations/sync/client/flows/911-call-attach.ts b/integrations/sync/client/flows/911-call-attach.ts index 53d7470..4e1b9ee 100644 --- a/integrations/sync/client/flows/911-call-attach.ts +++ b/integrations/sync/client/flows/911-call-attach.ts @@ -30,11 +30,7 @@ onNet( ); const POSTAL_COMMAND_DEFAULT = GetConvar("postal_command", "null"); -onNet( - ClientEvents.AutoPostalOnAttach, - ( - postal: string - ) => { +onNet(ClientEvents.AutoPostalOnAttach, (postal: string) => { const PostalCode = Number(postal); if (POSTAL_COMMAND_DEFAULT === "null") { @@ -46,15 +42,15 @@ onNet( \`setr postal_command "" \` ---------------------------------------`); - }; + } - if (PostalCode != null && PostalCode > 0){ + if (PostalCode != null && PostalCode > 0) { ExecuteCommand(`${POSTAL_COMMAND_DEFAULT} ${PostalCode}`); } else { - emit('chat:addMessage', { + emit("chat:addMessage", { color: [255, 0, 0], multiline: true, - args: ["SnailyCAD", "An error occured while making route to call postal"] + args: ["SnailyCAD", "An error occured while making route to call postal"], }); - }; -}) + } +}); diff --git a/package.json b/package.json index 464164a..31b9759 100644 --- a/package.json +++ b/package.json @@ -51,4 +51,4 @@ "printWidth": 100, "tabWidth": 2 } -} \ No newline at end of file +} From 158ca55de9d7c8c06c78a783e580f64ad07e430c Mon Sep 17 00:00:00 2001 From: casperiv0 <53900565+casperiv0@users.noreply.github.com> Date: Sun, 16 Jun 2024 17:01:39 +0200 Subject: [PATCH 8/9] fix: small fixes --- integrations/sync/client/flows/911-call-attach.ts | 15 ++++++++------- integrations/sync/server/flows/911-call-attach.ts | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/integrations/sync/client/flows/911-call-attach.ts b/integrations/sync/client/flows/911-call-attach.ts index 4e1b9ee..0b122f5 100644 --- a/integrations/sync/client/flows/911-call-attach.ts +++ b/integrations/sync/client/flows/911-call-attach.ts @@ -31,21 +31,22 @@ onNet( const POSTAL_COMMAND_DEFAULT = GetConvar("postal_command", "null"); onNet(ClientEvents.AutoPostalOnAttach, (postal: string) => { - const PostalCode = Number(postal); + const postalCodeAsInt = parseInt(postal); if (POSTAL_COMMAND_DEFAULT === "null") { - console.error(` + console.info(` --------------------------------------- - + [${GetCurrentResourceName()}] Failed to find the "postal_command" convar in your server.cfg. Please make sure you are using \`setr\` and not \`set\`: - + \`setr postal_command "" \` - + ---------------------------------------`); + return; } - if (PostalCode != null && PostalCode > 0) { - ExecuteCommand(`${POSTAL_COMMAND_DEFAULT} ${PostalCode}`); + if (postalCodeAsInt > 0) { + ExecuteCommand(`${POSTAL_COMMAND_DEFAULT} ${postalCodeAsInt}`); } else { emit("chat:addMessage", { color: [255, 0, 0], diff --git a/integrations/sync/server/flows/911-call-attach.ts b/integrations/sync/server/flows/911-call-attach.ts index 5cd2961..8d37f48 100644 --- a/integrations/sync/server/flows/911-call-attach.ts +++ b/integrations/sync/server/flows/911-call-attach.ts @@ -109,7 +109,7 @@ onNet( ), ], }); - emitNet(ClientEvents.AutoPostalOnAttach, source2, updatedCall.postal); + emitNet(ClientEvents.AutoPostalOnAttach, source, updatedCall.postal); } else { emitNet("chat:addMessage", source, { args: [ From 4b153e932b672201bff062f77da5ad1f51a072d8 Mon Sep 17 00:00:00 2001 From: casperiv0 <53900565+casperiv0@users.noreply.github.com> Date: Sun, 16 Jun 2024 17:04:31 +0200 Subject: [PATCH 9/9] chore: improve error message --- integrations/sync/client/flows/911-call-attach.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/integrations/sync/client/flows/911-call-attach.ts b/integrations/sync/client/flows/911-call-attach.ts index 0b122f5..a29ac67 100644 --- a/integrations/sync/client/flows/911-call-attach.ts +++ b/integrations/sync/client/flows/911-call-attach.ts @@ -29,24 +29,23 @@ onNet( }, ); -const POSTAL_COMMAND_DEFAULT = GetConvar("postal_command", "null"); +const POSTAL_COMMAND = GetConvar("snailycad_postal_command", "null"); onNet(ClientEvents.AutoPostalOnAttach, (postal: string) => { const postalCodeAsInt = parseInt(postal); - if (POSTAL_COMMAND_DEFAULT === "null") { + if (POSTAL_COMMAND === "null") { console.info(` - --------------------------------------- +--------------------------------------- - [${GetCurrentResourceName()}] Failed to find the "postal_command" convar in your server.cfg. Please make sure you are using \`setr\` and not \`set\`: +[${GetCurrentResourceName()}] Not automatically setting postal code for call. There was no postal command set.: +\`setr snailycad_postal_command "" \` - \`setr postal_command "" \` - - ---------------------------------------`); +---------------------------------------`); return; } if (postalCodeAsInt > 0) { - ExecuteCommand(`${POSTAL_COMMAND_DEFAULT} ${postalCodeAsInt}`); + ExecuteCommand(`${POSTAL_COMMAND} ${postalCodeAsInt}`); } else { emit("chat:addMessage", { color: [255, 0, 0],