@echo off
setlocal
cd /d "%~dp0"
title ButlersMansion Dedicated Server
echo Starting ButlersMansion dedicated server...
echo.
echo Logs: %~dp0ButlersMansionServer.log
echo PID:  %~dp0ButlersMansionServer.pid
echo.
echo Press Ctrl+C to stop. If the process remains, run Stop-ButlersMansionServer.cmd.
echo.
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$exe = Join-Path (Get-Location) 'ButlersMansionServer.exe'; $log = Join-Path (Get-Location) 'ButlersMansionServer.log'; $pidFile = Join-Path (Get-Location) 'ButlersMansionServer.pid'; $serverArgs = @('--server', '--headless', '--log-file', $log) + $args; $p = Start-Process -FilePath $exe -ArgumentList $serverArgs -PassThru; Set-Content -LiteralPath $pidFile -Value $p.Id; try { while (-not $p.HasExited) { Start-Sleep -Milliseconds 250; $p.Refresh() } } finally { if (-not $p.HasExited) { Stop-Process -Id $p.Id -Force -ErrorAction SilentlyContinue }; Remove-Item -LiteralPath $pidFile -Force -ErrorAction SilentlyContinue }; exit $p.ExitCode" %*
echo.
echo Server stopped.
pause
