the nerd page ↓

How the hell it works

A jigsaw where the video never stops, eight people grab pieces at once, and nobody's laptop gets to lie about where a piece is. Here's the Rust that makes that true. Crude headings, straight facts, and every claim links to the file it came from.

  • 6Rust crates
  • v19wire protocol
  • 1,000pieces max
  • 8+16players + spectators
  • 64videos per room
  • 509Rust tests

Numbers checked against the app repo on 2026-11-30. The repo wins if they ever disagree. For answers about player limits and platform support, see the FAQ.

Six crates and a grudge.

The rules live in one crate that has never heard of a window, a GPU or a video codec. Everything else is a host for those rules.

rules

pieceoff-core

Puzzle definitions, piece topology, joins, the versioned room messages, and RoomRuntime::apply: the one function every host calls to turn a player's intent into a change or a refusal.

core/src/lib.rs
authority

pieceoff-server

axum WebSockets on tokio. Holds the real room state, validates every move, persists atomic JSON snapshots, serves media over HTTP with Range. Listens on port 28878.

server/src/lib.rs
desktop

pieceoff-app

eframe/egui UI, textured triangle meshes for pieces, FFmpeg and native WebP decoders behind MediaDecoderBackend, audio through cpal.

app/src/main.rs
live

pieceoff-room-wasm

The same core rules compiled to WebAssembly for the Cloudflare Durable Object room host behind PieceOff Online (one object per room, media in R2). 288,099 bytes raw, 96,851 gzipped when last measured (2026-10-21). Chapter 9 covers it.

docs/DEPLOYMENT.md
browser

pieceoff-web-wasm

The slice of core the browser client needs: the protocol version, name filtering, the shared-edge piece outlines and the core's limits. The copy this site serves is 447,420 bytes raw, 128,844 gzipped. Chapter 10 covers the client.

docs/ARCHITECTURE.md
desktop

pieceoff-launcher

What a player double-clicks on Windows: it starts the local room server hidden on the first free port, starts the app pointed at it, and stops the server when the app closes. If the server can't start, the app still opens, because online rooms don't need it.

launcher/src/main.rs

The point of the split: there is exactly one implementation of "can this player pick up this piece". The axum server runs it natively; the hosted-rooms Worker runs it as wasm. Clients never decide anything, they send intents and render what comes back. The wire schema is versioned (34 client message types, 15 server message types at protocol v19), which is how a second client, the browser one, could be written without touching the rules. A client on the wrong version gets one error telling the player to update, then the socket closes, instead of a stream of messages it can't parse.

Source: docs/ARCHITECTURE.md, Cargo.toml.

The server tells you to piss off.

Two people grab the same piece. One of them gets it. The other gets a polite refusal from a Rust function.

Picking up a piece sends drag_start. The server checks nobody else holds that piece's group, sets held_by, and broadcasts pieces_changed with a new revision. Anyone else who tries gets "Another player is moving that piece group", word for word from core.

Ctrl-click selections lease every group atomically or not at all ("Another player is moving part of that selection"). Leases die when a socket does, so a rage-quit never leaves a piece glued to a ghost. A piece in someone's private holder is refused to everyone but the owner.

Events go out under the room lock, in revision order. That wasn't always true: the end-to-end suite caught two concurrent changes reaching clients out of order, and clients throw away anything older than what they have. A regression test now fails three times in six against the old code. (TESTING.md, playtest log)

  1. you → drag_start { piece_id: 7 }
  2. ← all pieces_changed { held_by: "you", rev 41 }
  3. mate → drag_start { piece_id: 7 }
  4. ← mate error "Another player is moving that piece group"
  5. you → move_piece { x, y } × ~30/s
  6. you → drag_end { piece_id: 7, x, y }
  7. ← all pieces_changed { placed: true, held_by: null, rev 42+ }
Message names and the error string are real. The animation is a drawing, not a capture.
One video. 24 pieces.
This board is the site's own canvas engine, not the Rust renderer. Same idea, though: one frame, sampled by every piece.

One frame. Every goddamn piece.

There aren't 1,000 videos playing. There's one decoder, one texture, and a lot of triangles pointing at it.

Each decoded frame updates a single texture. Every piece is a jigsaw-shaped mesh whose UVs point at its own patch of that texture, so the clip moves across the whole board at once, whether the piece is in the tray, in your hand, or snapped home.

Big boards got the profiler treatment. Small pieces draw thinned outlines (every 2nd to 16th sample, corners kept), pieces under 7 points wide skip the stroke entirely, and drag updates are capped at about 30 a second. A 400-piece table (the cap back then) went from about 16 ms and 770k vertices a frame to about 3 ms and 140k; entering a 400-piece room dropped from about 110 ms to 15 ms. The cap is 1,000 pieces now; the repo's measurement for a 1,000-piece board is about 2 ms to build and 5 ms to tessellate per whole-table frame in a release build.

# measure it yourself
cargo test --release -p pieceoff-app large_board_frame_cost \
  -- --ignored --nocapture

Source: ARCHITECTURE.md, board rendering.

Same frame. Every screen.

Nobody counts frames. Everybody reads the same clock.

The host controls play, pause, seek, loop in/out and speed (0.25× to 2×). The server publishes that playback state with a timestamp. Each client learns the server clock offset from welcome.server_now_ms, so a laptop with a wrong system clock still lands on the right frame.

Decoder workers pace against that clock: show a frame when it's due, drop frames that are late, start the next loop pass early. Every 3 seconds the app re-checks, and a client more than 200 ms off seeks back into line. Audio goes through cpal and is stricter: it skips ahead when late, holds when early, and reseeks past 3 seconds of error. Volume, mute and audio delay stay local.

If FFmpeg dies, the worker restarts it (a budget of two restarts that refills when frames arrive). If it hangs in one read for 10 seconds, a watchdog kills it.

Source: ARCHITECTURE.md, video rendering model, app/src/decoder.rs.

Room clock
0 ms
Host
+0 ms
Guest, shit laptop
+0 ms

Every 3 s: off by more than 200 ms? Seek.

A 6-second loop. The guest's drift is exaggerated so you can see the correction. Thresholds are the real ones.

Cuts that match on every machine.

The piece shapes are never sent over the wire. Every client works them out and gets the same answer.

Jigsaw Classic knobs. Up to 4 neighbours.
Hexagons Brick rows, half-cell offset. Up to 6 neighbours.
Triangles Two-cell base, trapezoids at the sides. Up to 3.

Contours are a pure function of the media fingerprint, the room's cut_style and the grid coordinates. Hex and triangle outlines are built from vertices with integer keys, and each shared edge is generated from its lower key, so two neighbours trace identical samples. Every style keeps the same rows × columns index with piece homes at cell corners, which is why snapping, joins, holders and the tray didn't need rewriting when hexagons and triangles arrived in protocol v14. The classic jigsaw generator is pinned by a bit-exact test: change a curve and it's a compatibility break, not a tweak.

Source: core/src/tiling.rs. Drawings above are simplified; the real knobs are curvier.

Fat files. Shit Wi-Fi.

Your mate's 9 GB concert rip will get there. Eventually. And it'll be the right file.

Media is content-addressed by SHA-256. The host streams an upload to a temp file; it must hash to what the room says, then gets installed atomically. The server caps each asset at 16 GiB by default (a bigger declared length is refused before a byte is read) and reserves space against a 50 GiB aggregate quota, so several rooms can upload at once.

Downloads honour HTTP Range. The client keeps one .part file per hash and resumes it with backoff, no total time limit. A guest who already has the file skips the transfer when the local hash matches.

A room holds a queue of up to 64 videos. The board (grid, shape seed, piece progress) is fixed when the room is made; the queue item is just the picture painted on it. Swap videos mid-solve and nothing moves. A 250 ms server ticker handles auto-advance for repeat All and Off.

Source: ARCHITECTURE.md, multiplayer model, DEPLOYMENT.md.

  1. hosthash the file → sha256
  2. serverhands the host a private upload token
  3. hoststreams to a temp file, size checked against 16 GiB
  4. serverhash matches? atomic install under media/
  5. guestlocal copy matches? skip. Otherwise ranged download into .part
  6. guestcable yanked → resume from the last byte, not from zero
Upload and download path, in order.

Rage-quit proof.

Slam the lid. Kill the server. The board survives; your dignity doesn't.

The server writes the room to disk as an atomic JSON snapshot on drops and playback changes, and saves every room on SIGTERM. Reconnecting clients get a fresh snapshot and carry on; reconnects back off and give up cleanly if the room has expired. Disconnected rooms expire after 90 days, and media is deleted only after the last room using it goes.

The solve clock is stored as banked elapsed_ms plus running_since_ms, so clients tick it locally with no per-second messages, and server downtime never counts. It only runs while someone's connected.

To move a puzzle somewhere else, export a .pieceoff package. It carries the versioned snapshot and the media; opening it makes a new room with a new identity. Invite codes, room IDs, leases and live playback are stripped on export; piece positions, groups and the playhead stay. Packages cap media at 64 GiB and are verified against the snapshot's SHA-256 on open. The reader never extracts archive paths.

Source: ARCHITECTURE.md, package model, app/src/package.rs.

PCOFFPKG8 bytes, magicu32 LEmanifest lengthu64 LEmedia length
JSON manifestversioned room snapshot, queuemedia bytesSHA-256 checked on open
A .pieceoff file, start to end.

Spam it. We dare you.

Cursors, chat and pings are cheap to send and expensive to relay. So the server is a dick about it.

Cursors ride a separate channel so pointer traffic can't push real room events out of a slow client's buffer; a lagging client just skips to newer positions. Non-finite or off-table points are dropped without a reply. Chat is tidied server-side (control, text-direction and invisible formatting characters go) and lives in memory only. Names are claimed per room with a private 128-bit key the server only ever stores salted and hashed.

Limits, as shipped
WhatLimitWhere
Pieces per room1,000 (2–50 rows and columns)lib.rs
Players / spectators8 / 16 per roommembership.rs
Drag updates sentabout 30 a secondARCHITECTURE.md
Cursor updatesclient ~15/s; server drops over 20/s per socket, 120/s per roomARCHITECTURE.md
Chat line300 characters; burst of 5, then 1/s; last 100 lines in memory onlyARCHITECTURE.md
Video queue64 items, server checks for auto-advance every 250 msFEATURE_MATRIX.md
Media file16 GiB default, 50 GiB aggregate quotaDEPLOYMENT.md
Media dimensions8192 px a side, 40 megapixels totalARCHITECTURE.md
Idle room expiry90 days (0 disables)ARCHITECTURE.md
Invite code8 characters, about 40 bits, no look-alike lettersARCHITECTURE.md
Holders4 per player, 16 per room, 2–12 cells a sideARCHITECTURE.md
Default port28878README.md

The hosted-room design.

PieceOff Online runs on rooms.pieceoff.app, speaks protocol v19 and has uploads off. Local and LAN rooms are still how you play your own files.

The Worker pieceoff-rooms is built for rooms.pieceoff.app. Each room is one Durable Object (RoomDO) running the pieceoff-room-wasm module, so "can this player pick up this piece" is the same Rust as on the axum server. Two more single objects sit beside the rooms: RegistryDO (device keys and the daily counters) and LobbyDO (the public lobby). Media lives in an R2 bucket. The axum server is unchanged; the desktop app tells the two apart with GET /api/info, which axum answers with a 404.

The flow needs no account. A desktop install links itself once: it asks the Worker for a link code, you open pieceoff.app/link in a browser and pass a Turnstile check, and the app polls until it collects a device key. The registry stores only SHA-256 hashes of the poll secret and the key, so the plain key exists on your machine and nowhere else. A revoked or unknown key gets a 401 and the app links again.

Rooms are made with POST /api/rooms and that key, then everyone connects to /ws?code=CODE. Joiners resume with the same token as on a self-hosted server.

Hosted uploads are off: PieceOff Online plays the eight built-in loops and the curated catalog (chapter 10) only, and the Worker refuses any other media with a 403. Your own videos still work in Local or LAN rooms. The Worker's own notes say uploads stay off until an abuse contact, a takedown process and a known-bad hash blocklist exist.

Source: DEPLOYMENT.md, Cloudflare section, worker/wrangler.jsonc, worker/src/room.ts.

  1. appPOST /api/links → a link code, good for 10 minutes
  2. youopen pieceoff.app/link?c=CODE, pass Turnstile
  3. apppolls every 2 s, collects the device key exactly once
  4. appPOST /api/rooms with the key → a room and an invite code
  5. friendspaste the code, socket opens on /ws?code=CODE
  6. roomone Durable Object, built-in or catalog media only, rules in wasm
Link once, then create and join, in order.
Online guard rails
WhatLimitWhere
Room creation10 a minute per address; 30 a day per device keywrangler.jsonc
Room-code socket lookups20 a minute per addresswrangler.jsonc
Link requests10 a minute per addresswrangler.jsonc
Lobby reads and link polls60 a minute per addresswrangler.jsonc
Service-wide rooms2000 a UTC daywrangler.jsonc
Service-wide link requests500 a UTC daywrangler.jsonc
All hosted media together8 GiB (uploads are off anyway)wrangler.jsonc
Lobby entry with no heartbeatdropped after 150 sDEPLOYMENT.md

Past a daily ceiling the Worker answers 503 until midnight UTC; joining existing rooms and the lobby keep working. A single secret, ONLINE_PLAY_ENABLED=0, pauses all new hosted play at once without waking a Durable Object. Moderation is the minimum: host kick with a rejoin ban, per-device mute, chat off by default in listed rooms, a name filter, and a report link that emails contact@pieceoff.app. Reports go to that mailbox and nothing acts on them automatically, and there are no address bans, so a kicked player who picks a new name can come back.

No install. Just a tab.

The browser client is a thin TypeScript and WebGL client, not an egui build in a trench coat. The server is still the only thing that decides anything.

It plays PieceOff Online from /play. First-load JS, wasm and CSS have a 400 KB gzipped budget that a script enforces; the board code loads as a lazy chunk. The DOM owns text input, chat and the toolbar, so mobile keyboards and screen readers get real elements, not an immediate-mode canvas.

One WebGL2 canvas draws the pieces. Outlines come out of the wasm module, get triangulated once and thinned by on-screen size, and per-piece state lives in a small data texture, so a drag uploads two texels instead of vertices. Bundled loops are muted video elements uploaded as a texture when a new frame arrives. Nothing redraws while nothing changes.

Input goes through one gesture machine: mouse drag, rubber-band select and wheel zoom, or touch drag, pinch, long-press select and double-tap ping. A drag sends the same lease messages as the desktop, capped at 30 moves a second. The protocol has no drag-abort and a lease must never stay held, so cancelling a drag (second finger, window blur, hidden tab) is a drop at the spot where the drag began. A reload resumes as the same player from a token in session storage.

Curated catalog. Rooms can also play longer real videos, not only the eight loops. catalog/catalog.json is the single source; a script generates the Rust list the Worker compiles in and the one the web client reads, and a core test fails if they disagree. At v0.3.2 it lists 9 items: 2 films and 7 HD loops. Bytes sit in R2 and stream withRange requests; sound starts muted.

Harder modes (protocol v16). The host can turn on rotation, where pieces start at random quarter turns and only fit when upright (E and Q or the wheel while holding one, validated by the server), and no hints, which hides the reference image and board ghost. No hints is played on trust: the client hides the help, the server only refuses the edges-first tidy.

What it can't do yet. Moving or resizing holders, the tray rearrange, uploaded media, queue management, timelapse and rebindable keys are deferred. iOS Safari video-in-WebGL and the 1,000-piece frame rate on real phones are not verified yet.

Source: ARCHITECTURE.md, Web play client, FEATURE_MATRIX.md, catalog/catalog.json.

  1. browseropens /ws?code=CODE, joins with a player key
  2. serversends a snapshot; the client builds its copy from messages only
  3. youdrag a piece: drag_start, move_piece, drag_end
  4. servergrants or refuses the lease, snaps, broadcasts in order
  5. browserdraws it; the dragged piece is the only optimistic one
  6. socket dropsreconnect with backoff, resume token, fresh snapshot
The client sends intents. It never decides.

How we know it's not bullshit.

509 Rust tests, one of which runs a whole multiplayer game with no humans in it.

cargo test -p pieceoff-app e2e:: boots a real room server in the test process, runs two or three real app instances through the same frame function the window calls, and decodes a generated video with real FFmpeg over real WebSockets. About six seconds. It covers create, upload, download-and-verify, host playback control, solving, leave and rejoin, a clean server restart, a server crash with no shutdown save, an expired room, a host whose connection dies mid-upload (a guest with the file takes over), and FFmpeg killed, given up on, hung, or decoding nothing.

The browser client has its own gate: a script builds the core wasm, typechecks, runs the vitest suite (the wasm is loaded for real and protocol tags are checked against the Rust enums), enforces the size budget and checks the release tarball. A separate two-client end-to-end run drives headless Chromium against a local rooms Worker: create, invite link, join, drag and snap, chat, reload resume, kick, a phone profile and a rotation room, plus 25 pick-up and drop rounds that must leave no lease held. The count above is Rust only, counted as #[test] and #[tokio::test]attributes.

CI runs Clippy with warnings as errors, the full test suite and a release build on Ubuntu, Windows and macOS, plus a Docker health check, cargo-deny, an audit, CodeQL and dependency review. Tagged releases publish themselves.

What it can't tell us: whether two people hear the same beat (audio is off in automated runs), real network latency between machines, and native Windows and macOS launches. Linux builds work. Windows and macOS are CI-checked, native launch checks still pending.

Source: docs/TESTING.md, ci.yml.

$ cargo test -p pieceoff-app e2e::
e2e create room from video, upload
e2e guest joins with no copy, downloads, verifies
e2e host loops, plays, pauses, seeks
e2e both players solve it
e2e guest leaves and rejoins
e2e server restart, both reconnect
e2e server crash, dropped pieces survive
e2e host dies mid-upload, guest takes over
e2e FFmpeg killed / hung / empty video
# paraphrased from docs/TESTING.md, not literal output

Now go read the real thing.

All of it is Apache-2.0. Star it, fork it, tell us which part is dumb.

Star it on GitHubRead ARCHITECTURE.mdPlay itHost a room