@echo off setlocal EnableExtensions DisableDelayedExpansion cd /d "%~dp0" set "CONFIG=%CD%\commonwealth-server.json" set "UPDATE=0" set "EXTRA_ARGS=" :parse if "%~1"=="" goto parsed if /I "%~1"=="--update-dependencies" ( set "UPDATE=1" shift goto parse ) if /I "%~1"=="--config" goto parse_config if /I "%~1"=="-c" goto parse_config if /I "%~1"=="--host" goto parse_host if /I "%~1"=="-H" goto parse_host if /I "%~1"=="--port" goto parse_port if /I "%~1"=="-p" goto parse_port if /I "%~1"=="--interactive" ( set "EXTRA_ARGS=%EXTRA_ARGS% --interactive" shift goto parse ) if /I "%~1"=="-i" ( set "EXTRA_ARGS=%EXTRA_ARGS% --interactive" shift goto parse ) if /I "%~x1"==".json" ( set "CONFIG=%~f1" shift goto parse ) echo ERROR: Unknown option or argument: %~1 1>&2 exit /b 1 :parse_config if "%~2"=="" ( echo ERROR: %~1 requires a config path. 1>&2 exit /b 1 ) set "CONFIG=%~f2" shift shift goto parse :parse_host if "%~2"=="" ( echo ERROR: %~1 requires a host. 1>&2 exit /b 1 ) set "EXTRA_ARGS=%EXTRA_ARGS% --host %~2" shift shift goto parse :parse_port if "%~2"=="" ( echo ERROR: %~1 requires a port. 1>&2 exit /b 1 ) set "EXTRA_ARGS=%EXTRA_ARGS% --port %~2" shift shift goto parse :parsed set "MODE=" set "SERVER_EXE=%CD%\CommonwealthOnline.Server.exe" set "SERVER_DLL=%CD%\CommonwealthOnline.Server.dll" set "SERVER_PROJECT=%CD%\CommonwealthOnline.Server.csproj" if exist "%SERVER_EXE%" set "MODE=apphost" if defined MODE goto resolved where dotnet >nul 2>nul if errorlevel 1 goto missing if exist "%SERVER_DLL%" ( set "MODE=dll" goto resolved ) if exist "%SERVER_PROJECT%" ( set "MODE=project" goto resolved ) :missing echo ERROR: CommonwealthOnline.Server is not published and the .NET 8 SDK/runtime is unavailable. 1>&2 exit /b 1 :resolved if "%UPDATE%"=="1" ( if not exist "%SERVER_PROJECT%" ( echo ERROR: --update-dependencies requires CommonwealthOnline.Server.csproj. 1>&2 exit /b 1 ) where dotnet >nul 2>nul || ( echo ERROR: --update-dependencies requires the .NET SDK. 1>&2 exit /b 1 ) dotnet restore "%SERVER_PROJECT%" || exit /b 1 ) if not exist "%CONFIG%" ( echo Generating default configuration: %CONFIG% call :run config init "%CONFIG%" || exit /b 1 ) echo Starting Commonwealth Online C# server call :run serve --config "%CONFIG%" %EXTRA_ARGS% exit /b %ERRORLEVEL% :run if /I "%MODE%"=="apphost" ( "%SERVER_EXE%" %* exit /b %ERRORLEVEL% ) if /I "%MODE%"=="dll" ( dotnet "%SERVER_DLL%" %* exit /b %ERRORLEVEL% ) dotnet run --project "%SERVER_PROJECT%" -c Release --no-launch-profile -- %* exit /b %ERRORLEVEL%