From 7bbe33725f45a55d8009964e2f50c27f50a21cdc Mon Sep 17 00:00:00 2001 From: minie4 Date: Fri, 28 Mar 2025 00:00:51 +0100 Subject: [PATCH] fix(backend): remove card from player before calling PlayCard --- backend/api/websocket.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/api/websocket.go b/backend/api/websocket.go index 5a75abd..55ceee1 100644 --- a/backend/api/websocket.go +++ b/backend/api/websocket.go @@ -248,7 +248,7 @@ func onPlayerJoin(client *socketio.Socket, room *types.Room, player *types.Playe return } card := player.Cards[*updatePlayerRequest.CardIndex] - if !room.CardDeck.PlayCard(card) { + if !room.CardDeck.CanPlay(card) { client.Emit("Status", types.S2C_Status{ IsError: true, StatusCode: "card_not_playable", @@ -257,6 +257,9 @@ func onPlayerJoin(client *socketio.Socket, room *types.Room, player *types.Playe return } player.Cards = append(player.Cards[:*updatePlayerRequest.CardIndex], player.Cards[*updatePlayerRequest.CardIndex+1:]...) + if !room.CardDeck.PlayCard(card) { + slog.Error("Cannot play card after checking", "roomId", room.RoomId.Hex(), "playerId", player.PlayerId.Hex()) + } game.OnPlayCard(room, player, *updatePlayerRequest.CardIndex, card) if len(player.Cards) == 0 {