From 889ee4ce4f43d8b1925888e17f481c05ad6ae197 Mon Sep 17 00:00:00 2001 From: minie4 Date: Tue, 11 Mar 2025 12:35:38 +0100 Subject: [PATCH] fix(backend): check that player socket exists before trying to send data --- backend/api/websocket.go | 4 ++++ backend/game/game.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/backend/api/websocket.go b/backend/api/websocket.go index b239a87..21659ea 100644 --- a/backend/api/websocket.go +++ b/backend/api/websocket.go @@ -64,6 +64,10 @@ func unpackData(datas []any, target interface{}) bool { } func verifyPlayerIsActivePlayer(room *types.Room, target *types.Player) bool { + if target.Connection.Socket == nil { + return false + } + if room.GameState != types.StateRunning { target.Connection.Socket.Emit("Status", types.S2C_Status{ IsError: true, diff --git a/backend/game/game.go b/backend/game/game.go index f8582d7..b17a4b2 100644 --- a/backend/game/game.go +++ b/backend/game/game.go @@ -141,6 +141,9 @@ func OnPlayerStateUpdate(room *types.Room, player *types.Player, skipDBUpdate bo if !skipDBUpdate { db.Conn.UpdateRoom(room) } + if player.Connection.Socket == nil { + return + } player.Connection.Socket.Emit("OwnCards", types.BuildOwnCardsPacket(room, player)) BroadcastInRoom(room, "PlayerState", types.BuildPlayerStatePacket(room, player)) }