How I built 60+ real-time multiplayer browser games with instant room links (and zero sign-up wall)
When you want to play a five-minute game of Chess, Snooker, or Court Piece with a friend in another city, most websites turn it into a chore: create an account, verify an email, install an app, hunt for each other's user
When you want to play a five-minute game of Chess, Snooker, or Court Piece with a friend in another city, most websites turn it into a chore: create an account, verify an email, install an app, hunt for each other's usernames.
I'm an independent Open Product Developer, and I built mympgames.com around the opposite constraint: pick any of 60+ classic multiplayer games, create a room, paste the link in WhatsApp or Discord, and play in seconds — no downloads and no login wall.
Building one multiplayer game in Node and Socket.IO is straightforward. Building and maintaining 60+ very different games — from turn-based boards like Chess, Trouble, and Mastermind to hidden-hand card games like Court Piece (Rang) and 2D cue physics like Snooker — forced a few architectural choices that saved me from drowning in glue code. Here is how the server is put together.
1. One room lifecycle, ~45 reusable engine factories
Early on, every game was its own standalone module (tic-tac-toe.js, connect-four.js, battleship.js). That scales to ten games, not sixty.
Instead, the registry (server/games/registry.js) mixes a small set of bespoke modules with a data-driven catalog built at boot time through a factory table (buildGame(entry)):
const games = {
'tic-tac-toe': ticTacToe,
'connect-four': connectFour,
rps,
pong,
battleship,
checkers,
memory,
'dots-boxes': dotsBoxes,
reversi,
'snake-duel': snakeDuel,
};
for (const entry of catalog) {
if (games[entry.id]) throw new Error(`Duplicate game id: ${entry.id}`);
games[entry.id] = buildGame(entry);
}
Every game implements the same thin contract: meta, initialState, applyAction, and publicState. That means the room server (server/index.js) does not care whether a room is running Trouble, Backgammon, or Rang. Room codes, shareable /play/<game>?code=... links, reconnect tokens, turn countdowns, spectators, and rematches are all written once.
One small Socket.IO detail that paid off immediately: because the catalog payload is ~100 KB, I cache it at boot and enable perMessageDeflate on the Socket.IO server so mobile clients aren't stalled on the initial handshake:
const io = new Server(server, {
transports: ['websocket', 'polling'],
perMessageDeflate: { threshold: 1024 },
httpCompression: true,
});
2. Keeping hidden information actually hidden (including from spectators)
Turn-based open-board games like Chess or Trouble are easy to broadcast: every player sees the same state.
Hidden-information games — like Court Piece / Rang, Hearts, Rummy, or Battleship — are where naive multiplayer servers leak secrets. If you send the full room state to the client and just "hide" opponent cards in CSS, anyone with DevTools can read every hand.
In mympgames, a game's publicState function signals whether it has per-viewer secrets by its arity:
-
publicState(state)(1 argument): open information, identical for every seat. -
publicState(state, viewerIndex)(2 arguments): server builds a tailored payload per seat, putting viewer-private data undermy*keys (likemyHandormyShips).
That also gave me a clean, fail-safe spectator view (server/index.js) without having to remember to write a custom spectator sanitizer for every single game:
function spectatorView(game, state) {
if (!state || !game) return null;
if (typeof game.spectatorState === 'function') {
return { ...game.spectatorState(state), spectatorView: true };
}
if (game.publicState.length < 2) return game.publicState(state);
const v = game.publicState(state, 0) || {};
const out = {};
for (const [k, val] of Object.entries(v)) {
if (/^my[A-Z]/.test(k)) continue;
out[k] = val;
}
out.spectatorView = true;
return out;
}
If a game defines spectatorState(), great. If not, the server automatically strips every my[A-Z]* field before broadcasting to spectators. You can still forget to write a spectator view, and you still won't leak a hand.
3. Deterministic 2D physics without flooding WebSockets
Real-time cue games like Snooker and 8-Ball Pool are a completely different beast from card games. Streaming 60 fps ball positions over Socket.IO for 20 seconds per shot wastes bandwidth and looks jittery on mobile connections.
Instead, snooker-core.js is a UMD module shared identically by Node (authoritative) and the browser (replay). It uses a fixed DT = 1 / 400 second step on real full-size table dimensions (3569 x 1778 mm) and restricts itself to basic IEEE-754 arithmetic (+ - * / and Math.sqrt) in a fixed iteration order:
const L = 3569; // full-size table length (mm)
const WT = 1778; // table width (mm)
const DT = 1 / 400; // fixed 400 Hz physics step
const FRAME_EVERY = 6; // ~66 fps replay frames
const SLIDE_A = 1962; // mu_slide (0.2) * g, mm/s^2
const ROLL_A = 170; // rolling resistance, mm/s^2
const E_BALL = 0.95; // ball-ball restitution
const E_CUSH = 0.78; // cushion restitution
When a player takes a shot, the client sends just the shot parameters (angle, power, cue-tip spin). The server simulates the entire shot authoritatively, validates fouls and potted balls, and sends the shot result; every client and spectator replays the exact same trajectory locally. Smooth 60+ fps animation, tiny network payloads, and zero client-side cheating.
4. Why every multiplayer game ships with a bot
Here is the most practical lesson from running a zero-budget indie arcade: most first-time visitors arrive alone. If someone searches for "2 player chess online" or "snooker online", lands on a lobby, and sees an empty waiting room, they bounce in five seconds.
So every game on the site has a server-side bot policy (server/bot/index.js). Rather than writing 60 bespoke bots from scratch, policies are keyed by meta.engine || meta.id, with an escape hatch when a game wants its own specialized AI (game.botAction):
function chooseAction(game, state, botIndex = 1, ctx = {}) {
if (!game || !state || over(state)) return null;
if (typeof game.botAction === 'function') {
return game.botAction(state, botIndex, ctx);
}
const engine = game.meta?.engine || game.meta?.id;
const fn = POLICIES[engine] || POLICIES[game.meta?.id];
return fn ? fn(state, botIndex, game, ctx) : null;
}
Visitors can play a round against the computer immediately to see how the board feels, and then click "Play with a friend" to copy a room link into WhatsApp or Discord.
Try a quick match
Everything is free, runs in desktop and mobile browsers, and needs no account. If you want to see the engine architecture in action, here are a few good starting points:
- 2-Player Games Hub — browse quick 2-player matches
- Snooker — deterministic 2D cue physics
- Trouble — classic board race
- Chess — 2-player chess with clocks & bots
- Mastermind — code-breaking duel
- Court Piece & Rang — hidden-hand trick-taking
Or browse all 60+ games at mympgames.com. Happy to answer any questions about Socket.IO scaling, deterministic physics, or bot design in the comments!
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.