#!/usr/bin/env bash # Starts a real dedicated server and a real client as two processes, joins the client # to the server over loopback UDP with its autoplay script at the controls, and checks # it got from the lobby into the match and played. Both run headless and in real time, # so this takes about a minute: the lobby waits 20 s and counts down 10 s. # # tools/client_check.sh CLIENT_CHECK_PORT=N picks the UDP port (default 24677) set -euo pipefail repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" port="${CLIENT_CHECK_PORT:-24677}" out="$repo/build/client-check" mkdir -p "$out" nice -n 15 "$repo/tools/godot.sh" -- --server --listen --port="$port" --seed=41 --bots=3 --ticks=2100 >"$out/server.log" 2>&1 & server=$! trap 'kill "$server" 2>/dev/null || true' EXIT sleep 3 set +e nice -n 15 "$repo/tools/godot.sh" -- --connect="127.0.0.1:$port" --name=Mara --autoplay --client-seconds=55 >"$out/client.log" 2>&1 client_code=$? wait "$server" server_code=$? set -e trap - EXIT report="$(grep -m1 '"event":"client"' "$out/client.log" || true)" fail() { echo "client-check: $1" >&2 echo " client: ${report:-no report}" >&2 tail -n 5 "$out/server.log" >&2 exit 1 } [[ "$client_code" -eq 0 ]] || fail "the client exited with $client_code" [[ "$server_code" -eq 0 ]] || fail "the server exited with $server_code" [[ -n "$report" ]] || fail "the client said nothing" grep -q '"joined":true' <<<"$report" || fail "the client never joined" grep -q '"phases":\["lobby","countdown","drop"' <<<"$report" || fail "the client didn't follow the match from the lobby into the drop" grep -q '"bad_packets":0' <<<"$report" || fail "the client was sent packets it couldn't read" playing="$(sed -n 's/.*"frames_playing":\([0-9]*\).*/\1/p' <<<"$report")" [[ "${playing:-0}" -ge 300 ]] || fail "the client's player was in the match for only ${playing:-0} frames" grep -q '"event":"player_joined".*"name":"Mara"' "$out/server.log" || fail "the server never saw the client join" grep -q '"errors":0,"event":"stop"' "$out/server.log" || fail "the server logged errors" if grep -q 'SCRIPT ERROR' "$out/client.log"; then fail "the client logged script errors"; fi echo "client-check: ok (joined over UDP, lobby to drop, played $playing frames, no bad packets)" echo " $report"