Repository navigation
feat(gameserver): add a deterministic quick join per mode - #2702
Merged
Merged
Conversation
Play now had to list rooms, pick one and create another, so two peers looking at the same moment each opened a room, and modes could not be told apart #1321. QuickJoin fills the fullest public room of a configured mode with a free seat or opens one with the mode's capacity, under a lock so a burst fills rooms instead of opening one each. Modes carry a capacity and a late-join policy, an unknown mode is ErrUnknownMode and a server out of rooms is ErrNoCapacity. Tests cover filling, opening, modes apart, the room cap, late join and concurrent joins.
This was referenced Nov 30, 2026
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.
"Play now" had to list rooms, choose one with a free seat and create a room when none fit. Two peers looking at the same moment both saw "no room" and each opened one, and rooms of different modes could not be told apart (#1321).
What changed
Rooms.QuickJoin(mode, peer)places a peer in the fullest public room ofmodewith a free seat, or opens one with the mode's capacity when every room is full. The fullest room wins and the lowest ID breaks ties, so placement is deterministic and rooms fill before new ones appear.Rooms.Modes map[string]ModeConfigcarries each mode's capacity and whether a peer may join a room whose match already runs (the join then returns the room'sSnapshotfor the joiner to apply). The mode is written into the room's"mode"setting, which is whatFindfilters on, so a room created by hand with the same setting is eligible.quickMuserializes QuickJoin. Selection reads a listing and then joins; without it two peers could both see the last seat free and each open a room.ErrUnknownMode; a server atCapacity.MaxRoomswith no free seat reportsErrNoCapacityinstead ofErrServerBusy, because the caller cannot act on the server being busy.Tests
Fills the fullest room first and does not open another, opens a room of the mode's capacity when every room is full, keeps modes apart, refuses an unknown or empty mode, honors
MaxRooms, joins a running room only under the late-join policy (Snapshotpath), and eight concurrent joins produce exactly four full rooms — no extra room and no room over capacity.go tool nsgo test ./pkg/online/gameserver: 131 passed.go tool nsgo check,go test ./internal/repocheck,bun run verify-notesandgo run ./tools/changelog checkpass.Stacking
This depends on the lobby state of #1320 (
RoomOptions,Find, mode settings), so it is based onfeat/lobby-state-1320(#2701) rather thanmain; merge #2701 first.Docs, changelog, notes
docs/en/gameserver.mdanddocs/zh/gameserver.mddocument QuickJoin beside the lobby;changelog.d/1321-quick-join.mdand.agents/notes/implemented/feature/2026-11-30-quick-join-1321.mdrecord why the fullest room wins, why the calls are serialized, and the alternatives.No visual change: no screenshot.
Fixes #1321