Multiplayer for self-hosted copies: sessions, server-side saves, a leaderboard

Off unless the page is built with MP_API set (MP_API=/api/mp npm run
build): a plain build has no door, no chip and makes no requests. The
session server is scripts/mp-server.js (npm run mp), plain node:http,
which can also serve the built site so one process sits behind the
reverse proxy; docs/MULTIPLAYER.md has the nginx and Caddy setups.

A session has a six-character code, one seed and one rules preset, so
every player starts in the same world, and up to twelve players with
their own AS numbers. Saves go to the server on a new game day at most
every 15 s and when the page hides, ordered by a sequence number (409 on
a stale push, and the player picks which one to keep). Tokens live in
localStorage, never in the save; the server keeps only their hash. A
#mp= link moves a network to another device. The session panel shows
the leaderboard, the feed and a short chat; each player's public card
(tier, POPs, links, exchanges, transit, peak, customers, score) carries
what in-game peering between players will need next.

Server limits: body sizes, one upload per player, uploads per address
and in total, sessions per hour, wrong-code lockout; addresses counted
per IPv6 /64, X-Forwarded-For only with --trust-proxy.
This commit is contained in:
jvanvik 2026-11-07 00:42:39 +01:00
parent 2b48a6ad65
commit 95aa9b6532
39 changed files with 2757 additions and 24 deletions

View file

@ -3084,6 +3084,65 @@
"modal_and_names.the_real_thing_follow_a_packet":"The real thing: follow a packet from Wi-Fi to undersea fiber.",
"modals.lay_your_own_subsea_cable":"Lay your own subsea cable…",
"modals.your_own_subsea_cable_level_n":"Your own subsea cable <small>level {n} or Tier 1</small>",
"mp.code":"Session code",
"mp.copy_link":"Copy the link",
"mp.door_d":"One world, your friends' networks next to yours: share a code and race to Tier 1.",
"mp.err_code":"A session code has six letters and digits, like K7Q-2XD.",
"mp.err_full":"That session is full: every seat in it is taken.",
"mp.err_no_session":"There is no session with that code.",
"mp.err_offline":"The multiplayer server cannot be reached right now. Try again in a moment.",
"mp.err_refused":"The server did not take that. Try another network name.",
"mp.err_server_full":"The server is not taking new sessions right now.",
"mp.err_slow":"Too many tries from here. Wait a little and try again.",
"mp.feed":"Feed",
"mp.feed_empty":"Nothing yet. Say hello!",
"mp.feed_join":"{name} joined the session.",
"mp.feed_leave":"{name} left the session.",
"mp.feed_t1":"{name} is Tier 1 too.",
"mp.feed_t1first":"{name} is the first Tier 1 in this session!",
"mp.feed_t2":"{name} made Tier 2.",
"mp.intro":"Everyone builds their own network in the same world, from the same day 0, under the same rules. The leaderboard and the feed show who is ahead.",
"mp.join":"Join",
"mp.join_a_session":"Join a session",
"mp.join_note":"The world and the rules come from whoever started the session, and the session hands you your AS number.",
"mp.joined":"<b>You joined session {code}.</b> Open the session to see who is ahead.",
"mp.keep_mine":"Keep this one",
"mp.leaderboard":"Leaderboard",
"mp.leave":"Leave the session",
"mp.leave_d":"{name} stays on this device as a game of its own. The session forgets it, and its save on the server is deleted.",
"mp.leave_q":"Leave session {code}?",
"mp.left":"You left the session. {name} plays on here on its own.",
"mp.link_bad":"That multiplayer link did not work: it is old, or that network never saved to the session.",
"mp.link_copied":"Link copied. Open it on your other device.",
"mp.load_newer":"Load the newer save",
"mp.loaded_newer":"Loaded the newer save of {name} from the session ({date}).",
"mp.loading":"Asking the server…",
"mp.move_device":"Move to another device",
"mp.move_note":"Open this link on your other phone or computer to carry on with this network there. Whichever device saves last wins.",
"mp.move_warn":"Anyone with this link can play as you. Keep it to yourself.",
"mp.moved_on_elsewhere":"<b>This session moved on elsewhere.</b> Your network was played on another device since. Load that save, or keep this one and overwrite it.",
"mp.multiplayer":"Multiplayer",
"mp.n_customers":{"one":"{n} customer","other":"{n} customers"},
"mp.n_pops":{"one":"{n} POP","other":"{n} POPs"},
"mp.no_card":"has not finished a day yet",
"mp.no_newer":"The session has no newer save of {name}. This one stays, and goes to the server with the next save.",
"mp.not_in_session":"This network is no longer in its session. It keeps playing here on its own.",
"mp.play_with_friends":"Play with friends",
"mp.save_unreadable":"The session's save of this network could not be read. Playing on with the one here.",
"mp.say":"Say something",
"mp.send":"Send",
"mp.server_away":"The multiplayer server is away. Your network keeps playing here and catches up when it is back.",
"mp.session":"Multiplayer session",
"mp.session_code":"Session {code}",
"mp.session_live":"<b>Session {code} is live.</b> Share the code: whoever joins builds in the same world.",
"mp.session_title":"Session name (optional)",
"mp.share_line":"Join my Series of Tubes session {code}: {url}",
"mp.share_note":"Friends join from the title screen: Multiplayer, then this code.",
"mp.slow_down":"Slow down a little: one line a second.",
"mp.start_a_session":"Start a session",
"mp.talking":"Talking to the server…",
"mp.welcome_device":"<b>{name}</b> moved to this device. Welcome back to session {code}.",
"mp.you":"you",
"networks.a_mobile_network_named_after_the":"A mobile network named after the sound of a toast. Cheers to every 5G tower.",
"networks.a_spanish_carrier_starring_in_every":"A Spanish carrier starring in every Latin American market, at least until it sells the next one.",
"networks.a_tiny_telco_in_a_country":"A tiny telco in a country where the world’s cables come ashore. Prices to match.",