Files
SirRoboGarage/tools/robocode_shim/make_botdir.sh
T
SirStone e6653199bb fix(shim): make the generated DrussGT bot dir runnable by hand
Running /tmp/tr_bots/DrussGT/DrussGT.sh manually failed with:
  BotException: Required bot property 'name' is missing.
The Tank Royale Java bot API reads bot identity from BOT_* environment
variables (EnvVars: BOT_NAME, BOT_VERSION, BOT_AUTHORS, BOT_DESCRIPTION,
BOT_HOMEPAGE, BOT_COUNTRY_CODES, BOT_GAME_TYPES, BOT_PLATFORM, BOT_PROG_LANG,
BOT_INITIAL_POS). When the TR booter launches the directory it supplies those,
derived from the .json - which is why every headless battle worked - but
launching the script directly supplies nothing, so the API rejects the
handshake.

make_botdir.sh now exports them in the generated <dir>.sh (kept in sync with
the .json it writes), so the script works standalone as well as under the
booter.

Verified against a server started for the test: before, the exact error above;
after, 'Connected to: ws://localhost:4599' and the server logs
'Bot joined: DrussGT 3.1.4159'.
2026-09-21 08:16:09 +02:00

61 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Generate a Tank Royale bot directory that boots the DrussGT bridge.
#
# tools/robocode_shim/make_botdir.sh [TARGET_DIR]
#
# The generated directory contains only text files (<dir>.json + <dir>.sh); the
# third-party jars stay outside the repo and are referenced by absolute path.
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TARGET="${1:-/tmp/tr_bots/DrussGT}"
NAME="$(basename "$TARGET")"
ROBOCODE_JAR="${ROBOCODE_JAR:-/tmp/robocode/install/libs/robocode.jar}"
TR_BOT_API_JAR="${TR_BOT_API_JAR:-$HOME/Downloads/sample-bots-java-1.0.2/lib/robocode-tankroyale-bot-api-1.0.2.jar}"
OUT="${OUT:-$HERE/out}"
mkdir -p "$TARGET"
cat > "$TARGET/$NAME.json" <<JSON
{
"name": "DrussGT",
"version": "3.1.4159",
"authors": ["Jacob"],
"description": "Real classic DrussGT running on Tank Royale via the robocode_shim bridge",
"homepage": "",
"countryCodes": ["se"],
"gameTypes": ["classic", "1v1"],
"platform": "JVM",
"programmingLang": "Java 8"
}
JSON
# The Tank Royale bot API reads bot identity from BOT_* environment variables.
# When the TR booter launches this directory it supplies them (derived from the
# .json above), but running this script BY HAND does not - and the API then
# rejects the handshake with "Required bot property 'name' is missing".
# Exporting them here makes the script work standalone as well.
cat > "$TARGET/$NAME.sh" <<SH
#!/bin/sh
cd "\$(dirname "\$0")"
# Bot identity - keep in sync with $NAME.json
export BOT_NAME="DrussGT"
export BOT_VERSION="3.1.4159"
export BOT_AUTHORS="Jacob"
export BOT_DESCRIPTION="Real classic DrussGT running on Tank Royale via the robocode_shim bridge"
export BOT_HOMEPAGE=""
export BOT_COUNTRY_CODES="se"
export BOT_GAME_TYPES="classic,1v1"
export BOT_PLATFORM="JVM"
export BOT_PROG_LANG="Java 8"
exec java -cp "$OUT:$ROBOCODE_JAR:$TR_BOT_API_JAR" robocode_shim.DrussGTBridge
SH
chmod +x "$TARGET/$NAME.sh"
echo "bot dir ready: $TARGET"
echo " $TARGET/$NAME.json"
echo " $TARGET/$NAME.sh"
echo " (classpath: $OUT:$ROBOCODE_JAR:$TR_BOT_API_JAR)"