Vibed rewrite of seriesoftub.es in rust because I wasn't able to play my big network anymore. It was simply too slow.
  • Rust 92%
  • JavaScript 6.2%
  • HTML 1.4%
  • Nix 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-03 05:16:14 +00:00
crates League: player loans from before the calendar carry on smoothly 2026-11-03 05:15:54 +00:00
docs Docs: the port follows upstream 2.5.0 2026-11-03 05:16:14 +00:00
nix v2: weekly puzzles, scenarios and architect runs from our own generator 2026-11-02 11:34:35 +00:00
tools Upstream 2.5: decommissioning counts the optics of the links it closes 2026-11-03 04:29:22 +00:00
web Upstream 2.5: cable ships 2026-11-03 03:53:38 +00:00
.envrc Add devshell, formatter and pinned upstream 2026-10-26 00:09:22 +00:00
.gitignore Ignore the server's default state directory 2026-10-26 22:39:29 +00:00
Cargo.lock Upstream 2.5: cable ships 2026-11-03 03:53:38 +00:00
Cargo.toml Check months of play against the original 2026-10-26 11:23:43 +00:00
flake.lock Upstream 2.5: foundation 2026-11-03 02:27:36 +00:00
flake.nix Upstream 2.5: foundation 2026-11-03 02:27:36 +00:00
LICENSE Add README and the license 2026-10-26 12:28:07 +00:00
README.md Docs: the port follows upstream 2.5.0 2026-11-03 05:16:14 +00:00
rustfmt.toml Add devshell, formatter and pinned upstream 2026-10-26 00:09:22 +00:00
treefmt.nix Add devshell, formatter and pinned upstream 2026-10-26 00:09:22 +00:00

Series of Tubes, in Rust

A port of Series of Tubes, the browser game about building an internet, to a Rust core. The game plays the same: every mechanic, every text and the same numbers down to the last bit, and saves move freely between the original and the port. What changes is speed. A game day on upstream's big-network benchmark save (104 POPs, about 2,000 exits) takes the original about 130 ms in Node; the port takes about 12 ms natively and 16 ms as WASM. On a late game with 100 POPs it is 113 ms against 16 and 19 ms.

It runs in two places:

  • Browser: the core is compiled to WASM and runs in a Web Worker. The page is static.
  • Desktop: a Tauri app runs the core natively behind the same web shell.

Layout

Path What
crates/sot-core The game: simulation, state, saves, and the HTML of every panel and dialog
crates/sot-wasm The core for the browser (wasm-bindgen)
crates/sot-desktop The Tauri app
crates/sot-cli Benchmarks against saves
crates/sot-server The multiplayer server: shared worlds and ISP leagues over WebSocket, serves the web build
crates/sot-league The ISP league: one network per player, the market, contracts, cables, auctions and loans between them
crates/sot-bots Bot players for leagues, to test and balance them
web/ The shell: page, styles, map drawing, worker
tools/ Data extraction from the original, the parity harness, the web build
docs/multiplayer.md Shared worlds on a server: decisions, server, protocol
docs/isp-league.md The ISP league: design, rules and how each part was built
nix/ NixOS module and VM test for the server

The core owns all game state and renders HTML; the shell applies the DOM changes it gets back and draws the map. Shell and core talk JSON (crates/sot-core/src/protocol.rs), the same over a Worker message, Tauri IPC or a WebSocket to sot-server.

The map has two renderers. The classic one (the default) paints the original's cartoon land on a 2D canvas. The detailed one (Settings → Map) draws Natural Earth coastlines, lakes, rivers and borders from web/natural.bin with WebGL2 (web/glmap.js) on a canvas under the 2D map, in the same colours, and zooms to 64× instead of 16×. The choice is kept in localStorage (sot-map); without WebGL2 the game falls back to the classic map. The geography is Natural Earth 1:10m (public domain), pinned in flake.nix; node tools/natural-earth.mjs rebuilds web/natural.bin from it with the original's projection, magnifying lenses included.

Building and running

Everything happens in the devshell (direnv allow, or nix develop).

bash tools/build-web.sh serve     # browser build in dist/, served on http://localhost:8080
cargo run -p sot-desktop          # desktop app
cargo run -p sot-server -- --dist dist   # multiplayer server on http://localhost:8080 (after build-web.sh)

With Nix alone:

nix build .#web                   # the static site
nix run .#desktop                 # the desktop app
nix run .#server                  # the multiplayer server with the matching web build

Tests

cargo nextest run --workspace

Most tests compare the port with the original. Node scripts next to the fixtures (crates/sot-core/tests/fixtures/gen-*.mjs) load the original game in jsdom, play it, and record what it does: state after routing, incidents, months of day ticks, action scripts, and the HTML of every view. The Rust tests replay the same and must match exactly. Run a generator with --full to also write the complete expected output (not committed); the tests then name the first field or byte that differs.

The reference is the original in Node 24 on Linux. A few results depend on the JS engine and the C library under it: the order Array.prototype.sort gives for comparators that are not consistent, and the last bit of Math.pow. The port follows V8 13.6 and glibc there (js::sort_by, js::pow), natively and in WASM.

tools/parity/ plays both games side by side and compares state, routing results and the DOM after every step, from scripted scenarios or random play:

node tools/parity/build-port.mjs
node tools/parity/run.mjs tools/parity/scenarios
node tools/parity/run.mjs --fuzz 2000 --fuzz-seed 1

The tools need their npm packages once: npm ci --prefix tools.

Following upstream

The port follows upstream 2.5.0. The original is pinned by commit as the flake input upstream ($SOT_UPSTREAM in the devshell). To move to a newer version:

  1. Put the new commit into the upstream URL in flake.nix, run nix flake update upstream, then re-enter the devshell.
  2. node tools/extract-data.mjs && node tools/gen-data.mjs regenerates the data tables in crates/sot-core/data/ and the constants in src/data/consts.rs.
  3. Run the fixture generators and the tests. Whatever differs is what changed upstream and needs porting; node tools/coverage.mjs lists functions of the original without a port, by owner (tools/ownership.json; new functions count as "Unassigned").
  4. Check what changed upstream against the league's hook points (docs/isp-league.md).

docs/v2-port.md records how the move from 1.37 to 2.0 went, docs/v25-port.md the move to 2.5.

Since 1.34 the original is split into partials under src/ and assembled into one page at build time. tools/upstream.mjs assembles it with upstream's own scripts/lib/page.js. The original's code also says tr('area.words') now, with the English in src/i18n/en.js. The port keeps writing the English text, and resolves the labels that data tables and saves carry through the same dictionary (D.en). Some tables hold only label keys (SPOT_W CHARTERS INTERNS OPS* WS_* PZ_WK_THEMES AR_SHAPES, the names in BVAR); their English comes from D.en too.

The original gives windows and save slots ids from crypto.getRandomValues and stamps saves with Date.now(). tools/upstream.mjs seeds the first (apart from Math.random) and stops Date and performance.now at the parity clock's start unless a setup installs its own clock, so data extracts, fixtures and parity runs come out the same every time. tools/extract-data.mjs leaves out the original's runtime constants (WIN SLOT BC LOCKS doorAct PZ_UNDO), which are state, not data.

Weekly content

Every week starts Sunday 06:00 Berlin time with a new weekly puzzle, weekly scenario and weekly Architect run. The game fetches them when the Puzzles or Scenarios door opens, from <kind>/weekly/<YYYY-Www>.json next to the page (puzzles, scenarios, architect), 5 s at most; without a file it falls back to a seeded weekly puzzle and the classic weekly challenge. The desktop app reads them itself (its weekly command): weekly/<kind>/weekly/ in its data directory first, then the copy built into it.

Upstream publishes a week on Sundays from its latest code, so its files are priced for its newest release, not for the version pinned here. We make our own with upstream's generators, run against the pinned game:

node tools/weekly.mjs                       # this week and the next, into state/weekly
node tools/weekly.mjs --out DIR --key 2026-W47 --next 3
nix run .#weekly -- --out DIR               # the same without the devshell

tools/weekly.mjs runs scripts/weekly-{puzzle,scenario,architect}.js of $SOT_UPSTREAM as upstream's weekly workflow does: --check (weeks not over yet that the game no longer verifies are made again with a new rev), the new weeks, --check again. Each kind works on a copy and is moved into place only when all of it passed. The weeks upstream shipped are copied in first, so the generators avoid the themes and cities players saw last. --no-check only makes what is missing.

tools/build-web.sh puts the shipped weeks into dist/. sot-server serves <kind>/weekly/* from its weekly directory (--weekly, default <state>/weekly) before those, with ETags and Cache-Control: no-cache since a running week can get a new revision. The NixOS module runs the generator into /var/lib/sot-server/weekly: every Sunday at 04:00 Berlin time (timer sot-weekly), and at boot for weeks that are missing (sot-weekly-boot); set services.sot-server.weekly.enable = false to keep only the shipped weeks. Shared worlds on the server never fetch weekly files: league players never see the doors, and a co-op world has no Puzzles door and plays the classic weekly challenge instead of a published weekly scenario.

Benchmarks

cargo build --release -p sot-cli
./target/release/sot-cli bench tools/fixtures/late-game.json --n 30

License

MIT, like the original. See LICENSE.