diff --git a/Server/websocket_server.py b/Server/websocket_server.py index fa667f8..0c09701 100644 --- a/Server/websocket_server.py +++ b/Server/websocket_server.py @@ -136,8 +136,19 @@ async def handler(self, websocket): except (websockets.ConnectionClosedOK, websockets.ConnectionClosedError, websockets.ConnectionClosed): logger.info("Connection Closed from Client-Side") self._connections.remove(websocket) - # TODO: Add handling when game is not over yet + if self._inprogress: + # TODO: Add handling (for reconnect) when game is not over yet + pass + else: + # request a ping from everyone and delete player list to wait for join messages. + websockets.broadcast(self._connections, json.dumps({ + "message_type": "lobby/ping", + })) + self._players = {} + + # End this connection loop break + # TODO: Catch other errors for disconnects diff --git a/json_schema/server_to_client.json b/json_schema/server_to_client.json index f89fd0c..303e0d7 100644 --- a/json_schema/server_to_client.json +++ b/json_schema/server_to_client.json @@ -8,7 +8,7 @@ "message_type": { "description": "The message type", "type": "string", - "enum": ["game/start", "lobby/status", "lobby/kick", "statistics/statistics", "game/turn", "game/error", "game/end", "chat/receive"] + "enum": ["game/start", "lobby/status", "lobby/kick", "lobby/ping", "statistics/statistics", "game/turn", "game/error", "game/end", "chat/receive"] } }, "required": ["message_type"],