verifies type of sent card positions
This commit is contained in:
parent
33e78e8987
commit
dab64f1095
1 changed files with 5 additions and 0 deletions
|
|
@ -243,6 +243,11 @@ export class Game {
|
||||||
|
|
||||||
revealCardAction(playerSocketId: string, cardPosition: CardPosition) {
|
revealCardAction(playerSocketId: string, cardPosition: CardPosition) {
|
||||||
const player = this.getPlayerBySocketId(playerSocketId);
|
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 [columnIndex, cardIndex] = cardPosition;
|
||||||
const revealedCard = player.deck[columnIndex][cardIndex];
|
const revealedCard = player.deck[columnIndex][cardIndex];
|
||||||
console.log(
|
console.log(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue