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:
@@ -3,11 +3,15 @@
|
||||
## tools/godot.sh -- --server [--listen] [--port=N] [--seed=N] [--players=N] [--bots=N]
|
||||
## [--bot-difficulty=mixed|easy|normal|hard] [--ticks=N]
|
||||
## [--unthrottled] [--log-every=N]
|
||||
## [--name=NAME] [--list=HOST[:PORT]]... [--no-lan]
|
||||
##
|
||||
## With `--listen` the server takes network players on UDP `--port`, waits in the lobby
|
||||
## for the first of them, and with any `--bots` above 0 fills each match's empty places
|
||||
## with bots. Without it the match starts at once with `--players` idle slots.
|
||||
##
|
||||
## A listening server answers LAN discovery on its port plus one unless `--no-lan`,
|
||||
## and registers with each `--list` server (see ListServer) under `--name`.
|
||||
##
|
||||
## Unknown or malformed arguments are errors, so a typo can't silently run the wrong
|
||||
## match. See `parse()`.
|
||||
class_name ServerConfig
|
||||
@@ -39,6 +43,12 @@ var unthrottled: bool = false
|
||||
## Logs a progress line every this many ticks. 0 turns progress lines off.
|
||||
var log_every: int = 0
|
||||
var fault: String = ""
|
||||
## The name shown in server lists.
|
||||
var server_name: String = NetDiscovery.DEFAULT_SERVER_NAME
|
||||
## List servers to register with: {"host", "port"}. Hosts may be names.
|
||||
var lists: Array[Dictionary] = []
|
||||
## Answer LAN discovery. On by default for a listening server.
|
||||
var lan: bool = true
|
||||
## Human-readable problems found while parsing. Empty when the config is usable.
|
||||
var errors: Array[String] = []
|
||||
|
||||
@@ -72,6 +82,9 @@ func to_dictionary() -> Dictionary:
|
||||
"bot_difficulty": "mixed" if bot_difficulty < 0 else String(Tuning.BOT_DIFFICULTIES[bot_difficulty]["name"]),
|
||||
"ticks": ticks,
|
||||
"unthrottled": unthrottled,
|
||||
"name": server_name,
|
||||
"lan": lan and listen,
|
||||
"lists": lists.size(),
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +95,9 @@ func _parse_one(arg: String) -> void:
|
||||
if arg == "--listen":
|
||||
listen = true
|
||||
return
|
||||
if arg == "--no-lan":
|
||||
lan = false
|
||||
return
|
||||
var parts: PackedStringArray = arg.split("=", true, 1)
|
||||
if parts.size() != 2 or not arg.begins_with("--"):
|
||||
errors.append("unknown argument '%s'" % arg)
|
||||
@@ -118,10 +134,44 @@ func _parse_one(arg: String) -> void:
|
||||
errors.append("--bot-difficulty must be mixed, easy, normal or hard, got '%s'" % value)
|
||||
"--fault":
|
||||
fault = value
|
||||
"--name":
|
||||
server_name = NetDiscovery.clean_server_name(value)
|
||||
"--list":
|
||||
var target: Dictionary = parse_host_port(value, NetDiscovery.DEFAULT_LIST_PORT)
|
||||
if target.is_empty():
|
||||
errors.append("--list needs HOST or HOST:PORT with a port from 1 to 65535, got '%s'" % value)
|
||||
else:
|
||||
lists.append(target)
|
||||
_:
|
||||
errors.append("unknown argument '%s'" % arg)
|
||||
|
||||
|
||||
## {"host", "port"} from "HOST" or "HOST:PORT", or empty if it doesn't parse. An
|
||||
## IPv6 address goes in brackets when it has a port: "[::1]:24660".
|
||||
static func parse_host_port(text: String, default_port: int) -> Dictionary:
|
||||
var host: String = text
|
||||
var port: int = default_port
|
||||
if text.begins_with("["):
|
||||
var close: int = text.find("]")
|
||||
if close < 0:
|
||||
return {}
|
||||
host = text.substr(1, close - 1)
|
||||
var rest: String = text.substr(close + 1)
|
||||
if not rest.is_empty():
|
||||
if not rest.begins_with(":") or not rest.substr(1).is_valid_int():
|
||||
return {}
|
||||
port = rest.substr(1).to_int()
|
||||
elif text.count(":") == 1:
|
||||
var at: int = text.find(":")
|
||||
host = text.substr(0, at)
|
||||
if not text.substr(at + 1).is_valid_int():
|
||||
return {}
|
||||
port = text.substr(at + 1).to_int()
|
||||
if host.is_empty() or port < 1 or port > 65535:
|
||||
return {}
|
||||
return {"host": host, "port": port}
|
||||
|
||||
|
||||
func _check_int(key: String, value: String) -> bool:
|
||||
if value.is_valid_int():
|
||||
return true
|
||||
@@ -145,5 +195,7 @@ func _validate() -> void:
|
||||
errors.append("--ticks can't be negative")
|
||||
if log_every < 0:
|
||||
errors.append("--log-every can't be negative")
|
||||
if not listen and (not lists.is_empty() or not lan):
|
||||
errors.append("--list and --no-lan are for a server started with --listen")
|
||||
if fault not in FAULTS:
|
||||
errors.append("unknown --fault '%s'" % fault)
|
||||
|
||||
Reference in New Issue
Block a user