Rooms, join codes and lobbies for multiplayer games. Easy-to-read 4-letter codes, create and join, private rooms with passwords, public room lists and quick join, ready-up and start rules, host-only settings and kicking, host handover when the host leaves, rejoining a started match, a safe room view for clients, invite links, and lobby UI patterns for desktop and phones. Tested module used by t...
Download skill (.zip) Files on GitHubMultiplayer lobbies
In a Bash kit, rooms already exist (playing-together); use this module’s rules for codes, ready-up and host handover on top.
assets/lobby.js
import { createLobbies } from "./lobby.js";
const lobbies = createLobbies({ minPlayers: 1, maxPlayers: 4 });
const { room } = lobbies.create(playerId, name, { public: false, password: null, settings: { map: "forest" } });
lobbies.join("kq7m", otherId, "Ben"); // case and spaces don't matter -> { ok } or { ok: false, error }
lobbies.setReady(otherId, true); lobbies.canStart(room.code); lobbies.start(hostId);
lobbies.leave(hostId); // host moves to whoever joined first; empty rooms are removed
lobbies.view(room); // send this to clients: no password, no ban list
Errors to show as friendly text: not_found “No room with that code”, full, started “That match already started”
(offer Watch), wrong_password, kicked, not_host, not_ready.
Codes use 32 characters without 0/O and 1/I, so they’re easy to read aloud and type on a phone. 4 characters = about a million codes; use 5 for big servers.
Rules that avoid stuck lobbies
- One person can start (
minPlayers: 1) unless the game truly needs two. Show “Start (just you so far)”. For 2-player games, offer a bot. - The host counts as ready. Show who isn’t ready instead of a disabled button with no explanation.
- Host leaves → next host, never close the room on everyone.
- Disconnected ≠ left. Keep the seat during a grace period (multiplayer-reconnection) and show “reconnecting…”.
- Players can rejoin a started match by session; new players can’t (unless
midGame: true). - Settings change only in the lobby, only by the host, and are checked by the server (
cleanSettingsin the game).
Invite links
https://your.game/?room=KQ7M: on load, fill the code and join. In Bash, the space’s own link is bash.space.publicUrl
when set (see playing-together for private spaces). Copy with navigator.clipboard.writeText from a click, then show “Copied”.
Lobby UI
- Menu: name field (remembered), Quick play (biggest button), Create room, code + Join, Watch.
- Room: big code with a Copy button, player list (name, ready, host, you), Ready / Start, Leave, host’s Kick.
- Phones: one column, 46 px tall buttons, code field with
autocapitalize="characters". - The websocket-multiplayer example (Gem Arena) implements all of this.
Tested
Node tests: safe codes, case-insensitive join, ready and start rules, host-only start, full rooms, host handover to the oldest player, kick and ban, password rooms, the client view hiding secrets, quick join filling the fullest public room, started rooms refusing new players but accepting rejoin, empty rooms removed.
Pitfalls
Trusting the client’s “I’m host” flag, codes with ambiguous letters, closing the room when the host’s phone locks, rooms that never get removed, and a lobby that only works with 2+ people.