Skip to content

Commit

Permalink
chore(release): 0.14.2
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Jun 14, 2024
1 parent fe28688 commit d33765e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.14.2

- fix: require personal API token for event validation (911-call and panic button notificatios)

## 0.14.1

- chore(debug): add version debug on initialize.
Expand Down
32 changes: 16 additions & 16 deletions integrations/sync/server/flows/validate-events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Call911 } from "@snailycad/types";
import { Call911, ShouldDoType } from "@snailycad/types";
import { ClientEvents, ServerEvents, SnCommands } from "~/types/events";
import { getPlayerApiToken } from "../server";
import { cadRequest } from "~/utils/fetch.server";
Expand All @@ -9,6 +9,7 @@ onNet(ServerEvents.Incoming911Call, async (call: Call911) => {

const player = global.source;
const userApiToken = getPlayerApiToken(player);
if (!userApiToken) return;

const { data } = await cadRequest<GetUserData>({
method: "POST",
Expand All @@ -18,22 +19,22 @@ onNet(ServerEvents.Incoming911Call, async (call: Call911) => {
},
});

if (!data?.unit) {
return;
const isOnDuty = data?.unit && data.unit.status?.shouldDo !== ShouldDoType.SET_OFF_DUTY;
if (isOnDuty) {
emitNet(ClientEvents.CreateNotification, player, {
message: `A new 911 call has been created with case number: #${call.caseNumber}. To assign yourself to the call, use /${SnCommands.AttachTo911Call} ${call.caseNumber}`,
title: "Incoming 911 Call",
timeout: 15_000,
});
}

emitNet(ClientEvents.CreateNotification, player, {
message: `A new 911 call has been created with case number: #${call.caseNumber}. To assign yourself to the call, use /${SnCommands.AttachTo911Call} ${call.caseNumber}`,
title: "Incoming 911 Call",
timeout: 15_000,
});
});

onNet(ServerEvents.PanicButtonOn, async (unit: { formattedUnitData: string }) => {
CancelEvent();

const player = global.source;
const userApiToken = getPlayerApiToken(player);
if (!userApiToken) return;

const { data } = await cadRequest<GetUserData>({
method: "POST",
Expand All @@ -43,12 +44,11 @@ onNet(ServerEvents.PanicButtonOn, async (unit: { formattedUnitData: string }) =>
},
});

if (!data?.unit) {
return;
const isOnDuty = data?.unit && data.unit.status?.shouldDo !== ShouldDoType.SET_OFF_DUTY;
if (isOnDuty) {
emitNet(ClientEvents.CreateNotification, player, {
message: `${unit.formattedUnitData} has pressed their panic button.`,
title: "Panic Button Enabled",
});
}

emitNet(ClientEvents.CreateNotification, player, {
message: `${unit.formattedUnitData} has pressed their panic button.`,
title: "Panic Button Enabled",
});
});

0 comments on commit d33765e

Please sign in to comment.