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
+29 -3
View File
@@ -155,15 +155,41 @@ func test_leaving_takes_the_player_out_of_the_match() -> void:
assert_eq(odo.state, NetClient.JOINED)
func test_a_full_match_turns_the_next_person_away() -> void:
func test_someone_arriving_mid_match_watches_a_living_player() -> void:
_client("Mara")
_client("Odo")
assert_true(_pump(func() -> bool: return loop.match_flow.in_match()))
# Bots filled the other two places, so there is no room until this match ends.
# Bots filled the other two places, so the newcomer watches until the next match.
var late: NetClient = _client("Late")
var late_index: int = clients.size() - 1
assert_true(_pump(func() -> bool: return late.state == NetClient.JOINED and receivers[late_index].own_id != 0), "the newcomer is sent someone to watch")
var flow: Match = loop.match_flow
assert_eq(flow.participants.size(), 4)
assert_true(flow.watchers.has(late.handle))
assert_false(flow.entity_of.has(late.handle), "a watcher has no player of their own")
var watched: int = receivers[late_index].own_id
assert_true(flow.handle_of.has(watched), "the snapshot follows a player in the match")
assert_false(flow.sim.entities.find(watched).eliminated)
assert_true(receivers[late_index].own.is_empty(), "nobody else's inventory is sent")
assert_eq(joined.size(), 3)
assert_true(bool(joined[2]["watching"]))
assert_eq(net.player_count(), 3)
# Leaving while watching is tidy.
late.leave()
assert_true(_pump(func() -> bool: return left.size() == 1))
assert_false(flow.watchers.has(late.handle))
assert_false(flow.spectating.has(late.handle))
assert_false(game.sender.has_client(late.handle))
func test_more_people_than_the_server_holds_are_turned_away() -> void:
net.max_players = 2
_client("Mara")
_client("Odo")
assert_true(_pump(func() -> bool: return net.player_count() == 2))
var late: NetClient = _client("Late")
assert_true(_pump(func() -> bool: return late.state == NetClient.CLOSED))
assert_eq(late.close_reason, NetProtocol.REASON_FULL)
assert_eq(loop.match_flow.participants.size(), 4)
assert_eq(net.player_count(), 2)