get join-game logic working
This commit is contained in:
parent
09bf48481a
commit
32ea10495e
3 changed files with 145 additions and 49 deletions
77
backend/test-client.sh
Executable file
77
backend/test-client.sh
Executable file
|
|
@ -0,0 +1,77 @@
|
|||
#!/bin/bash
|
||||
|
||||
# UDP test client with interactive key controls
|
||||
# Connects to game server and displays responses
|
||||
|
||||
HOST="localhost"
|
||||
SERVER_PORT=9999
|
||||
LISTEN_PORT=12345
|
||||
|
||||
echo "=========================================="
|
||||
echo " Game Test Client"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
echo "Controls:"
|
||||
echo " 1 = REGISTER (join game)"
|
||||
echo " 2 = Send position update (100, 200)"
|
||||
echo " 3 = Send position update (300, 150)"
|
||||
echo " q = quit"
|
||||
echo ""
|
||||
echo "Listening for server responses on port $LISTEN_PORT..."
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
|
||||
# Create named pipe for responses
|
||||
RESPONSE_PIPE=$(mktemp -d)/response
|
||||
mkfifo "$RESPONSE_PIPE"
|
||||
|
||||
# Start UDP listener in background, output to FIFO
|
||||
nc -u -l 127.0.0.1 $LISTEN_PORT > "$RESPONSE_PIPE" 2>/dev/null &
|
||||
LISTENER_PID=$!
|
||||
|
||||
# Read responses in background and display them
|
||||
(while IFS= read -r line; do
|
||||
echo "[SERVER] $line"
|
||||
done < "$RESPONSE_PIPE") &
|
||||
READER_PID=$!
|
||||
|
||||
# Cleanup on exit
|
||||
cleanup() {
|
||||
kill $LISTENER_PID $READER_PID 2>/dev/null
|
||||
rm -rf "$(dirname "$RESPONSE_PIPE")"
|
||||
echo ""
|
||||
echo "Disconnected."
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Interactive input loop
|
||||
echo -n "> "
|
||||
while IFS= read -rsn1 key; do
|
||||
case "$key" in
|
||||
1)
|
||||
echo ""
|
||||
echo "[CLIENT] Sending: REGISTER"
|
||||
echo -n "REGISTER" | nc -u -w1 -p $LISTEN_PORT "$HOST" "$SERVER_PORT" 2>/dev/null
|
||||
echo -n "> "
|
||||
;;
|
||||
2)
|
||||
echo ""
|
||||
echo "[CLIENT] Sending: POS#100#200"
|
||||
echo -n "POS#100#200" | nc -u -w1 -p $LISTEN_PORT "$HOST" "$SERVER_PORT" 2>/dev/null
|
||||
echo -n "> "
|
||||
;;
|
||||
3)
|
||||
echo ""
|
||||
echo "[CLIENT] Sending: POS#300#150"
|
||||
echo -n "POS#300#150" | nc -u -w1 -p $LISTEN_PORT "$HOST" "$SERVER_PORT" 2>/dev/null
|
||||
echo -n "> "
|
||||
;;
|
||||
q|Q)
|
||||
echo ""
|
||||
break
|
||||
;;
|
||||
*)
|
||||
# Don't print anything for invalid keys, just show prompt again
|
||||
;;
|
||||
esac
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue