feat(lobby): block create/join while in matchmaking#496
Merged
V-rtualized merged 1 commit intoJul 21, 2026
Merged
Conversation
You could create or join a custom lobby while a matchmaking search was active, ending up searching and in a lobby at once (search left running server-side with no feedback). Guard MP.pvp_create_private_lobby / MP.pvp_join_lobby with the API's shared MPAPI.matchmaking.guard_queued: while searching it shows the "Leave Queue & Continue" overlay and stashes a replay closure instead of proceeding. Crucially the replay re-enters the consumer function, not the API primitive -- MP.pvp_join_lobby / MP.pvp_create_private_lobby call MP.setup_lobby_mirror(lobby) after obtaining the lobby, which builds the lobby UI and wires the CONNECTED handler that transitions the client into the lobby. Replaying MPAPI.join_lobby/create_lobby directly joined/created server-side (the other player saw you) but skipped setup_lobby_mirror, stranding the client on the PvP menu. Requires MultiplayerAPI with the queue-guard helper. Adds tests/test_lobby_guard_while_queued.lua: blocked while searching (nothing allocated, overlay shown, replay stashed), Leave Queue & Continue runs the full consumer setup (setup_lobby_mirror ran), proceeds normally when not searching, plus a control that replays the API primitive and proves setup_lobby_mirror never ran (the strand bug).
This was referenced Jul 14, 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.
Beta testers could create or join a private lobby while a matchmaking search was active, ending up searching and in a lobby at once. The search kept running server-side with no feedback. This PR blocks both lobby entry points while queued. Two BalatroMultiplayerAPI PRs must merge first (see Depends on).
The bug
MP.pvp_create_private_lobbyandMP.pvp_join_lobbyhad no queue check. Nothing stopped a queued player from allocating or joining a lobby mid-search.The fix
Both functions now run this guard before touching the API (create's closure re-enters
MP.pvp_create_private_lobbyinstead):guard_queued(replay)lives in the API (Balatro-Multiplayer/BalatroMultiplayerAPI#7). If the player is queued, it shows a "Leave Queue & Continue" overlay, stashesreplay, and returns true; the caller returns early. If not queued, it returns false and the function proceeds. Clicking the overlay button leaves the queue and runs the stashed replay.The replay re-enters this mod's own function, not
MPAPI.create_lobby/MPAPI.join_lobby. Only the mod function runsMP.setup_lobby_mirrorand the CONNECTED handler that moves the client into the lobby. Replaying the API primitive would join or create server-side (the other player sees you) but leave the client stuck on the PvP main menu. That is why the guard lives here and not inside the API primitives.How to review
pvp_api/flow.lua: the core change. Two guard blocks, one per entry point. Nothing else changes.tests/test_lobby_guard_while_queued.lua: new standalone test.Tests
Run from the repo root:
luajit tests/test_lobby_guard_while_queued.lua. No game install needed. Cases:MPAPI.join_lobbyandMP.setup_lobby_mirrorboth run.setup_lobby_mirror, reproducing the original stranding bug.Depends on
Merge both before this PR:
MPAPI.matchmaking.guard_queuedand the overlay. The call here is not nil-guarded, so running against an API without that helper errors at these entry points.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:
Full annotated gallery of the guard's behavior (every entry point, every button outcome): VERIFICATION.md