- docs/PLAY.md is now the player guide: install from the tarball or .deb, starting a match, controls, how a match goes, settings files and troubleshooting, ahead of the graphics and tested-configuration sections. - docs/SERVER.md: quick start, every option, ports, being found, logs, Docker and systemd, memory, and what was checked. - CONTRIBUTING.md (engine setup, rules, commits, licence of contributions) and CREDITS.md. - README: status and known limitations as they are. - GDD controls table matched to the real defaults (B, Tab, G, 1 to 6). Running the documented commands from an unpacked release found two bugs, fixed here: - `tidewall --connect=HOST` ignored the option unless it came after `--`. ClientConfig.game_args() now takes the game's own options from the engine's arguments when there is no `--`; tested. - A headless run with no mode printed a line and never exited; it quits now. The renderer option is given as the pair the capture tests use (`--rendering-method gl_compatibility --rendering-driver opengl3`) in the docs, the tarball README and the man page. The Join menu only searching the LAN is documented and filed as #82. Closes #62 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
130 lines
5.2 KiB
GDScript
130 lines
5.2 KiB
GDScript
## What the client was asked to do on the command line.
|
|
##
|
|
## tidewall the main menu (with a window)
|
|
## tidewall --offline 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
|
|
##
|
|
## With a window and none of these, the game opens on its menus (AppShell). 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] = []
|
|
|
|
|
|
## Every option parse() knows, by name.
|
|
const OPTIONS: Array[String] = [
|
|
"--offline", "--autoplay", "--browse", "--list", "--lan-port", "--lan-target",
|
|
"--connect", "--name", "--seed", "--bots", "--client-seconds",
|
|
]
|
|
|
|
|
|
## The game's own options from the command line. Godot hands the options after "--" to
|
|
## the game (`user`); a player who leaves the "--" out, as in `tidewall --connect=HOST`,
|
|
## has them among the engine's options (`all`) instead, so then the ones this class
|
|
## knows are taken from there. The engine's own options, such as --headless, are left
|
|
## alone. With options after "--", those alone count.
|
|
static func game_args(user: PackedStringArray, all: PackedStringArray) -> PackedStringArray:
|
|
if not user.is_empty():
|
|
return user
|
|
var found: PackedStringArray = PackedStringArray()
|
|
for arg: String in all:
|
|
if OPTIONS.has(arg.split("=", true, 1)[0]):
|
|
found.append(arg)
|
|
return found
|
|
|
|
|
|
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()
|