Add 'scripts/admin.sh'
parent
e8de1d62c1
commit
a50b2e573f
@ -0,0 +1,180 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
COMMAND="${1:-}"
|
||||||
|
|
||||||
|
HERO_ID=""
|
||||||
|
TOWN_ID=""
|
||||||
|
LEVEL=""
|
||||||
|
GOLD=""
|
||||||
|
HP=""
|
||||||
|
LIMIT=20
|
||||||
|
OFFSET=0
|
||||||
|
N=""
|
||||||
|
|
||||||
|
BASE_URL="${ADMIN_BASE_URL:-http://localhost:8080}"
|
||||||
|
USERNAME="${ADMIN_BASIC_AUTH_USERNAME:-}"
|
||||||
|
PASSWORD="${ADMIN_BASIC_AUTH_PASSWORD:-}"
|
||||||
|
|
||||||
|
shift || true
|
||||||
|
|
||||||
|
# --- parse args ---
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
--hero-id) HERO_ID="$2"; shift 2 ;;
|
||||||
|
--town-id) TOWN_ID="$2"; shift 2 ;;
|
||||||
|
--level) LEVEL="$2"; shift 2 ;;
|
||||||
|
--gold) GOLD="$2"; shift 2 ;;
|
||||||
|
--hp) HP="$2"; shift 2 ;;
|
||||||
|
--limit) LIMIT="$2"; shift 2 ;;
|
||||||
|
--offset) OFFSET="$2"; shift 2 ;;
|
||||||
|
--n) N="$2"; shift 2 ;;
|
||||||
|
--base-url) BASE_URL="$2"; shift 2 ;;
|
||||||
|
--username) USERNAME="$2"; shift 2 ;;
|
||||||
|
--password) PASSWORD="$2"; shift 2 ;;
|
||||||
|
*) echo "Unknown arg: $1"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z "$USERNAME" || -z "$PASSWORD" ]]; then
|
||||||
|
echo "Missing admin credentials. Set ADMIN_BASIC_AUTH_USERNAME and ADMIN_BASIC_AUTH_PASSWORD."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
require_value() {
|
||||||
|
local name="$1"
|
||||||
|
local value="$2"
|
||||||
|
if [[ -z "$value" ]]; then
|
||||||
|
echo "Parameter --$name is required for '$COMMAND'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
request() {
|
||||||
|
local method="$1"
|
||||||
|
local path="$2"
|
||||||
|
local body="${3:-}"
|
||||||
|
|
||||||
|
local url="${BASE_URL%/}${path}"
|
||||||
|
|
||||||
|
if [[ -n "$body" ]]; then
|
||||||
|
curl -sS -X "$method" "$url" \
|
||||||
|
-u "$USERNAME:$PASSWORD" \
|
||||||
|
-H "Accept: application/json" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$body" | jq .
|
||||||
|
else
|
||||||
|
curl -sS -X "$method" "$url" \
|
||||||
|
-u "$USERNAME:$PASSWORD" \
|
||||||
|
-H "Accept: application/json" | jq .
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$COMMAND" in
|
||||||
|
info)
|
||||||
|
request GET "/admin/info"
|
||||||
|
;;
|
||||||
|
|
||||||
|
heroes)
|
||||||
|
request GET "/admin/heroes?limit=$LIMIT&offset=$OFFSET"
|
||||||
|
;;
|
||||||
|
|
||||||
|
hero)
|
||||||
|
require_value "hero-id" "$HERO_ID"
|
||||||
|
request GET "/admin/heroes/$HERO_ID"
|
||||||
|
;;
|
||||||
|
|
||||||
|
set-level)
|
||||||
|
require_value "hero-id" "$HERO_ID"
|
||||||
|
require_value "level" "$LEVEL"
|
||||||
|
request POST "/admin/heroes/$HERO_ID/set-level" \
|
||||||
|
"{\"level\": $LEVEL}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
set-gold)
|
||||||
|
require_value "hero-id" "$HERO_ID"
|
||||||
|
require_value "gold" "$GOLD"
|
||||||
|
request POST "/admin/heroes/$HERO_ID/set-gold" \
|
||||||
|
"{\"gold\": $GOLD}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
set-hp)
|
||||||
|
require_value "hero-id" "$HERO_ID"
|
||||||
|
require_value "hp" "$HP"
|
||||||
|
request POST "/admin/heroes/$HERO_ID/set-hp" \
|
||||||
|
"{\"hp\": $HP}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
revive)
|
||||||
|
require_value "hero-id" "$HERO_ID"
|
||||||
|
request POST "/admin/heroes/$HERO_ID/revive" "{}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
reset)
|
||||||
|
require_value "hero-id" "$HERO_ID"
|
||||||
|
request POST "/admin/heroes/$HERO_ID/reset" "{}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
reset-buffs)
|
||||||
|
require_value "hero-id" "$HERO_ID"
|
||||||
|
request POST "/admin/heroes/$HERO_ID/reset-buff-charges" "{}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
add-potions)
|
||||||
|
require_value "hero-id" "$HERO_ID"
|
||||||
|
require_value "n" "$N"
|
||||||
|
request POST "/admin/heroes/$HERO_ID/add-potions" \
|
||||||
|
"{\"potions\": $N}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
delete)
|
||||||
|
require_value "hero-id" "$HERO_ID"
|
||||||
|
request DELETE "/admin/heroes/$HERO_ID"
|
||||||
|
;;
|
||||||
|
|
||||||
|
engine-status)
|
||||||
|
request GET "/admin/engine/status"
|
||||||
|
;;
|
||||||
|
|
||||||
|
engine-combats)
|
||||||
|
request GET "/admin/engine/combats"
|
||||||
|
;;
|
||||||
|
|
||||||
|
ws-connections)
|
||||||
|
request GET "/admin/ws/connections"
|
||||||
|
;;
|
||||||
|
|
||||||
|
towns)
|
||||||
|
request GET "/admin/towns"
|
||||||
|
;;
|
||||||
|
|
||||||
|
start-adventure)
|
||||||
|
require_value "hero-id" "$HERO_ID"
|
||||||
|
request POST "/admin/heroes/$HERO_ID/start-adventure" "{}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
teleport-town)
|
||||||
|
require_value "hero-id" "$HERO_ID"
|
||||||
|
require_value "town-id" "$TOWN_ID"
|
||||||
|
request POST "/admin/heroes/$HERO_ID/teleport-town" \
|
||||||
|
"{\"townId\": $TOWN_ID}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
start-rest)
|
||||||
|
require_value "hero-id" "$HERO_ID"
|
||||||
|
request POST "/admin/heroes/$HERO_ID/start-rest" "{}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
time-pause)
|
||||||
|
request POST "/admin/time/pause" "{}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
time-resume)
|
||||||
|
request POST "/admin/time/resume" "{}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Unsupported command: $COMMAND"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
Loading…
Reference in New Issue