From dab64f109525f30161d1e52a42443c5190876098 Mon Sep 17 00:00:00 2001 From: pb-coding <71174645+pb-coding@users.noreply.github.com> Date: Tue, 3 Oct 2023 20:59:34 +0200 Subject: [PATCH] verifies type of sent card positions --- src/game/game.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/game/game.ts b/src/game/game.ts index e01b94d..b46e629 100644 --- a/src/game/game.ts +++ b/src/game/game.ts @@ -243,6 +243,11 @@ export class Game { revealCardAction(playerSocketId: string, cardPosition: CardPosition) { const player = this.getPlayerBySocketId(playerSocketId); + // ugly type checking - typescript is not able to check the type of the data sent by the client if its a type alias :( + if (!(cardPosition instanceof Array)) return; + if (cardPosition.length !== 2) return; + if (cardPosition.some((position) => typeof position !== "number")) return; + const [columnIndex, cardIndex] = cardPosition; const revealedCard = player.deck[columnIndex][cardIndex]; console.log(