128 lines
3.3 KiB
Bash
128 lines
3.3 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
|
|
|
|
if [[ -f "$ENV_FILE" ]]; then
|
|
set -a
|
|
# shellcheck disable=SC1090
|
|
source "$ENV_FILE"
|
|
set +a
|
|
fi
|
|
|
|
REALM_ID="${ACORE_REALMLIST_ID:-1}"
|
|
REALM_NAME="${ACORE_REALMLIST_NAME:-MoonWell}"
|
|
REALM_PUBLIC_ADDRESS="${ACORE_REALMLIST_PUBLIC_ADDRESS:-127.0.0.1}"
|
|
REALM_LOCAL_ADDRESS="${ACORE_REALMLIST_LOCAL_ADDRESS:-127.0.0.1}"
|
|
REALM_LOCAL_SUBNET_MASK="${ACORE_REALMLIST_LOCAL_SUBNET_MASK:-255.255.255.0}"
|
|
REALM_PORT="${ACORE_REALMLIST_PORT:-${DOCKER_WORLD_EXTERNAL_PORT:-8085}}"
|
|
REALM_GAMEBUILD="${ACORE_REALMLIST_GAMEBUILD:-12340}"
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: $(basename "$0")
|
|
|
|
Synchronizes acore_auth.realmlist with values from .env.
|
|
EOF
|
|
}
|
|
|
|
log() {
|
|
printf '[sync-realmlist] %s\n' "$*"
|
|
}
|
|
|
|
require_integer() {
|
|
local name="$1"
|
|
local value="$2"
|
|
if ! [[ "$value" =~ ^[0-9]+$ ]]; then
|
|
printf '%s must be a positive integer, got: %s\n' "$name" "$value" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
sql_quote() {
|
|
local value="$1"
|
|
value="${value//\\/\\\\}"
|
|
value="${value//\'/\\\'}"
|
|
printf "'%s'" "$value"
|
|
}
|
|
|
|
if (($# > 0)); then
|
|
case "$1" in
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
printf 'Unknown option: %s\n\n' "$1" >&2
|
|
usage >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
require_integer "ACORE_REALMLIST_ID" "$REALM_ID"
|
|
require_integer "ACORE_REALMLIST_PORT" "$REALM_PORT"
|
|
require_integer "ACORE_REALMLIST_GAMEBUILD" "$REALM_GAMEBUILD"
|
|
|
|
if [[ -z "$REALM_NAME" || -z "$REALM_PUBLIC_ADDRESS" || -z "$REALM_LOCAL_ADDRESS" || -z "$REALM_LOCAL_SUBNET_MASK" ]]; then
|
|
printf 'realmlist values must not be empty\n' >&2
|
|
exit 1
|
|
fi
|
|
|
|
cd "$ROOT_DIR"
|
|
|
|
if ! docker compose ps --status running --services | grep -qx 'ac-database'; then
|
|
printf 'ac-database is not running. Start the server first with ./start-server.sh\n' >&2
|
|
exit 1
|
|
fi
|
|
|
|
SQL=$(cat <<EOF
|
|
INSERT INTO realmlist (id, name, address, localAddress, localSubnetMask, port, icon, flag, timezone, allowedSecurityLevel, population, gamebuild)
|
|
VALUES (
|
|
${REALM_ID},
|
|
$(sql_quote "$REALM_NAME"),
|
|
$(sql_quote "$REALM_PUBLIC_ADDRESS"),
|
|
$(sql_quote "$REALM_LOCAL_ADDRESS"),
|
|
$(sql_quote "$REALM_LOCAL_SUBNET_MASK"),
|
|
${REALM_PORT},
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
${REALM_GAMEBUILD}
|
|
)
|
|
ON DUPLICATE KEY UPDATE
|
|
name = VALUES(name),
|
|
address = VALUES(address),
|
|
localAddress = VALUES(localAddress),
|
|
localSubnetMask = VALUES(localSubnetMask),
|
|
port = VALUES(port),
|
|
icon = VALUES(icon),
|
|
flag = VALUES(flag),
|
|
timezone = VALUES(timezone),
|
|
allowedSecurityLevel = VALUES(allowedSecurityLevel),
|
|
population = VALUES(population),
|
|
gamebuild = VALUES(gamebuild);
|
|
|
|
SELECT id, name, address, localAddress, localSubnetMask, port, flag, gamebuild
|
|
FROM realmlist
|
|
WHERE id = ${REALM_ID};
|
|
EOF
|
|
)
|
|
|
|
log "syncing realm ${REALM_ID}: ${REALM_NAME} -> ${REALM_PUBLIC_ADDRESS}:${REALM_PORT}"
|
|
|
|
docker compose exec -T ac-database bash -lc 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" acore_auth' <<<"$SQL"
|
|
|
|
if docker compose ps --status running --services | grep -qx 'ac-authserver'; then
|
|
log "restarting authserver so it reloads realmlist"
|
|
docker compose restart ac-authserver >/dev/null
|
|
else
|
|
log "authserver is not running, skipped restart"
|
|
fi
|
|
|
|
log "realmlist synced"
|