# L2 Interlude SPP - запуск одной командой (Docker-вариант). # Использование: # powershell -ExecutionPolicy Bypass -File start.ps1 # поднять всё # powershell -ExecutionPolicy Bypass -File start.ps1 -Down # остановить # powershell -ExecutionPolicy Bypass -File start.ps1 -Reset # остановить и стереть базу (полный сброс) # powershell -ExecutionPolicy Bypass -File start.ps1 -Client "D:\Games\L2Interlude" # + запустить клиент param( [switch]$Down, [switch]$Reset, [string]$Client = "" ) $ErrorActionPreference = "Stop" $Base = $PSScriptRoot $ServerDir = Join-Path $Base "server" $Zip = Join-Path $Base "server_interlude.zip" $Compose = Join-Path $ServerDir "docker\docker-compose.yml" function Compose { docker compose -f $Compose @args } # --- Docker есть? --- try { docker info *>$null } catch { Write-Host "Docker не запущен или не установлен. Поставь Docker Desktop и запусти его." -ForegroundColor Red exit 1 } # --- Остановка / сброс --- if ($Down -or $Reset) { if (Test-Path $Compose) { if ($Reset) { Compose down -v Write-Host "Остановлено, база стёрта. Следующий запуск начнёт с чистой базы (боты - со стартовых уровней)." -ForegroundColor Yellow } else { Compose down Write-Host "Остановлено. Прогресс ботов и персонажи сохранены." -ForegroundColor Green } } else { Write-Host "Сервер ещё не разворачивался, останавливать нечего." } exit 0 } # --- Распаковка сервера при первом запуске --- if (-not (Test-Path (Join-Path $ServerDir "game"))) { if (-not (Test-Path $Zip)) { Write-Host "Не найден $Zip" -ForegroundColor Red exit 1 } Write-Host "Распаковываю сервер (~700 МБ, минуту-другую)..." New-Item -ItemType Directory -Force -Path $ServerDir | Out-Null Expand-Archive -Path $Zip -DestinationPath $Base -Force # в архиве корневая папка server_interlude - переименуем в server if (Test-Path (Join-Path $Base "server_interlude\game")) { if (Test-Path $ServerDir) { Remove-Item $ServerDir -Recurse -Force } Rename-Item (Join-Path $Base "server_interlude") $ServerDir } } # --- Docker-файлы внутрь папки сервера --- if (-not (Test-Path $Compose)) { Copy-Item -Recurse -Force (Join-Path $Base "docker") (Join-Path $ServerDir "docker") } # --- Поднимаем --- Write-Host "Собираю и запускаю контейнеры (первый раз - несколько минут)..." Compose up --build -d # --- Ждём готовности гейм-сервера --- Write-Host "Жду старта гейм-сервера (загрузка геодаты ~1 мин)..." $deadline = (Get-Date).AddMinutes(10) $ready = $false while ((Get-Date) -lt $deadline) { Start-Sleep -Seconds 5 $logs = Compose logs game --tail 100 2>$null | Out-String if ($logs -match "Registered on login") { $ready = $true; break } if ($logs -match "OutOfMemoryError") { Write-Host "Гейм-серверу не хватило памяти. Docker Desktop -> Settings -> Resources: дай WSL2 минимум 6 ГБ RAM." -ForegroundColor Red exit 1 } } if ($ready) { Write-Host "" Write-Host "=== Сервер готов ===" -ForegroundColor Green Write-Host "Логин-сервер: 127.0.0.1:2106" Write-Host "В клиенте: system\l2.ini -> ServerAddr=127.0.0.1, запускать system\l2.exe" Write-Host "Аккаунт: любые логин/пароль на экране входа - создастся сам." Write-Host "" Write-Host "Админка (после первого входа в игру):" Write-Host " docker compose -f `"$Compose`" exec db mariadb -uroot -pl2j l2jmobiusinterlude -e `"UPDATE accounts SET accessLevel=100 WHERE login='ЛОГИН'`"" -ForegroundColor DarkGray Write-Host "Логи: docker compose -f `"$Compose`" logs -f game" Write-Host "Стоп: powershell -File start.ps1 -Down" } else { Write-Host "Гейм-сервер не отрапортовал готовность за 10 минут. Смотри логи:" -ForegroundColor Red Write-Host " docker compose -f `"$Compose`" logs game --tail 50" exit 1 } # --- Клиент --- if ($Client -ne "") { $l2exe = Join-Path $Client "system\l2.exe" if (Test-Path $l2exe) { Write-Host "Запускаю клиент..." Start-Process -FilePath $l2exe -WorkingDirectory (Join-Path $Client "system") } else { Write-Host "Не нашёл $l2exe - проверь путь к клиенту." -ForegroundColor Yellow } }