N6: Joining games: direct connect, LAN and server list
- LAN discovery: a listening server answers QUERY packets on its game port plus one (ServerBeacon, off with --no-lan). ServerBrowser scans eight game ports from 24650 by broadcast. - A self-hostable list server: --list-server [--port=N] (ListServer, default UDP 24660). Game servers register with --list=HOST[:PORT] and --name=NAME; they are listed under their source address only after echoing a CHALLENGE token. Entries expire after 45 s, 8 per address, 256 in all; every source is rate-limited (SourceLimiter). - NetDiscovery messages: every QUERY is padded to 512 bytes and no answer is bigger, so neither service amplifies spoofed requests. - tidewall --browse [--list=...] [--lan-target=IP] [--lan-port=N] prints the servers found as JSON until menus (A10) show them. - People who connect mid-match or during results watch a living player (Match.watch) and take places ahead of bots in the next lobby, instead of being told the server is full. Bots fill only the places left when the match starts. - Tests: codec round trips, size limits and a 40,000-message fuzz; list server with fake servers (challenge, stolen and wrong tokens, renewal, expiry, caps, flood); LAN scan over loopback; watchers over UDP; lobby backfill. make discovery-check runs it all as real processes. Closes #37 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -144,6 +144,39 @@ timeout (5 to 15 seconds without an acknowledgement), and the owner sees the sam
|
||||
raise an engine error; anything a joined player sends that isn't understood is counted
|
||||
and dropped.
|
||||
|
||||
## Finding and joining games
|
||||
|
||||
People join a server three ways, none needing a third-party service:
|
||||
|
||||
- **By address.** `--connect=HOST[:PORT]`; the game port defaults to 24650.
|
||||
- **On the LAN.** A listening server answers discovery QUERY packets on its game port
|
||||
plus one (`ServerBeacon`), unless started with `--no-lan`. A scan
|
||||
(`ServerBrowser.scan_lan()`) broadcasts a QUERY to the discovery ports of eight game
|
||||
ports, 24650 and the next seven even ports, so several servers on one machine are
|
||||
found.
|
||||
- **Through a list server.** Anyone can run one: `--list-server [--port=N]`
|
||||
(`ListServer`, default UDP 24660). A game server started with `--list=HOST[:PORT]`
|
||||
sends a REGISTER every 15 s. The list server answers an unknown or wrong token with
|
||||
a CHALLENGE carrying a token derived from a per-start secret and the sender's
|
||||
address and port, and lists the server only when a REGISTER echoes it. Servers are
|
||||
listed under the address their packets come from, never a claimed one. Entries
|
||||
expire after 45 s, with at most 8 per address and 256 in all. Clients ask for the
|
||||
list four servers per page, one page after another.
|
||||
|
||||
The messages are in `NetDiscovery`. Every QUERY is padded to 512 bytes and no answer
|
||||
is larger, so neither the beacon nor the list server can amplify a spoofed request.
|
||||
Both rate-limit each source address (`SourceLimiter`: 20 packets a second, at most
|
||||
4,096 addresses tracked per second).
|
||||
|
||||
**Lobby, backfill and late arrivals.** People who connect during the lobby or the
|
||||
countdown take places (`Match.join()`); bots are only added when the match starts,
|
||||
into whatever places are still empty, so people joining and leaving in the lobby
|
||||
never displace or strand a bot. Someone who connects after the barge leaves, or
|
||||
during results, becomes a watcher (`Match.watch()`): they spectate a living player
|
||||
(the winner during results) through the same snapshots an eliminated player gets,
|
||||
and take a place ahead of any bots when the next lobby opens. The server still turns
|
||||
people away when `NetServer.max_players` people are connected.
|
||||
|
||||
## Snapshot format
|
||||
|
||||
`NetSnapshot` (`src/net/`) owns the layouts. An entity travels as a **record**: a list
|
||||
|
||||
Reference in New Issue
Block a user