get join-game logic working

This commit is contained in:
Travis Shears 2026-04-16 22:33:33 +02:00
parent 09bf48481a
commit 32ea10495e
Signed by: travisshears
GPG key ID: CB9BF1910F3F7469
3 changed files with 145 additions and 49 deletions

View file

@ -1,48 +1,61 @@
#!/bin/bash
# Simple UDP test script for the game server
# Sends registration and position updates to simulate two players
# Sends registration from two players on specific ports and receives responses
HOST="localhost"
PORT=9999
SERVER_PORT=9999
echo "Testing game server at $HOST:$PORT"
echo ""
echo "Testing game server at $HOST:$SERVER_PORT"
RESPONSE1=$(mktemp)
# RESPONSE2=$(mktemp)
# Helper to send UDP packet
send_udp() {
local msg="$1"
echo "Sending: $msg"
echo -n "$msg" | nc -u -w1 "$HOST" "$PORT"
}
echo "=== Listener on port 12345 ==="
nc -u -l 127.0.0.1 12345 > "$RESPONSE1" &
PID1=$!
sleep 3
echo "=== Registering Player 1 ==="
send_udp "REGISTER"
nc -u -l 0.0.0.0 12345
trap "rm -f $RESPONSE1 $RESPONSE2; jobs -p | xargs kill -9 2>/dev/null" EXIT
# echo ""
# # Create temp files for responses
# RESPONSE1=$(mktemp)
# RESPONSE2=$(mktemp)
# # Cleanup on exit
# trap "rm -f $RESPONSE1 $RESPONSE2; jobs -p | xargs kill -9 2>/dev/null" EXIT
# echo "=== Starting Player 1 listener on port 12345 ==="
# nc -u -l 127.0.0.1 12345 > "$RESPONSE1" 2>/dev/null &
# PID1=$!
# sleep 0.3
# echo "=== Starting Player 2 listener on port 12346 ==="
# nc -u -l 127.0.0.1 12346 > "$RESPONSE2" 2>/dev/null &
# PID2=$!
# sleep 0.3
# echo ""
# echo "=== Sending REGISTER from Player 1 (port 12345) ==="
# echo -n "REGISTER" | nc -u -w1 -p 12345 "$HOST" "$SERVER_PORT"
# sleep 0.5
# echo ""
# echo "=== Registering Player 2 ==="
# send_udp "register:2"
# sleep 0.5
# echo "=== Sending REGISTER from Player 2 (port 12346) ==="
# echo -n "REGISTER" | nc -u -w1 -p 12346 "$HOST" "$SERVER_PORT"
# sleep 1
# echo ""
# echo "=== Player 1 moving around ==="
# for i in {1..3}; do
# x=$((100 + i * 10))
# y=$((200 + i * 5))
# send_udp "1:$x:$y"
# sleep 0.3
# done
# echo "=== Stopping listeners ==="
# kill $PID1 $PID2 2>/dev/null
# sleep 0.2
# echo ""
# echo "=== Player 2 moving around ==="
# for i in {1..3}; do
# x=$((300 - i * 10))
# y=$((150 + i * 20))
# send_udp "2:$x:$y"
# sleep 0.3
# done
# echo "=== Results ==="
# echo "Player 1 response:"
# cat "$RESPONSE1"
# echo ""
# echo "Player 2 response:"
# cat "$RESPONSE2"
echo ""
# echo ""
echo "Done!"