diff --git a/.env.example b/.env.example index 5e19129..4c40499 100644 --- a/.env.example +++ b/.env.example @@ -120,6 +120,11 @@ ACORE_REALMLIST_PORT=8085 # Обычно оставлять 0. ACORE_PLAYERBOTS_FORCE=0 +# 1 = импортировать дополнительный SQL для lua_scripts/MythicPlus, который не входит в обычный dbimport. +# Оставляйте 1, если используете папку lua_scripts/MythicPlus. +# Скрипт импортирует только отсутствующие таблицы и world-объекты, не перезатирая уже созданные данные. +ACORE_IMPORT_MYTHICPLUS_SQL=1 + # ------------------------------------------------------------------------------ # worldserver.conf: управляемые override-настройки # ------------------------------------------------------------------------------ diff --git a/import-custom-sql.sh b/import-custom-sql.sh new file mode 100644 index 0000000..8a00093 --- /dev/null +++ b/import-custom-sql.sh @@ -0,0 +1,141 @@ +#!/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 + +IMPORT_MYTHICPLUS_SQL="${ACORE_IMPORT_MYTHICPLUS_SQL:-1}" + +usage() { + cat <&2 + exit 1 + fi + + log "importing $(basename "$file_path") into ${database}" + docker compose exec -T ac-database bash -lc \ + "mysql -uroot -p\"\$MYSQL_ROOT_PASSWORD\" \"$database\"" < "$file_path" +} + +require_integer_flag() { + local name="$1" + local value="$2" + + if ! [[ "$value" =~ ^[01]$ ]]; then + printf '%s must be 0 or 1, got: %s\n' "$name" "$value" >&2 + exit 1 + fi +} + +maybe_import_table() { + local database="$1" + local table_name="$2" + local file_path="$3" + + if table_exists "$database" "$table_name"; then + log "table ${database}.${table_name} already exists, skipping" + return 0 + fi + + import_sql_file "$database" "$file_path" +} + +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_flag "ACORE_IMPORT_MYTHICPLUS_SQL" "$IMPORT_MYTHICPLUS_SQL" + +cd "$ROOT_DIR" + +if ! docker compose ps --status running --services | grep -qx 'ac-database'; then + printf 'ac-database is not running. Start the database first.\n' >&2 + exit 1 +fi + +if [[ "$IMPORT_MYTHICPLUS_SQL" == "0" ]]; then + log "MythicPlus SQL import disabled, skipped" + exit 0 +fi + +if [[ ! -d "$ROOT_DIR/sql/Mythic+" ]]; then + log "sql/Mythic+ directory not found, skipped" + exit 0 +fi + +maybe_import_table "acore_characters" "character_mythic_history" \ + "$ROOT_DIR/sql/Mythic+/characters/character_mythic_history.sql" +maybe_import_table "acore_characters" "character_mythic_keys" \ + "$ROOT_DIR/sql/Mythic+/characters/character_mythic_keys.sql" +maybe_import_table "acore_characters" "character_mythic_rating" \ + "$ROOT_DIR/sql/Mythic+/characters/character_mythic_rating.sql" +maybe_import_table "acore_characters" "character_mythic_vault" \ + "$ROOT_DIR/sql/Mythic+/characters/character_mythic_vault.sql" +maybe_import_table "acore_characters" "character_mythic_weekly_affixes" \ + "$ROOT_DIR/sql/Mythic+/characters/character_mythic_weekly_affixes.sql" + +maybe_import_table "acore_world" "world_mythic_loot" \ + "$ROOT_DIR/sql/Mythic+/world/world_mythic_loot.sql" +maybe_import_table "acore_world" "world_vault_loot" \ + "$ROOT_DIR/sql/Mythic+/world/world_vault_loot.sql" + +if [[ "$(mysql_query "acore_world" "SELECT COUNT(*) FROM creature_template WHERE entry = 900001;")" == "0" ]]; then + import_sql_file "acore_world" "$ROOT_DIR/sql/Mythic+/world/creature_and_keystones.sql" +else + log "MythicPlus creature bootstrap already exists, skipping" +fi + +log "custom SQL bootstrap completed" diff --git a/start-server.sh b/start-server.sh index 980842c..b70e331 100644 --- a/start-server.sh +++ b/start-server.sh @@ -189,6 +189,9 @@ fi log "running database import" run_one_shot_service "ac-db-import" "ac-db-import" +log "importing custom SQL" +bash "$ROOT_DIR/import-custom-sql.sh" + log "initializing client data" run_one_shot_service "ac-client-data-init" "ac-client-data-init"