Skip to content

feat(gameserver): add a deterministic quick join per mode - #2702

Merged
houko merged 1 commit into
feat/lobby-state-1320from
feat/quick-join-1321
Dec 1, 2026
Merged

houko merged 1 commit into
feat/lobby-state-1320from
feat/quick-join-1321

Conversation

@houko

@houko houko commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

"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 of mode with 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]ModeConfig carries each mode's capacity and whether a peer may join a room whose match already runs (the join then returns the room's Snapshot for the joiner to apply). The mode is written into the room's "mode" setting, which is what Find filters on, so a room created by hand with the same setting is eligible.
  • Concurrency: a quickMu serializes QuickJoin. Selection reads a listing and then joins; without it two peers could both see the last seat free and each open a room.
  • Errors: an unconfigured mode is ErrUnknownMode; a server at Capacity.MaxRooms with no free seat reports ErrNoCapacity instead of ErrServerBusy, 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 (Snapshot path), 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-notes and go run ./tools/changelog check pass.

Stacking

This depends on the lobby state of #1320 (RoomOptions, Find, mode settings), so it is based on feat/lobby-state-1320 (#2701) rather than main; merge #2701 first.

Docs, changelog, notes

docs/en/gameserver.md and docs/zh/gameserver.md document QuickJoin beside the lobby; changelog.d/1321-quick-join.md and .agents/notes/implemented/feature/2026-11-30-quick-join-1321.md record why the fullest room wins, why the calls are serialized, and the alternatives.

No visual change: no screenshot.

Fixes #1321

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.
@github-actions github-actions Bot added enhancement New feature or request documentation Improvements or additions to documentation area/agents pkg/online size/M labels Nov 30, 2026
@houko
houko merged commit c76fbd1 into feat/lobby-state-1320 Dec 1, 2026
97 checks passed
@houko
houko deleted the feat/quick-join-1321 branch December 1, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agents documentation Improvements or additions to documentation enhancement New feature or request pkg/online size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant