feat(multiplayer): close outdated clients with a protocol version handshake - #27
Merged
Merged
Conversation
…dshake Every lobby, room and spectator socket sends GAME_PROTOCOL_VERSION (packages/shared/src/protocol.ts) as a non-secret query parameter; the web proxy routes forward it. GameRoom and GlobalLobby check it before any room, seat or presence work and close a missing or different version with application code 4426 (upgrade_required) on a socket that never joins the hibernation set. On 4426 the lobby store and the room and spectator services stop reconnecting and hand off to protocolUpgrade: reload once, recording the time in sessionStorage; a second 4426 within two minutes shows 'Dicee is updating. Try again in a minute.' instead of looping, and without storage it never auto-reloads. No compatibility shims: current protocol or refresh. Docs: roadmap section 1 drops the finished step; the first release deploys dicee-web and moves the domain before deploying dicee, because today's Pages client sends no version (status action 3, cloudflare.md cutover).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Roadmap section 1 step 3: the protocol version handshake. Policy: current protocol or refresh.
packages/shared/src/protocol.ts:GAME_PROTOCOL_VERSION = 1, query parameterprotocol, close code 4426 and reasonupgrade_required.?protocol=1. The/ws/lobbyand/ws/room/[code]proxies forward only that parameter (plusrole) and still replaceAuthorizationwith the session bearer. Previously the lobby route dropped the query string entirely.lib/protocol-gate.tsruns first inGameRoom.fetchandGlobalLobby.fetch. A missing or different version gets a 101 whose socket is closed at once with 4426 via plainaccept(), so it never counts as presence and never reacheswebSocketClose. The rejection is logged with the structured logger.protocolUpgradetakes over. It reloads once (time recorded in sessionStorage). If a second 4426 arrives within 2 minutes,UpdateRequiredBannershows "Dicee is updating. Try again in a minute." with a retry button. If storage is unavailable, it never auto-reloads. Every other close code behaves as before.dicee-weband move the domain before deployingdicee, and use operator commands rather than a CI dispatch. Today's Pages client sends no version, so the gateddiceewould close its sockets.Known rollout effect: tabs already open when the gated
diceeships run old code that sends no version and does not recognise 4426. They need one manual reload. The reload logic protects future version bumps.No deployment.
Verification
test:agent: 519 passed. The integration file needs a loopback port and passed 15/15 alone outside the sandbox.test:agent: 1625 passed, including the workerd proxy runtime test for 4426 before the 101.pnpm checkandpnpm lintpass apart from a docs finding that clears once the new files are tracked.node scripts/check-docs.mjsandgit diff --checkon the squashed commit; pre-pushpnpm validate:ci; CI and CodeQL on this PR.