Lobby service (5DO client)¶
Status: prototype, 2026-11-29. The lobby server moved to the separate GameLobby solution. This page documents the 5DO client and the shared HTTP, WebSocket, and relay contract. Server installation, deployment scripts, the admin dashboard, and server operations now live in GameLobby.
The service does four jobs:
- Register rooms and human join codes over HTTP.
- Exchange room presence and transport state over WebSockets.
- Discover public UDP endpoints and coordinate NAT hole punching.
- Relay the emulator control channel over TCP and the emulator data channel over UDP when a direct path is blocked.
It never interprets save states, frame hashes, input packets, or guest network frames.
1. What runs where¶
| Component | Runs on | Responsibility |
|---|---|---|
GameLobby.Server | Windows VPS | Room registry, join codes, WebSocket signaling, TCP control relay, UDP rendezvous, UDP relay; separate GameLobby solution |
GameLobby.Protocol | Server | Server-side HTTP/WebSocket models, UDP datagram codec, TCP relay handshake |
FiveDo.Lobby.Protocol | 5DO client | 5DO's own HTTP/WebSocket client models; each emulator keeps its client |
| 5DO | Player PC | TCP state transfer, UDP lockstep input and hashes, desktop lobby dialog and --lobby client path |
| XGrid | Player PC | Its own handshake and guest-network framing over the same control/data relays |
FiveDo.LobbyProbe | Any test machine | Headless room/control/UDP probe without a disc or BIOS |
The VPS sees only opaque bytes after the relay handshake. It does not need a 3DO BIOS, an Xbox BIOS, a game image, or any emulator dependency. Clients do not reference the GameLobby server project; the wire contract is the integration boundary.
2. Server repository and dashboard¶
- Server source:
GameLobbyrepository,src/GameLobby.Serverandsrc/GameLobby.Protocol. - Deployment:
GameLobby/packaging/windows/install-lobby-iis.ps1(separate IIS site and app pool) orinstall-lobby-service.ps1(Windows service). - Admin dashboard:
https://lobby.purelogiccode.com/admin, ASP.NET Core Identity + SQLite, with active rooms/players/connections, request and failure counters, relay usage, health, and a 60-minute activity chart. - Configuration: see GameLobby
docs/Admin.mdanddocs/Lobby.md.
The 5DO repository no longer contains the server, the IIS/service installers, or the server tests. The old src\FiveDo.Lobby paths in older notes are obsolete.
3. 5DO usage¶
The desktop Netplay dialog supports both direct IP and the online lobby. Open the disc and BIOS, start the game, then:
- Host (desktop): Netplay > Host Session..., select Use the online lobby, leave the lobby URL at
https://lobby.purelogiccode.com, and select Create lobby room. Share the six-character room code. Transport selects automatic punching with relay fallback, forced relay, or direct only. The host closes the room when Stop Session is selected. - Join (desktop): Netplay > Join Session..., select Use the online lobby, enter the room code, and select Join lobby room.
Both peers must use the same disc, BIOS, and behavior-affecting settings. The desktop uses its saved settings; a CLI peer must match them (for example, add --high-res when the desktop has High resolution enabled, which is the new-settings default, or use the same --profile).
The 5DO CLI can also create or join a lobby room directly.
Host:
5do netplay host game.chd --bios bios/panafz1.bin `
--lobby http://lobby.example.com:8080 `
--frames 3600
The host prints a join code, for example:
Join:
5do netplay join X7JTX4 game.chd --bios bios/panafz1.bin `
--lobby http://lobby.example.com:8080 `
--frames 3600
Options:
| Option | Meaning |
|---|---|
--lobby <url> | Absolute http or https lobby URL |
--lobby-name <name> | Display name shown in room status |
--lobby-relay | Force the TCP/UDP relay path |
--lobby-direct | Require direct punching; no relay fallback |
--lobby-timeout <seconds> | Direct-punch deadline before relay fallback (default 3) |
The host uses the lobby TCP relay for state transfer and the UDP rendezvous for input and hash traffic. The join does the same. If direct punching does not produce a game packet within the deadline, both sides switch to the relay automatically. --lobby-relay is useful for validating the relay path; --lobby-direct is useful for debugging NAT behavior.
The resulting JSON includes lobby, roomCode, and transport in addition to the direct-IP fields.
Validated 2026-11-29: the deployed GameLobby service passed 600-frame sessions in both directions on the LAN, forced-relay sessions on the LAN, and cross-NAT sessions between Windows x64 and Azure linux-arm64 on direct and relay paths. A Windows desktop host and Linux X11 desktop join also ran past 3,000 frames. See Compatibility.md §10.21 for room codes and hashes. The 3,000-frame reconnect run resumed at frame 1717, but the host stopped at 2,999 when the join exited; that finish race is still open.
4. Emulator-agnostic control plane¶
Rooms carry the following tags:
| Field | Example | Meaning |
|---|---|---|
emulator | 5do or xgrid | Emulator family |
protocolVersion | 1 | The emulator-facing handshake version |
contentId | disc or title id | Opaque content identity |
contentHash | optional | Optional content fingerprint |
maxPlayers | 2 | Prototype supports two slots |
playerSlot | 0 or 1 | Host or join |
The lobby rejects a join when emulator, protocolVersion, contentId, or a supplied contentHash does not match the room. The emulator still performs its own full state and content validation; the lobby check is only an early UX rejection.
4.1 HTTP API¶
| Method | Path | Purpose |
|---|---|---|
GET | /healthz | Health, room count, UDP port, uptime |
POST | /v1/rooms | Create a room and return the host token |
POST | /v1/rooms/{code}/join | Join a room and return a slot token |
GET | /v1/rooms/{code} | Public room status |
DELETE | /v1/rooms/{code} | Close a room with the host bearer token |
GET | /v1/signal | WebSocket signaling upgrade |
Create:
POST /v1/rooms
Content-Type: application/json
{
"emulator": "5do",
"protocolVersion": 1,
"contentId": "T2K-USA",
"contentHash": "0x1234567890abcdef",
"displayName": "Alice",
"maxPlayers": 2
}
The response contains room.joinCode, hostToken, room.udpRoomId, and these endpoints:
{
"room": {
"udpRoomId": "1c55f1a4cd7ed5d1",
"joinCode": "YRERN9",
"emulator": "5do",
"protocolVersion": 1,
"contentId": "T2K-USA",
"signal": { "host": "lobby.example.com", "port": 8080 },
"signalPath": "/v1/signal",
"controlRelay": { "host": "lobby.example.com", "port": 40000 },
"udpRendezvous": { "host": "lobby.example.com", "port": 5700 },
"udpRelay": { "host": "lobby.example.com", "port": 41000 },
"expiresAt": "2026-11-27T18:00:00Z"
},
"hostToken": "857574888d93464cb3d1a39d0e05583e"
}
Join uses the same metadata plus an optional slotToken for a reconnect. It returns room, slotToken, and slot.
Errors are structured:
4.2 WebSocket signaling¶
Connect to ws(s)://<host>:<port>/v1/signal?room=<joinCode>&token=<slotToken>.
Server messages:
type | Meaning |
|---|---|
welcome | Initial room snapshot and assigned slot |
peer-joined | The other slot joined |
peer-left | The other slot left |
transport | A peer reported auto, direct, or relay |
ready | A peer reported readiness |
closed | The room closed |
pong | Reply to a client ping |
error | Invalid or oversized client message |
Client messages:
{ "type": "ready" }
{ "type": "transport", "mode": "direct" }
{ "type": "ping" }
{ "type": "leave" }
The 5DO CLI does not require the WebSocket; it uses HTTP for room setup and the relays for traffic. Desktop shells and XGrid can use the socket for presence and transport status.
4.3 TCP control relay¶
Each room gets one TCP relay port. The relay is byte-transparent after a small pre-handshake, so 5DO's framed control channel and XGrid's handshake/state payloads both work unchanged.
Each peer connects and sends a 32-byte header:
0 "5DLC"
4 version (1)
5 player slot (0 or 1)
6-7 reserved
8-15 room id (little-endian)
16-31 slot token (GUID bytes)
The relay validates the room id and token, pairs one slot 0 with one slot 1, and sends both an 8-byte preamble:
After the preamble the relay copies bytes in both directions. The host and join must both send the connect header before either reads the preamble. A reconnect opens a new pair; the room and its relay port stay alive.
4.4 UDP rendezvous and relay¶
The rendezvous datagram is 48 bytes, IPv4 only:
| Offset | Size | Field |
|---|---|---|
| 0 | 4 | magic 5DOL |
| 4 | 1 | version 1 |
| 5 | 1 | type |
| 6 | 1 | player slot |
| 7 | 1 | transport mode (0 auto, 1 direct, 2 relay) |
| 8 | 8 | room id, little-endian |
| 16 | 16 | slot token, or zero |
| 32 | 8 | nonce, little-endian |
| 40 | 4 | peer IPv4 address, network order |
| 44 | 2 | peer port, little-endian |
| 46 | 2 | relay port, little-endian |
Types:
| Type | Direction | Meaning |
|---|---|---|
Register | client to 5700 | Register or refresh the game socket's public endpoint |
RegisterAck | server to client | Registered; includes the peer endpoint if known |
Peer | server to client | Peer public endpoint and punch nonce |
Punch | client to peer | Open the NAT mapping toward the peer |
RelayHello | client to relay port | Register the game socket at the relay |
RelayAck | relay to client | Relay registration accepted |
Bye | client to server | Leave the room |
Keepalive | client to 5700 | Refresh registration |
The client sends Register from the same UDP socket that carries game traffic. The server records the public source endpoint. When both slots are registered, each client receives the other's endpoint and a punch nonce, then sends Punch packets directly to the peer. If both NATs are cone-like, the game packets flow directly.
If no direct game packet arrives within the deadline, the client sends RelayHello to the room's UDP relay port and sends game traffic to the relay. The relay records each source endpoint from RelayHello and forwards every non-lobby datagram unchanged to the other slot. It never parses the emulator payload.
5. XGrid integration (in the XGrid repository)¶
Do not edit the XGrid tree from a 5DO change. The shared contract is the HTTP/WebSocket API, the TCP relay handshake, and the UDP datagram format above. When XGrid integrates:
- Tag rooms with
emulator: "xgrid"and an XGrid handshakeprotocolVersion. - Use
contentIdfor the XBE title id or image identity. - Keep the XGrid handshake/state payload on the TCP control relay.
- Keep guest Ethernet/UDP framing on the UDP direct/relay path. The relay is byte-transparent and preserves datagram boundaries.
- Reuse the same auto/direct/relay decision: direct first, relay after the deadline.
- Keep XGrid's own state transfer, frame sync, and hashing out of the lobby.
XGrid already has its own netplay client and UI (NetplaySettings, LobbyApiClient, and NetplayViewModel); keep those changes in the XGrid repository. The GameLobby server accepts xgrid rooms and the same HTTP/WebSocket/relay contract, but 5DO changes must not edit the XGrid tree.
6. Headless probe¶
tools/FiveDo.LobbyProbe exercises the control plane without a disc or BIOS. It creates or joins a room, opens the WebSocket, pairs the TCP relay, registers UDP endpoints, and exchanges PING/PONG datagrams.
Host:
dotnet run --project tools\FiveDo.LobbyProbe -c Release -- `
host --lobby http://127.0.0.1:8080 `
--emulator xgrid --content probe-test --pings 20 --interval 500
Join:
dotnet run --project tools\FiveDo.LobbyProbe -c Release -- `
join --lobby http://127.0.0.1:8080 --code <JOIN_CODE> `
--emulator xgrid --content probe-test
Use --relay to force the UDP relay, --direct to require punching, and --no-ws to skip WebSocket signaling. The summary prints the path (Direct or Relay), local and peer endpoints, and packet counts.
7. Security and limitations¶
This is a prototype, not a production matchmaking service.
- Rooms and tokens are in memory only; restarting the service drops every room.
- Tokens are bearer secrets. Use HTTPS, do not put tokens in logs, and do not share the host token with the joining player.
- There is no account system, moderation, or abuse reporting yet. Rate limits and per-IP quotas are described in §7.1.
- The UDP protocol is IPv4 only. IPv6 and dual-stack are future work.
- Exactly two player slots are supported.
- The relay forwards packets without encryption or integrity checks. Emulator protocols must provide their own authentication/integrity if they need it.
- The origin IP is reachable without Cloudflare unless you restrict it. Add IIS IP Security/Cloudflare IP allowlisting or Cloudflare Authenticated Origin Pulls before treating the origin as private.
TrustCloudflareHeadersis only trustworthy when direct origin access is blocked; otherwise a caller can spoofCF-Connecting-IP. - Relay traffic counts against VPS bandwidth. Size the plan for the expected number of simultaneous sessions.
- The service is designed for a small number of rooms (
MaxRoomsdefault 500). Each relayed room consumes one TCP and one UDP port. PublicHostmust be the address players can reach. A private LAN address in the room response will not work over the internet.
7.1 Rate limits and quotas¶
| Setting | Default | Effect |
|---|---|---|
MaxRooms | 500 | Global live-room cap |
MaxRoomsPerIp | 5 | Live rooms created by one client IP |
RoomCreatePerMinute | 5 | Room-create requests per IP per minute |
RoomJoinPerMinute | 20 | Join requests per IP per minute |
SignalPerMinute | 10 | WebSocket upgrades per IP per minute |
GlobalRequestsPerMinute | 120 | All HTTP requests per IP per minute |
MaxUdpRelayBytesPerSecond | 1,000,000 | Per-room UDP relay budget; 0 disables |
MaxControlRelayMinutes | 10 | Maximum TCP control relay pair lifetime; 0 disables |
MaxRendezvousDatagramsPerSecond | 5,000 | Global rendezvous datagram budget; 0 disables |
MaxRequestBytes | 65,536 | HTTP request body cap |
HTTP limits return 429 with a JSON body and Retry-After. The health endpoint bypasses all limiters so a monitor is never rate-limited.
TrustCloudflareHeaders controls whether CF-Connecting-IP is used for the IP partition. Enable it only when the site is reachable exclusively through Cloudflare; if the origin is directly reachable, a client can spoof that header. The IIS deployment scripts set it to true by default.
The UDP relay drops packets above the per-room byte budget. The TCP control relay closes pairs after the configured lifetime. These are abuse caps, not traffic shaping; size them for the highest expected emulator rate.
7.2 Logs and monitoring¶
- IIS writes HTTP access logs under
C:\inetpub\logs\LogFiles\W3SVC<site-id>. Find the lobby site id withappcmd list site GameLobby; see GameLobbydocs/Admin.md. - In-process ASP.NET Core errors and warnings are in the Windows
Applicationevent log:
Get-WinEvent -LogName Application -MaxEvents 50 |
Where-Object { $_.ProviderName -match 'IIS|ASP.NET|Runtime' }
- Run the health probe from Task Scheduler every 5 minutes:
It exits 0 when /healthz reports status: ok and 1 otherwise. Point an external uptime monitor at https://lobby.purelogiccode.com/healthz as the first alert. - Do not use Test-NetConnection lobby-direct.purelogiccode.com -Port 40000 as a health check: relay listeners exist only while a room is active. - Cloudflare Analytics shows request volume and error rates. Keep Full (strict) TLS enabled after the origin certificate is installed.
7.3 Origin lock¶
The origin IP can be reached without Cloudflare unless it is locked down. The app supports an origin-secret header that blocks direct-origin HTTP/WebSocket requests.
Cloudflare setup:
- Rules → Transform Rules → Modify Request Header → Create rule
- Expression:
http.host eq "lobby.purelogiccode.com" - Set static header
X-FiveDo-Origin-Secretto a random value of at least 32 characters (64 hex characters works well). - Deploy the rule.
Store the same value on the VPS and install with the GameLobby installer (GameLobby\packaging\windows\install-lobby-iis-package.ps1):
.\install-lobby-iis-package.ps1 `
-PackagePath C:\Deploy\gamelobby-iis.tar.gz `
-HostName lobby.purelogiccode.com `
-RelayHost lobby-direct.purelogiccode.com `
-CertificateThumbprint <thumbprint> `
-OriginSecretFile C:\Deploy\lobby-origin-secret.txt `
-TrustCloudflareHeaders `
-AdminEmail <admin-email> `
-AdminPassword <admin-password> `
-Force
The app returns 403 {"code":"forbidden"} when the header is missing or wrong. Loopback /healthz requests are exempt so the local health probe keeps working. Enable the app-side secret only after the Cloudflare rule is live; otherwise public requests will be rejected.
Verify:
# Through Cloudflare: 200
Invoke-RestMethod https://lobby.purelogiccode.com/healthz
# Direct origin without the header: 403
curl.exe -k --resolve lobby.purelogiccode.com:443:107.174.146.107 `
https://lobby.purelogiccode.com/healthz
7.4 Edge cache and rate limits¶
5DO clients select the production lobby with --lobby https://lobby.purelogiccode.com; the room response advertises lobby-direct.purelogiccode.com for the TCP/UDP relay endpoints.
The purelogiccode.com zone (currently the Free plan) carries these Cloudflare rules for the lobby:
- Cache bypass (
http_request_cache_settings, ruleFiveDo Lobby no-cache):http.host eq "lobby.purelogiccode.com" and (starts_with(http.request.uri.path, "/v1/") or http.request.uri.path eq "/healthz")withcache: false. This covers the room API, WebSocket signaling, and health endpoint. Cloudflare may reportcf-cache-status: DYNAMICfor a bypassed dynamic response; it must never reportHIT. - Rate limiting: the requested 30-requests/1-minute rule requires the Host field and a 60-second window, which the Free plan does not offer (Free allows the Path field only, a 10-second window, and one rule). The app-level limits in §7.1 remain the enforcement point: room-create 5/min, join 20/min, signal 10/min, global 120/min, with
/healthzexempt. The exact edge rule requires Pro or higher.
Do not enable Bot Fight Mode or Under Attack Mode for this hostname; both can challenge the 5DO/XGrid API clients. The zone is on security_level: medium with Bot Fight Mode off.
Validated 2026-11-27 through https://lobby.purelogiccode.com: room create/join/delete returned 201/200/204, WebSocket signaling returned 101 and a welcome message, the TCP control relay paired on lobby-direct.purelogiccode.com:40000, and FiveDo.LobbyProbe --relay completed with 7 of 8 UDP ping/pong replies over the relay path (UDP loss is expected); both peers exited 0. A direct-origin request without X-FiveDo-Origin-Secret returned 403, and CF-Connecting-IP partitioning is enabled by Lobby:TrustCloudflareHeaders=true in appsettings.Production.json.
8. Troubleshooting¶
| Symptom | Check |
|---|---|
room_not_found | Join code case, room expiry, service restart |
content_mismatch | Same disc/title, BIOS, and tuning; same contentHash |
| Control relay connects but never pairs | Both players used the same room; host and join both sent the 32-byte header |
UDP path stays Auto | Both players registered from the game socket; UDP 5700 and the relay range are open |
| Direct fails, relay works | Symmetric NAT or restrictive firewall; expected fallback |
| Relay works but game desyncs | The lobby is transparent; investigate the emulator's own state/hash path |
| Browser WebSocket upgrade fails | Reverse proxy must forward Upgrade/Connection headers |
The desktop shell trims and uppercases the six-character join code before the request. room_not_found, room_expired, room_full, content_mismatch, protocol_mismatch, emulator_mismatch, unauthorized, and room_quota are expected 4xx rejections: they show an actionable message and are logged at Information, so a mistyped or expired code does not generate a bug report. Unexpected 5xx responses remain Error-level.
For local validation without a VPS, use the separate GameLobby solution:
dotnet run --project <GameLobby>\src\GameLobby.Server -c Debug --urls http://127.0.0.1:8080
dotnet test <GameLobby>\GameLobby.sln
The 5DO client tests remain in tests\FiveDo.Tests; the server and dashboard tests live in GameLobby.