NetSnapshot defines the game traffic after the handshake: delta snapshots of quantized entity records, the client's input packet and a reliable match notice. SnapshotSender builds each client's snapshot against the newest one it acknowledged, tells it only about entities near the player it is watching, and keeps every snapshot under 1,200 bytes, nearest first, with a staleness bonus so nothing starves. SnapshotReceiver rebuilds the picture, ignores old and repeated snapshots and asks for a fresh start if it is ever sent a delta on something it doesn't hold. NetGame joins the transport to the match: people who connect become participants, their inputs go through ServerLoop.submit() once per tick, and snapshots go out 20 times a second. `--server --listen` makes the headless server take network players and wait in the lobby for the first of them. Measured by test on a 24-player match start with every player a client, a tenth of packets lost and late acknowledgements: 2.4 KB/s mean and 2.5 KB/s for the worst client, packet headers included, against a 40 KB/s limit. Closes #33 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
3.2 KiB
GDScript
88 lines
3.2 KiB
GDScript
extends TestCase
|
|
|
|
|
|
func _parse(args: Array[String]) -> ServerConfig:
|
|
return ServerConfig.parse(PackedStringArray(args))
|
|
|
|
|
|
func test_without_server_flag_nothing_is_parsed() -> void:
|
|
var config: ServerConfig = _parse(["--seed=5", "--bots=3"])
|
|
assert_false(config.server)
|
|
assert_eq(config.bots, 0)
|
|
assert_true(config.is_valid())
|
|
|
|
|
|
func test_defaults() -> void:
|
|
var config: ServerConfig = _parse(["--server"])
|
|
assert_true(config.server)
|
|
assert_true(config.is_valid())
|
|
assert_false(config.has_seed)
|
|
assert_eq(config.port, ServerConfig.DEFAULT_PORT)
|
|
assert_eq(config.ticks, 0)
|
|
assert_false(config.unthrottled)
|
|
|
|
|
|
func test_all_options() -> void:
|
|
var config: ServerConfig = _parse([
|
|
"--path", "/ignored", "--server", "--seed=-17", "--port=4000", "--players=3",
|
|
"--bots=20", "--ticks=900", "--unthrottled", "--log-every=30", "--bot-difficulty=hard",
|
|
])
|
|
assert_true(config.is_valid(), str(config.errors))
|
|
assert_true(config.has_seed)
|
|
assert_eq(config.match_seed, -17)
|
|
assert_eq(config.port, 4000)
|
|
assert_eq(config.players, 3)
|
|
assert_eq(config.bots, 20)
|
|
assert_eq(config.ticks, 900)
|
|
assert_true(config.unthrottled)
|
|
assert_eq(config.log_every, 30)
|
|
assert_eq(config.bot_difficulty, BotBrain.HARD)
|
|
assert_eq(config.to_dictionary()["bot_difficulty"], "hard")
|
|
|
|
|
|
func test_listen_is_off_by_default_and_refuses_idle_slots() -> void:
|
|
assert_false(_parse(["--server"]).listen)
|
|
var config: ServerConfig = _parse(["--server", "--listen", "--port=4001", "--bots=24"])
|
|
assert_true(config.is_valid(), str(config.errors))
|
|
assert_true(config.listen)
|
|
assert_eq(config.to_dictionary()["listen"], true)
|
|
assert_false(_parse(["--server", "--listen", "--players=2"]).is_valid())
|
|
|
|
|
|
func test_bot_difficulty_defaults_to_mixed_and_rejects_unknown_names() -> void:
|
|
assert_eq(_parse(["--server"]).bot_difficulty, -1)
|
|
assert_eq(_parse(["--server", "--bot-difficulty=mixed"]).bot_difficulty, -1)
|
|
assert_eq(_parse(["--server", "--bot-difficulty=easy"]).bot_difficulty, BotBrain.EASY)
|
|
var bad: ServerConfig = _parse(["--server", "--bot-difficulty=brutal"])
|
|
assert_false(bad.is_valid())
|
|
|
|
|
|
func test_large_seed_round_trips() -> void:
|
|
var config: ServerConfig = _parse(["--server", "--seed=9223372036854775807"])
|
|
assert_eq(config.match_seed, 9223372036854775807)
|
|
assert_eq(config.to_dictionary()["seed"], 9223372036854775807)
|
|
|
|
|
|
func test_unknown_argument_is_an_error() -> void:
|
|
var config: ServerConfig = _parse(["--server", "--bot=3"])
|
|
assert_false(config.is_valid())
|
|
assert_true(config.errors[0].contains("--bot=3"))
|
|
|
|
|
|
func test_non_numeric_value_is_an_error() -> void:
|
|
var config: ServerConfig = _parse(["--server", "--seed=abc"])
|
|
assert_false(config.is_valid())
|
|
assert_false(config.has_seed)
|
|
|
|
|
|
func test_ranges_are_checked() -> void:
|
|
assert_false(_parse(["--server", "--port=0"]).is_valid())
|
|
assert_false(_parse(["--server", "--port=70000"]).is_valid())
|
|
assert_false(_parse(["--server", "--bots=-1"]).is_valid())
|
|
assert_false(_parse(["--server", "--ticks=-1"]).is_valid())
|
|
assert_false(_parse(["--server", "--fault=meteor"]).is_valid())
|
|
var too_many: String = "--bots=%d" % (Tuning.SOLO_PLAYERS + 1)
|
|
assert_false(_parse(["--server", too_many]).is_valid())
|
|
var full: Array[String] = ["--server", "--players=4", "--bots=%d" % (Tuning.SOLO_PLAYERS - 4)]
|
|
assert_true(_parse(full).is_valid())
|