Files
tidewall/tools/discovery_check.sh
T
claudeandClaude Opus 5.5 f795ee3fa5 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>
2026-11-12 17:33:32 -05:00

56 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Starts a list server and a listening game server as real processes, then runs the
# client's --browse twice: once asking the LAN (loopback stands in for the broadcast
# address, which a sandbox may not route) and once asking the list server. Both must
# find the game server under its name and game port. About 15 seconds.
#
# tools/discovery_check.sh DISCOVERY_CHECK_PORT=N picks the game port (default 24687)
set -euo pipefail
repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
port="${DISCOVERY_CHECK_PORT:-24687}"
list_port=$((port + 10))
out="$repo/build/discovery-check"
mkdir -p "$out"
nice -n 15 "$repo/tools/godot.sh" -- --list-server --port="$list_port" --seconds=14 >"$out/list.log" 2>&1 &
list=$!
nice -n 15 "$repo/tools/godot.sh" -- --server --listen --port="$port" --seed=3 --bots=1 --ticks=360 \
--name="Discovery Check" --list="127.0.0.1:$list_port" >"$out/server.log" 2>&1 &
server=$!
trap 'kill "$list" "$server" 2>/dev/null || true' EXIT
sleep 4
set +e
nice -n 15 "$repo/tools/godot.sh" -- --browse --lan-target=127.0.0.1 --lan-port="$((port - 2))" --client-seconds=1.5 >"$out/lan.log" 2>&1
lan_code=$?
nice -n 15 "$repo/tools/godot.sh" -- --browse --lan-target=127.0.0.2 --list="127.0.0.1:$list_port" --client-seconds=1.5 >"$out/list-browse.log" 2>&1
list_code=$?
wait "$server"
server_code=$?
wait "$list"
list_server_code=$?
set -e
trap - EXIT
fail() {
echo "discovery-check: $1" >&2
for log in lan list-browse server list; do echo "--- $log" >&2; tail -n 3 "$out/$log.log" >&2; done
exit 1
}
[[ "$lan_code" -eq 0 && "$list_code" -eq 0 ]] || fail "a browse exited with $lan_code / $list_code"
[[ "$server_code" -eq 0 ]] || fail "the game server exited with $server_code"
[[ "$list_server_code" -eq 0 ]] || fail "the list server exited with $list_server_code"
lan="$(grep -m1 '"event":"servers"' "$out/lan.log" || true)"
listed="$(grep -m1 '"event":"servers"' "$out/list-browse.log" || true)"
grep -q "\"name\":\"Discovery Check\"" <<<"$lan" || fail "the LAN scan didn't find the server"
grep -q "\"port\":$port" <<<"$lan" || fail "the LAN scan didn't report the game port"
grep -q '"source":"lan"' <<<"$lan" || fail "the LAN answer wasn't marked as LAN"
grep -q "\"name\":\"Discovery Check\"" <<<"$listed" || fail "the list server didn't list the server"
grep -q '"source":"list"' <<<"$listed" || fail "the listed server wasn't marked as from the list"
grep -q '"servers":1' "$out/list.log" || fail "the list server never counted the registration"
grep -q '"errors":0,"event":"stop"' "$out/server.log" || fail "the game server logged errors"
if grep -q 'SCRIPT ERROR' "$out"/*.log; then fail "something logged script errors"; fi
echo "discovery-check: ok (found on the LAN and through the list server)"
echo " lan: $lan"
echo " list: $listed"