feat(api): add play again / reset lobby functionality #9
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Background
After a game finishes, the lobby status is set to
'finished'in the DBvia
finishGame(). TheMultiplayerScoreScreenhas a "Play Again" buttonthat navigates back to
/multiplayer/lobby/$code, which sendslobby:joinvia WebSocket.
Currently
handleLobbyJoinrejects connections wherelobby.status !== 'waiting'.This means "Play Again" always fails with a "Lobby is not in waiting state" error.
What needs to happen
When the host clicks "Play Again", the lobby needs to be reset to
'waiting'status so players can reconnect and start a new game.
Proposed approach
Option A: Implicit reset on lobby:join
If a player sends
lobby:joinon a finished lobby they're a member of,automatically reset the lobby status to
'waiting'and clear scores.Option B: Explicit reset message
Add a new
WsLobbyResetSchemaclient message. Host sends it, serverresets the lobby. Players then send
lobby:joinas normal.Option B is cleaner — explicit intent, host controls the reset, consistent
with how
lobby:startworks. Option A is implicit and could cause unexpectedresets.
Scope
packages/shared/src/schemas/lobby.tsWsLobbyResetSchema { type: 'lobby:reset', lobbyId }.WsClientMessageSchema.apps/api/src/ws/handlers/lobbyHandlers.tshandleLobbyReset— validates host, resets status to'waiting',resets all player scores to 0, broadcasts
lobby:state.apps/api/src/models/lobbyModel.tsresetLobby(lobbyId)— transaction: update status to'waiting',reset all
lobby_players.scoreto 0.apps/web/src/components/multiplayer/MultiplayerScoreScreen.tsxlobby:resetbefore navigating back to lobby route.apps/api/src/ws/handlers/lobbyHandlers.tshandleLobbyJointo accept'waiting'status only — no change neededif reset happens before navigation.
Acceptance criteria
Related
apps/web/src/components/multiplayer/MultiplayerScoreScreen.tsxapps/api/src/ws/handlers/lobbyHandlers.tsapps/api/src/models/lobbyModel.tspackages/shared/src/schemas/lobby.ts