#!/bin/bash
# Offline chat harness: real engine classes + real XML, no game server.
# Usage: tools/run_harness.sh [path/to/GameServer.jar]
# Needs JAVA_HOME with JDK 25 (or java/javac on PATH).
set -e
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
SRC="$ROOT/src_mobius/mobius/L2J_Mobius_CT_0_Interlude"
JAR="${1:-$ROOT/build/dist/libs/GameServer.jar}"
if [ ! -f "$JAR" ]; then
    echo "GameServer.jar not found: $JAR (build first: tools/build.sh)" >&2
    exit 1
fi
WORK="$(mktemp -d)"
mkdir -p "$WORK/data/xsd"
cp "$SRC"/dist/game/data/FakePlayer*.xml "$WORK/data/"
cp "$SRC"/dist/game/data/xsd/FakePlayer*.xsd "$WORK/data/xsd/"
JAVAC="${JAVA_HOME:+$JAVA_HOME/bin/}javac"
JAVA="${JAVA_HOME:+$JAVA_HOME/bin/}java"
"$JAVAC" -nowarn -d "$WORK" -cp "$JAR:$SRC/dist/libs/*" "$ROOT/tools/harness/ChatHarness.java"
cd "$WORK"
"$JAVA" -Dfile.encoding=UTF-8 -cp "$WORK:$JAR:$SRC/dist/libs/*" ChatHarness
STATUS=$?
rm -rf "$WORK"
exit $STATUS
