#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

# Read default server URL from server.conf if present
SERVER=""
if [ -f "$SCRIPT_DIR/server.conf" ]; then
    SERVER=$(cat "$SCRIPT_DIR/server.conf" | tr -d '[:space:]')
fi

# Command-line arg overrides
SERVER="${1:-$SERVER}"

# Final fallback
SERVER="${SERVER:-http://localhost:5000}"

# Clear macOS Gatekeeper quarantine flag
xattr -cr "$SCRIPT_DIR/Skirmish.Client.Terminal" 2>/dev/null
chmod +x "$SCRIPT_DIR/Skirmish.Client.Terminal"

echo "[Skirmish] Connecting to $SERVER"
"$SCRIPT_DIR/Skirmish.Client.Terminal" "$SERVER"
