Link relay
The relay joins two emulators’ link cables through the server, so players need no port forwarding
and never learn each other’s IP address. It lives at /relay/{matchId}?ticket=<ticket>
(Relay/LinkRelay.cs).
Tickets
Section titled “Tickets”When a challenge is accepted, the server creates the Match and one relay ticket per player
(RelayTickets). A ticket contains:
- the match id;
- the account id;
- an expiry time 30 s ahead;
- an HMAC-SHA256 over all three, with a key derived from
Auth:SigningKeythat is separate from the JWT key.
A ticket is single-use, works only for its match, and is checked without a database lookup. Before accepting the WebSocket, the relay also checks that the match exists, hasn’t ended, and that the account is one of its players.
Pairing and relaying
Section titled “Pairing and relaying”- The first player to connect waits up to
Relay:WaitForPartner(30 s) for the second. - When both are there,
ConnectedAtis recorded and the relay copies WebSocket messages in both directions unchanged. Link timing stays entirely in the emulators (lockstep). - When one side closes, the relay:
- answers its close (completing the handshake);
- tells the other side (“The other player left” or “…connection was lost”);
- waits up to 2 s for it to close;
- ends the session.
The relay never parses the link protocol, except to notice the 1-byte Bye (5) a side sends when it
unplugs normally. That tells a clean exit from a dropped connection.
How a match ends
Section titled “How a match ends”EndReason |
Meaning |
|---|---|
Clean |
A player unplugged (the last message before the close was Bye) |
Disconnect |
A connection dropped without saying goodbye |
Timeout |
No traffic for Relay:IdleTimeout (10 min). Emulators send heartbeats every second, so this means both stopped |
NeverConnected |
The second player never reached the relay |
Moderated |
A moderator ended it (the player was banned) |
Error |
The server stopped or failed |
The match also records EndedById (whose side ended it) and BytesRelayed. Ending a match decides
its outcome from the verified rounds (Data model) and makes both
players available again in the lobby. Each end is logged, for example:
Match 01a233d6-… ended: Clean by 01a23303-… (unplugged), 4030050 bytes relayedModeration and live view
Section titled “Moderation and live view”LinkRelay.EndMatchesFor(accountId)cancels every session an account takes part in. It’s used by bans.LinkRelay.Snapshot()lists the sessions in progress (players, start, connected, bytes so far) for the dashboard’s Live and match pages.
