Bash.tv → GitHub → itch.io

Keep every player's view of a multiplayer game the same. Snapshots versus events versus lockstep, delta compression against the last acknowledged snapshot, rebuilding full state on the client, rounding values to cut size, interest management (send only what is near or visible), server clock estimation from ping and pong, exactly-once events over unreliable channels, tick and send rates, and ban...

Download skill (.zip) Files on GitHub

Network synchronization

Pick a sync style

Style How Good for
Snapshots Server sends the state of things 10-30x/s Action games (default)
Events Send only what happened (“card played”) and apply it Turn-based, board, card games
Lockstep Everyone sends inputs; every machine simulates the same RTS with hundreds of units; needs perfectly deterministic code (game-replay-system)
Shared state One saved value everyone reads (Bash shared) Party games, boards, lists

assets/sync.js

import { encodeDelta, createHistory, createReceiver, quantizeEnts, interest, createClock, createEventSender, createEventReceiver } from "./sync.js";
// server, each send tick, per player:
const snap = quantizeEnts(interest(full, player, 900, { always: [player.id] }), { x: 0.1, y: 0.1, a: 0.01 });
history.put(snap); send({ t: "snap", ...encodeDelta(history.get(ackedTick), snap) });
// client:
const full = receiver.receive(msg);   // null = missing base → send { t: "ack", tick: -1 } for a full snapshot
send({ t: "ack", tick: full.tick });

Rates and budgets

  Typical
Server tick 30-60 Hz (simulation)
Snapshot send 10-20 Hz (100 ms interpolation delay at 20 Hz)
Client input send every tick (60 Hz), small
Bandwidth goal under 10-20 KB/s per player down for mobile data

Measure: JSON.stringify(msg).length * sendRate. Over budget: round more, drop fields that don’t change (send names once, not every snapshot), interest radius, lower send rate, then binary encoding as the last step.

Desync checklist

Different code on client and server, floating-point drift in lockstep (use integers or fixed point), events applied twice, state changed in network callbacks instead of the tick, wall-clock time in game logic, and missing “full snapshot” recovery.

Tested

Node tests: delta encoding only changed fields, removed and new entities, exact rebuild, refusing a delta on the wrong base, receiver dropping old packets, quantizing, interest radius with always-sent entities, clock offset within 20 ms under jitter, exactly-once events with acks. Used in the websocket-multiplayer server tests with real sockets.