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:
2026-11-12 17:33:32 -05:00
co-authored by Claude Opus 5.5
parent 53e81bebe1
commit f795ee3fa5
31 changed files with 1524 additions and 17 deletions
+32 -1
View File
@@ -4,6 +4,9 @@
## tidewall --connect=HOST[:PORT] join a server
## options: --name=NAME --seed=N --bots=N (offline) --autoplay
## --client-seconds=N quit after N seconds, saying what happened
## tidewall --browse [--list=HOST[:PORT]]... [--lan-target=ADDRESS]... [--lan-port=N]
## print the servers found on the LAN and in list
## servers as one JSON line, then quit
##
## Menus replace most of this later. Under tools/godot.sh, which has no window, a mode
## has to be asked for: --offline or --connect.
@@ -23,7 +26,15 @@ var bots: int = DEFAULT_BOTS
var autoplay: bool = false
## Quit after this many seconds; 0 runs until the window is closed.
var seconds: float = 0.0
## True when --offline or --connect was given.
## True for --browse: find servers and print them.
var browse: bool = false
## List servers to ask when browsing: {"host", "port"}.
var lists: Array[Dictionary] = []
## Where a LAN scan sends its queries; the broadcast address unless given.
var lan_targets: Array[String] = []
## The first game port a LAN scan asks about (see ServerBrowser.scan_lan()).
var lan_port: int = ServerConfig.DEFAULT_PORT
## True when --offline, --connect or --browse was given.
var asked: bool = false
var errors: Array[String] = []
@@ -38,6 +49,24 @@ static func parse(args: PackedStringArray) -> ClientConfig:
config.asked = true
"--autoplay":
config.autoplay = true
"--browse":
config.asked = true
config.browse = true
"--list":
var target: Dictionary = ServerConfig.parse_host_port(value, NetDiscovery.DEFAULT_LIST_PORT)
if target.is_empty():
config.errors.append("--list needs HOST or HOST:PORT, got '%s'" % value)
else:
config.lists.append(target)
"--lan-port":
config.lan_port = value.to_int() if value.is_valid_int() else 0
if config.lan_port < 1 or config.lan_port > 65534:
config.errors.append("--lan-port must be between 1 and 65534, got '%s'" % value)
"--lan-target":
if value.is_valid_ip_address():
config.lan_targets.append(value)
else:
config.errors.append("--lan-target needs an IP address, got '%s'" % value)
"--connect":
config.asked = true
var at: int = value.rfind(":")
@@ -67,6 +96,8 @@ static func parse(args: PackedStringArray) -> ClientConfig:
_:
if arg.begins_with("--"):
config.errors.append("unknown option '%s'" % arg)
if config.browse and not config.host.is_empty():
config.errors.append("--browse and --connect can't be used together")
return config