Repository navigation
201 netplay 7 room codes
Question: after document 200 machines can set a match up together, but to link they still paste two long codes to each other through some chat, and only two machines can link that way in practice. How do players meet by typing a short code instead, how do three or four machines all link to each other, and where does the server that makes this work run (issue #154, stage N6; tracking #43)?
The netplay series: document 195 is the plan (stages N1 to N8); 196 is N1, save and restore; 197 is N2, the rollback session; 198 is N3, WebRTC and link codes; 199 is N4, the handshake; 200 is N5, the room. This document is N6, room codes.
| Term | Meaning |
|---|---|
| room server | A small server that knows which machines are in which room and passes messages between them. It never carries the match. |
| room code | Five letters and digits naming a room, such as NN325. The letters I, L and O and the digits 0 and 1 are never used, so nothing is misread. |
| signalling | Passing the WebRTC offers and answers between two machines before they can talk directly (document 188). In N3 the players did it by pasting; here the room server does it. |
| link code | One machine's WebRTC offer or answer, with its addresses, as text (document 198). The room server carries exactly these. |
| full mesh | Every machine linked directly to every other. The match's input words need it. |
| Durable Object | Cloudflare's unit of state: one small program instance per name, which every request for that name reaches. Here, one per room. |
| hibernation | A Durable Object leaving memory between messages while its WebSockets stay open. Idle time costs nothing on the free plan. |
- The user chose Cloudflare Workers (2026-12-06) as the room server's host, from the free options checked on that day (below). Its address is a setting, so another host or a tester's own server works too.
-
One set of rules, two homes.
server/src/rooms.jsholds the whole protocol.worker.jsruns it as a Cloudflare Worker with one Durable Object per room.node_server.mjsruns it as a plain Node program, for a machine of one's own and for the checks. The server lives in the game's repo (openfire-nettestserver/), as the plan says. The engine has only the client. -
The server carries link codes and nothing else. The host connects to
<server>/createand gets a room code. A joiner connects to<server>/join/<code>and gets the lowest free peer number (1 to 3). The server then passes{"t": "to", "peer", "data"}messages between the machines in the room. The data is the same link code a player would have pasted, soWebRtcTransportneeded no new way to connect. - Every machine links to every other. When a machine comes in, the server tells everyone already there, and each of them makes it an offer. The newcomer answers each one. Four machines make six links, with no relay through the host.
-
The engine's client is
NetSignal. It hangs off the transport (WebRtcTransport.signalling), which polls it, so it lives on through the room and the match without anyone else holding it. It sends a ping every 30 s so an idle connection stays open, and it reports failures with a reason:no_room,full,unreachable,closed(the host left) andlost(the server went away). - Link play leads with rooms. The screen shows the room server's address, which a player can change, then Host a room and Join a room. Link codes stay below them, for when there is no server. The host's room code is shown in large type, because it is read out loud, and it stays on the room screen so more people can join later.
-
Where the address comes from: the project setting
openfire/netplay/room_server; on the web,?server=in the page's address overrides it. With neither, the room buttons are off and the screen says to use link codes.
The plan left the host to the user (document 188 listed unverified candidates). The free options were checked on 2026-12-06:
| Host | What the free plan gives (as documented that day) | Cost to the game |
|---|---|---|
| Cloudflare Workers + Durable Objects (chosen) | SQLite-backed Durable Objects are on the free plan. 100,000 requests a day. WebSockets can hibernate, so an idle room costs nothing. No cold start. | Needs a free Cloudflare account. The Worker needs its own small adapter (worker.js). |
| Render free web service | Runs the Node server as it is. It sleeps after 15 minutes with no request or WebSocket message, and takes about a minute to wake. Render may restart it at any time, which drops every room. | Players wait a minute after a quiet spell. |
| Deno Deploy free | Sources disagreed on WebSocket limits on the free plan. The Classic version is being shut down. | Not checked further. |
| A machine of one's own | The Node server as it is, behind TLS for wss://. |
Upkeep. |
Sources: Cloudflare's Durable Objects pricing and limits; Render's free tier and its WebSocket change of February 2026; Deno's pricing and limits. One limit was not found in Cloudflare's pages: whether the free plan caps how many WebSockets can be open at once.
Mermaid source
sequenceDiagram
participant H as Host (peer 0)
participant S as Room server
participant A as Joiner A (peer 1)
participant B as Joiner B (peer 2)
H->>S: WebSocket /create
S->>H: room {code NN325, peer 0}
Note over H: shows NN325, read out to the others
A->>S: WebSocket /join/NN325
S->>A: room {peer 1, peers [0]}
S->>H: joined {peer 1}
H->>S: to 1: offer (link code)
S->>A: from 0: offer
A->>S: to 0: answer
S->>H: from 1: answer
Note over H,A: linked directly (WebRTC)
B->>S: WebSocket /join/NN325
S->>B: room {peer 2, peers [0, 1]}
S->>H: joined {peer 2}
S->>A: joined {peer 2}
H->>S: to 2: offer
A->>S: to 2: offer
S->>B: from 0: offer, from 1: offer
B->>S: to 0: answer, to 1: answer
S->>H: from 2: answer
S->>A: from 2: answer
Note over H,B: every machine linked to every other, the server carries nothing more
| Message | Direction | Meaning |
|---|---|---|
room {code, peer, peers} |
server → machine | the room it is in, its number, who else is there |
joined {peer} / left {peer}
|
server → machine | a machine came in (make it an offer) / a joiner went |
to {peer, data} → from {peer, data}
|
machine → server → machine | a link code passed on, with who sent it |
error {why} |
server → machine |
no_room and full end the connection; bad_message, too_big and no_peer do not |
closed |
server → machine | the host went: the room is over |
ping / pong
|
both ways | keeps a quiet connection open |
A message is at most 16 KB (a link code is under 1 KB). After a last message (a refusal or closed) the server waits 2 s before it closes the connection, so the machine reads the message and closes first. That delay was needed: Godot's WebSocketPeer dropped a message that came in just before the other side's close, so a joiner of a full room saw only "unreachable".
The shared rules, for a message from a machine:
// openfire-nettest server/src/rooms.js
export function handle(room, peer, text) {
const reply = room.peers.get(peer);
if (typeof text !== "string" || text.length > MAX_MESSAGE) return reply({ t: "error", why: "too_big" });
let m;
try {
m = JSON.parse(text);
} catch {
return reply({ t: "error", why: "bad_message" });
}
if (m === null || typeof m !== "object") return reply({ t: "error", why: "bad_message" });
if (m.t === "ping") return reply({ t: "pong" });
if (m.t !== "to" || !Number.isInteger(m.peer) || typeof m.data !== "string") return reply({ t: "error", why: "bad_message" });
if (m.data.length > MAX_DATA) return reply({ t: "error", why: "too_big" });
const to = room.peers.get(m.peer);
if (!to || m.peer === peer) return reply({ t: "error", why: "no_peer" });
to({ t: "from", peer, data: m.data });
}
/** `peer` went (its connection closed). The host going ends the room: true means the room is over. */
export function leave(room, peer) {
room.peers.delete(peer);
if (peer === 0) {
for (const [p, send] of room.peers) {
send({ t: "closed" });
room.close(p);
}
room.peers.clear();
return true;
}
for (const send of room.peers.values()) send({ t: "left", peer });
return room.peers.size === 0;
}On Cloudflare each room is the Durable Object named by its code. The object keeps no state of its own: the room is its open WebSockets, each tagged with its peer number. That is what lets it hibernate, which keeps an idle room free, and lose nothing when it does. A new room draws a code and asks that code's object; an object that already has connections answers 409, and the Worker draws again:
// openfire-nettest server/src/worker.js
async fetch(request) {
const kind = request.headers.get("X-Room-Kind");
const code = request.headers.get("X-Room-Code");
const taken = this.sockets().map((ws) => ws.deserializeAttachment().peer);
if (kind === "create" && taken.length > 0) return new Response(null, { status: 409 });
let peer = 0;
let refusal = "";
if (kind !== "create") {
peer = freePeer(taken);
refusal = !taken.includes(0) ? "no_room" : peer < 0 ? "full" : "";
}
const [client, server] = Object.values(new WebSocketPair());
...
this.ctx.acceptWebSocket(server);
server.serializeAttachment({ peer, code });
arrive(this.room(), code, peer);
return new Response(null, { status: 101, webSocket: client });
}A ping is answered by Cloudflare itself (setWebSocketAutoResponse) without waking the object.
NetSignal turns the server's messages into calls on the transport:
# addons/openfire_engine/game/net/net_signal.gd
func _take(m: Dictionary) -> void:
match String(m.get("t", "")):
"room":
code = String(m.get("code", ""))
me = int(m.get("peer", -1))
transport.set("me", me)
room_ready.emit(code, me)
"joined":
transport.call("offer", int(m.get("peer", -1))) # every machine already here links to the newcomer
"from":
var link_code := String(m.get("data", ""))
var d := WebRtcTransport.decode(link_code)
if d.get("kind") == "offer":
transport.call("accept", link_code)
elif d.get("kind") == "answer":
transport.call("finish", link_code)
"error":
var why := String(m.get("why", ""))
if why in ["no_room", "full"]:
_fail(why)
else:
push_warning("NetSignal: the room server says %s" % why)
"closed":
_fail("closed")and the other way, every link code the transport makes goes to the machine it is for:
# addons/openfire_engine/game/net/net_signal.gd
func _init(t: Object) -> void:
transport = t
transport.connect("code_ready", func(peer: int, link_code: String): _send({"t": "to", "peer": peer, "data": link_code}))WebRtcTransport.accept already took the joiner's own number from the offer's to. So a joiner taking an offer from another joiner works with no change, and that is all the mesh needed from the transport. Two things in poll and close were found by the check:
# addons/openfire_engine/game/net/net_signal.gd
func poll() -> void:
if _ended:
if _ws.get_ready_state() != WebSocketPeer.STATE_CLOSED:
_ws.poll() # a close goes out only through poll
return
_ws.poll()
var state := _ws.get_ready_state()
# what arrived is read first: a refusal ("no_room", "full") comes with the server's close
while _ws.get_available_packet_count() > 0:
...Without the first, a host that left was never seen to leave: its close frame was never sent, because nothing polled the socket after close. Without the second, a refusal that arrived in the same poll as the close was lost.
The Link play screen's two new pages (host_room_pressed, join_room_pressed) make a NetSignal for the transport, then go on to the room exactly as link codes do: on the first agreed hello (document 200).
| Check | What it proves |
|---|---|
openfire-nettest server/test/server_test.mjs (26 checks) |
Through a real server: a room with a five-letter code; joiners numbered 1, 2, 3, each told who is there, and everyone told of each newcomer; a code typed in lower case with a dash finds the room; messages host to joiner and joiner to joiner, and nobody else gets them; no_peer, bad_message, too_big and pong, none of which end the connection; a fifth machine gets full, an unknown code no_room, any other address no WebSocket; a joiner leaving is heard by all and its number is reused; the host leaving ends the room for everyone and the code is gone; two rooms never mix. It passes against the Node server and against the Worker under wrangler dev
|
openfire-nettest tests/signal_check.gd
|
Three machines' NetSignals through the Node server, each over a stand-in transport that makes link codes as WebRtcTransport does: the host offered to both joiners and took both answers; the first joiner answered the host and offered to the second; the second answered both, so every pair is linked. Refusals: a code that cannot be one is refused before connecting, then no_room, full, unreachable (no server), and closed for both joiners when the host leaves |
openfire-nettest CI (web.yml) |
The server test on Node and under wrangler dev, then a second browser pair: the two pages meet by room code through the local Worker, set the match up in the room, and must play the recording's 600 ticks, as the link-code pair does |
| by hand, two tabs, the local Worker | Link play → Host a room shows NN325 in large type. The second tab types nn-325 into Join a room. Both reach the room screen showing "Room code: NN325". The joiner moves its player, and the host sees it. The joiner says Ready; the host moves its own player, which clears the Ready, as it should. The joiner says Ready again, the host's Start comes on, and both tabs start the match on Crossroads |
| engine suite | 89 checks pass |
First green run: nettest c842855, engine cea82e5. The server test passed on Node and under wrangler dev. Then the two browser pages met in room J3DWV through the local Worker, as peers 0 and 1, and both rooms held the same setup. The matches started 17 ms apart, and both pages' 600 confirmed hashes equal the recording's, with no desyncs. In the same run the link-code pair stalled on 0 ticks (both pages took 9.7 s for 600 ticks). In N4 and N5's runs it stalled on about 185 to 212 ticks and took about 13 s. The code that pair runs did not change, so that difference was the runner's. This answers document 199's "seen, not explained", at least in part.
-
Under
wrangler dev, the Worker's own close of a hibernating WebSocket never reached the machine, from either Node's built-in WebSocket or thewspackage. The server's close went to CLOSING and stopped there. Closes the Worker makes on a socket it never hibernated (the refusals) do arrive. So a machine closes its own connection when toldclosed, and the server test checks the server's close only on the Node server. Whether deployed Cloudflare behaves the same is not yet known. -
The browser pane's
typeaction does not reach a Godot text box on the web, but single key presses do. This is a quirk of the tool, not of the game, and it is why N5's hand test could not paste a link code (document 200). Typing a room code works.
-
The server is not deployed yet. Deploying needs the user's Cloudflare account:
npx wrangler login, thennpx wrangler deployinserver/, then thewss://address goes intoproject.godot(server/README.md). Until then the published build has no room server, and Link play offers link codes only. - No TURN relay. Two machines whose routers both refuse direct links still cannot link. Signalling does not change that.
- No limits on abuse. Anyone can open rooms. Cloudflare's daily request cap is the only limit.
- Desktop builds still lack WebRTC, so room codes are web-only, like link codes.
- More than two machines in one match has not run in a browser. The mesh is checked through the server with stand-in transports, and the room and handshake handle any number of peers. A real three- or four-browser match is N8's try-out.
| What | Where |
|---|---|
| The server's rules | openfire-nettest server/src/rooms.js
|
| The Worker and its settings |
server/src/worker.js, server/wrangler.toml
|
| The Node server | server/src/node_server.mjs |
| The server's test, how to run and deploy it |
server/test/server_test.mjs, server/README.md
|
| The engine's client |
addons/openfire_engine/game/net/net_signal.gd (NetSignal), game/net/webrtc_transport.gd (signalling) |
| The screens |
game/net_link_screen.gd (Host a room, Join a room, the server's address), game/side_pick_screen.gd and game/net/net_room.gd (room_code) |
| The checks | openfire-nettest tests/signal_check.gd, tests/recorded_match/net_pair.gd (?server=), .github/workflows/web.yml; the engine's tools/ci/web_pair.mjs
|
Next: N7, #155: desyncs, statistics and disconnects. A desync stops the match with a report. Round trips and rollbacks are logged. A machine that drops pauses the match, and the host's policy from the room ("a computer takes over" or "the match ends") then applies.
Return Fire, rebuilt
Elsewhere