Skip to content

Commit

Permalink
fix(server): ask for lobby/ping on disconnect
Browse files Browse the repository at this point in the history
[TTTK-72]
  • Loading branch information
JM-Lemmi committed Mar 12, 2024
1 parent dc1458c commit 38344f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion Server/websocket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion json_schema/server_to_client.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 38344f3

Please sign in to comment.