- 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>
106 lines
4.2 KiB
GDScript
106 lines
4.2 KiB
GDScript
## What the client was asked to do on the command line.
|
|
##
|
|
## tidewall an offline match against bots
|
|
## 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.
|
|
class_name ClientConfig
|
|
extends RefCounted
|
|
|
|
const DEFAULT_NAME: String = "Islander"
|
|
const DEFAULT_BOTS: int = Tuning.SOLO_PLAYERS - 1
|
|
|
|
## Empty to play offline.
|
|
var host: String = ""
|
|
var port: int = ServerConfig.DEFAULT_PORT
|
|
var player_name: String = DEFAULT_NAME
|
|
var match_seed: int = 0
|
|
var has_seed: bool = false
|
|
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 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] = []
|
|
|
|
|
|
static func parse(args: PackedStringArray) -> ClientConfig:
|
|
var config: ClientConfig = ClientConfig.new()
|
|
for arg: String in args:
|
|
var parts: PackedStringArray = arg.split("=", true, 1)
|
|
var value: String = parts[1] if parts.size() == 2 else ""
|
|
match parts[0]:
|
|
"--offline":
|
|
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(":")
|
|
config.host = value if at < 0 else value.substr(0, at)
|
|
if at >= 0:
|
|
var port_text: String = value.substr(at + 1)
|
|
config.port = port_text.to_int() if port_text.is_valid_int() else 0
|
|
if config.host.is_empty():
|
|
config.errors.append("--connect needs a host, as in --connect=192.0.2.7:%d" % ServerConfig.DEFAULT_PORT)
|
|
if config.port < 1 or config.port > 65535:
|
|
config.errors.append("the port in --connect must be between 1 and 65535")
|
|
"--name":
|
|
config.player_name = value
|
|
"--seed":
|
|
config.has_seed = value.is_valid_int()
|
|
config.match_seed = value.to_int()
|
|
if not config.has_seed:
|
|
config.errors.append("--seed must be a whole number, got '%s'" % value)
|
|
"--bots":
|
|
config.bots = value.to_int()
|
|
if not value.is_valid_int() or config.bots < 0 or config.bots > Tuning.SOLO_PLAYERS - 1:
|
|
config.errors.append("--bots must be between 0 and %d, got '%s'" % [Tuning.SOLO_PLAYERS - 1, value])
|
|
"--client-seconds":
|
|
config.seconds = value.to_float()
|
|
if not value.is_valid_float() or config.seconds <= 0.0:
|
|
config.errors.append("--client-seconds must be a number above 0, got '%s'" % value)
|
|
_:
|
|
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
|
|
|
|
|
|
func is_valid() -> bool:
|
|
return errors.is_empty()
|