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:
+68
-1
@@ -199,17 +199,23 @@ func test_leaving_during_results_and_joining_during_a_match() -> void:
|
||||
m.join(1)
|
||||
m.join(2)
|
||||
_until(m, Match.DROP)
|
||||
assert_true(m.join(3), "a late joiner waits for the next match")
|
||||
assert_false(m.join(3), "nobody joins a match under way")
|
||||
assert_true(m.watch(3), "a late arrival watches and waits for the next match")
|
||||
assert_false(m.watch(3), "once")
|
||||
assert_false(m.watch(1), "a participant isn't a watcher")
|
||||
assert_false(m.entity_of.has(3))
|
||||
assert_true(m.spectate_target(3) in [1, 2], "they watch someone still standing")
|
||||
assert_false(m.submit_command(3, PlayerCommand.new()))
|
||||
_eliminate(m, 2)
|
||||
m.step()
|
||||
assert_eq(m.phase, Match.RESULTS)
|
||||
assert_eq(m.winners, [1] as Array[int], "the late joiner isn't in this match")
|
||||
assert_eq(m.spectate_target(3), 1, "during results they watch the winner")
|
||||
m.leave(1)
|
||||
assert_eq(m.winners, [1] as Array[int], "leaving during results keeps the result")
|
||||
_until(m, Match.LOBBY)
|
||||
assert_eq(m.participants, [2, 3] as Array[int])
|
||||
assert_eq(m.watchers.size(), 0)
|
||||
_until(m, Match.DROP)
|
||||
assert_true(m.entity_of.has(3), "the late joiner plays the next match")
|
||||
|
||||
@@ -263,3 +269,64 @@ func test_ten_matches_in_a_row_start_clean() -> void:
|
||||
assert_eq(m.entity_of.size(), 0)
|
||||
assert_eq(seeds.size(), 10, "every match gets its own island")
|
||||
assert_eq(m.match_seed(0), SEED, "the first match uses the server's seed")
|
||||
|
||||
|
||||
func test_watch_is_only_for_a_match_under_way() -> void:
|
||||
var m: Match = Match.new(SEED, _rules())
|
||||
assert_false(m.watch(5), "in the lobby, people join")
|
||||
m.join(1)
|
||||
_until(m, Match.COUNTDOWN)
|
||||
assert_false(m.watch(5), "the countdown still takes people")
|
||||
assert_true(m.join(5))
|
||||
|
||||
|
||||
func test_bots_backfill_around_people_joining_and_leaving_in_the_lobby() -> void:
|
||||
var rules: MatchRules = _rules(6)
|
||||
rules.min_players = 2
|
||||
rules.lobby_ticks = 50
|
||||
var m: Match = Match.new(SEED, rules)
|
||||
m.join(1)
|
||||
m.join(2)
|
||||
m.join(3)
|
||||
_steps(m, 5)
|
||||
m.leave(2)
|
||||
m.join(4)
|
||||
m.leave(1)
|
||||
m.join(5)
|
||||
m.join(6)
|
||||
assert_eq(m.phase, Match.LOBBY)
|
||||
assert_eq(m.bot_handles.size(), 0, "no bots are added while people come and go")
|
||||
_until(m, Match.DROP)
|
||||
var people: Array[int] = []
|
||||
for handle: int in m.participants:
|
||||
if not m.bot_handles.has(handle):
|
||||
people.append(handle)
|
||||
people.sort()
|
||||
assert_eq(people, [3, 4, 5, 6] as Array[int], "everyone still here has a place")
|
||||
assert_eq(m.bot_handles.size(), 2, "bots fill exactly the places left")
|
||||
assert_eq(m.participants.size(), 6)
|
||||
for handle: int in people:
|
||||
assert_true(m.entity_of.has(handle))
|
||||
|
||||
|
||||
func test_watchers_take_places_ahead_of_bots_in_the_next_match() -> void:
|
||||
var m: Match = Match.new(SEED, _rules(4))
|
||||
m.join(1)
|
||||
_until(m, Match.DROP)
|
||||
assert_eq(m.bot_handles.size(), 3)
|
||||
for handle: int in [7, 8, 9]:
|
||||
assert_true(m.watch(handle))
|
||||
m.leave(8)
|
||||
assert_false(m.watchers.has(8))
|
||||
for handle: int in m.participants.duplicate():
|
||||
if handle != 1:
|
||||
_eliminate(m, handle)
|
||||
m.step()
|
||||
assert_eq(m.phase, Match.RESULTS)
|
||||
_until(m, Match.LOBBY)
|
||||
assert_true(_saw(m, "joined"))
|
||||
assert_eq(m.participants, [1, 7, 9] as Array[int], "watchers take places, bots are gone")
|
||||
_until(m, Match.DROP)
|
||||
assert_eq(m.bot_handles.size(), 1, "one bot fills the one empty place")
|
||||
for handle: int in [1, 7, 9]:
|
||||
assert_true(m.entity_of.has(handle))
|
||||
|
||||
Reference in New Issue
Block a user