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:
+13
-5
@@ -45,11 +45,18 @@ func poll() -> void:
|
||||
for event: Dictionary in net.events.duplicate():
|
||||
var handle: int = int(event.get("handle", 0))
|
||||
if event["type"] == "joined":
|
||||
if loop.match_flow.join(handle):
|
||||
# In the lobby they take a place; once a match is under way they watch it
|
||||
# and take a place in the next one.
|
||||
var watching: bool = false
|
||||
if not loop.match_flow.join(handle):
|
||||
watching = loop.match_flow.watch(handle)
|
||||
if loop.match_flow.participants.has(handle) or watching:
|
||||
adopt(handle)
|
||||
_send_match(handle)
|
||||
net.send(handle, NetProtocol.CHANNEL_CONTROL, world_notice(), true)
|
||||
events.append(event)
|
||||
var joined: Dictionary = event.duplicate()
|
||||
joined["watching"] = watching
|
||||
events.append(joined)
|
||||
else:
|
||||
net.kick(handle, NetProtocol.REASON_FULL)
|
||||
elif event["type"] == "left" and sender.has_client(handle):
|
||||
@@ -163,15 +170,16 @@ func match_notice() -> PackedByteArray:
|
||||
|
||||
|
||||
## The entity a participant is watching: their own player, the player they spectate
|
||||
## once eliminated, or 0 when they aren't in a match.
|
||||
## once eliminated (or, for someone who arrived mid-match, from the start), or 0 when
|
||||
## they aren't in a match.
|
||||
func viewer_of(handle: int) -> int:
|
||||
var flow: Match = loop.match_flow
|
||||
if flow.phase == Match.LOBBY or flow.phase == Match.COUNTDOWN or not flow.entity_of.has(handle):
|
||||
if flow.phase == Match.LOBBY or flow.phase == Match.COUNTDOWN:
|
||||
return 0
|
||||
var target: int = flow.spectate_target(handle)
|
||||
if target != 0 and flow.entity_of.has(target):
|
||||
return int(flow.entity_of[target])
|
||||
return int(flow.entity_of[handle])
|
||||
return int(flow.entity_of.get(handle, 0))
|
||||
|
||||
|
||||
## An OWN message for a participant if what they carry has changed since they were
|
||||
|
||||
Reference in New Issue
Block a user