Skip to content

feat(lobby): block create/join while in matchmaking - #1

Open
ChronoFinale wants to merge 1 commit into
Balatro-Multiplayer:mainfrom
ChronoFinale:feat/lobby-guard-while-queued
Open

feat(lobby): block create/join while in matchmaking#1
ChronoFinale wants to merge 1 commit into
Balatro-Multiplayer:mainfrom
ChronoFinale:feat/lobby-guard-while-queued

Conversation

@ChronoFinale

@ChronoFinale ChronoFinale commented Jul 13, 2026

Copy link
Copy Markdown

While a matchmaking search is active, you could still create or join a custom lobby and end up searching and in a lobby at the same time. With this PR, a queued player who tries either gets a "Leave Queue & Continue" overlay instead; continuing leaves the queue and then re-runs the action. When not searching, nothing changes.

The bug

create_lobby_with_gamemode (ui/main_menu/create_lobby.lua) and SPDRN._join_lobby_with_code (ui/main_menu/join.lua) never checked matchmaking state.

The fix

Both entry points now open with a guard — join's:

if MPAPI.matchmaking.guard_queued(function() return SPDRN._join_lobby_with_code(code) end) then
	return
end

(create's is identical, replaying create_lobby_with_gamemode(key).) When not searching, guard_queued returns false and the function proceeds as before. When searching, it shows the overlay and stashes the closure to run after leaving the queue. If the player declines, the entry point has already returned; nothing happens.

The closure re-enters the mod's own entry point, not MPAPI.create_lobby/MPAPI.join_lobby. That is the load-bearing detail: these entry points call SPDRN.setup_lobby_events, which wires the lobby events and the connected handler that moves the client into the lobby. Replaying only the API call would create/join server-side (the host sees you) while your client stays stranded on the main menu.

How to review

  • The product change is two near-identical small guards: ui/main_menu/create_lobby.lua and ui/main_menu/join.lua. Start there.
  • The rest of the diff is the new test. Its header explains the stranding failure mode; the control case at the bottom reproduces it.

Tests

From the repo root:

luajit tests/lobby_guard_while_queued.lua

Covers:

  • create and join are blocked while searching (no lobby allocated, overlay shown, replay stashed)
  • the replay runs the full flow, including setup_lobby_events, for both create and join
  • join proceeds unchanged when not searching (create's replay exercises the same not-searching path)
  • a control case replays the API primitive directly and asserts setup_lobby_events never runs, pinning the stranding failure mode

Depends on

Both must merge before this PR:

Related: Balatro-Multiplayer/BalatroMultiplayer#496 adds the same guard to the PvP mod, so behavior is consistent across mods.

What it looks like

Clicking a lobby create/join button while searching shows the shared guard overlay (from the API's queue-guard PR) instead of silently stranding the queue — with the search visibly running in the status panel:

queue guard overlay

Full annotated gallery of the guard's behavior (every entry point, every button outcome): VERIFICATION.md

Creating or joining a custom lobby while a matchmaking search was active
left the player searching and in a lobby at once. Route
create_lobby_with_gamemode and SPDRN._join_lobby_with_code through
MPAPI.matchmaking.guard_queued, which shows the "Leave Queue & Continue"
overlay and stashes a replay of the consumer function so the full setup
(setup_lobby_events + the connected handler) runs on continue.

Requires MultiplayerAPI with the guard_queued helper and the api_client
concurrent-request fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant