@echo off setlocal enabledelayedexpansion chcp 65001 >nul set SERVER_UPPER=SCENARIO set SERVER_LOWER=scenario set SERVER_HUMP=Scenario set /a SERVER_PORT=28880 set /a WEBSITE_PORT=%SERVER_PORT%-10000 set modifyTitle=1 for %%a in (%*) do ( if /i "%%a"=="/notitle" set modifyTitle=0 ) if %modifyTitle% equ 1 ( title %SERVER_HUMP% Quick Start ) :: ============================================= :: Validation :: ============================================= if not defined !SERVER_UPPER!_MAIN ( echo [ERROR] !SERVER_UPPER!_MAIN environment variable is not defined pause && exit /b 1 ) if not defined !SERVER_UPPER!_MANAGE_BIN ( echo [ERROR] !SERVER_UPPER!_MANAGE_BIN environment variable is not defined pause && exit /b 1 ) if not defined !SERVER_UPPER!_VM_PARAMS ( echo Warning: !SERVER_UPPER!_VM_PARAMS environment variable is not defined set %SERVER_UPPER%_VM_PARAMS=-Xms512m -Xmx2048m ) cd /d "!%SERVER_UPPER%_MAIN!" 2>nul if errorlevel 1 ( echo [ERROR] Directory not found: !%SERVER_UPPER%_MAIN! echo Please verify %SERVER_UPPER%_MAIN environment variable pause && exit /b 1 ) if not exist "!%SERVER_UPPER%_MANAGE_BIN!" ( echo [ERROR] Main JAR file not found: !%SERVER_UPPER%_MANAGE_BIN! echo Please verify %SERVER_UPPER%_MANAGE_BIN environment variable pause && exit /b 1 ) cd web 2>nul if errorlevel 1 ( echo [ERROR] web directory does not exist in !%SERVER_UPPER%_MAIN! pause && exit /b 1 ) if not exist "%SERVER_LOWER%-web.exe" ( echo [ERROR] %SERVER_LOWER%-web.exe does not exist in !%SERVER_UPPER%_MAIN!\web pause && exit /b 1 ) if not exist "conf\web.conf" ( echo [ERROR] conf\web.conf does not exist in !%SERVER_UPPER%_MAIN!\web pause && exit /b 1 ) :: ============================================= :: Service Launch :: ============================================= cd .. setlocal echo Starting %SERVER_HUMP% Server... jps -v | grep "\-Dserver.port=%SERVER_PORT%" | awk "{print $1}" >server.tmp set /p pid=nul if defined pid ( taskkill -f -pid !pid! ) start "%SERVER_HUMP% Server" /B cmd /c "chcp 65001 && java !%SERVER_UPPER%_VM_PARAMS! -jar !%SERVER_UPPER%_MANAGE_BIN!" echo Starting %SERVER_HUMP% Website... cd web set "tmp=tmp" cd dist && mkdir temp && cd %tmp% && cp ../wsUrl.js . sed -i "s/6680/18680/" wsUrl.js >nul sed -i "s/6681/18880/" wsUrl.js >nul sed -i "s/6682/18280/" wsUrl.js >nul sed -i "s/6683/18480/" wsUrl.js >nul cp wsUrl.js .. && cd .. && rm -rf %tmp% && cd "%~dp0/web" taskkill -f -im %SERVER_LOWER%-web.exe >nul start "%SERVER_HUMP% Website" /B cmd /c "%SERVER_LOWER%-web.exe -c conf\web.conf" set MAX_WAIT=300 set CHECK_INTERVAL=5 set counter=0 echo Waiting for services to start... echo. :CHECK_LOOP netstat -an | find ":%SERVER_PORT%" > nul set server_up=%errorlevel% netstat -an | find ":%WEBSITE_PORT%" > nul set website_up=%errorlevel% if !server_up! equ 0 if !website_up! equ 0 ( call :DISPLAY_SUCCESS exit /b 0 ) set /a counter+=CHECK_INTERVAL if !counter! geq %MAX_WAIT% ( echo Error: Services did not start within !counter! seconds exit /b 1 ) timeout /t %CHECK_INTERVAL% /nobreak > nul goto CHECK_LOOP :DISPLAY_SUCCESS :: ============================================= :: Status Display :: ============================================= echo. echo ======================================== echo %SERVER_HUMP% Services Successfully Started echo ======================================== echo - %SERVER_HUMP% Server (Port: %SERVER_PORT%) echo - %SERVER_HUMP% Website (Port: %WEBSITE_PORT%) echo ======================================== echo. endlocal exit /b 0