- Add fix-port.bat to handle 'port already in use' errors - Detect blocking process and kill it, or prompt to use different port - Updated start.bat to detect startup failures and offer fix - Updated README.md with troubleshooting guide for port conflicts Users can now easily resolve port 7777 conflicts by running fix-port.bat or using --port override on the CLI. Co-authored-by: Cursor <cursoragent@cursor.com>
111 lines
2.5 KiB
Batchfile
111 lines
2.5 KiB
Batchfile
@echo off
|
|
setlocal enabledelayedexpansion
|
|
|
|
echo.
|
|
echo ================================================================================
|
|
echo Commonwealth Online - Port 7777 in Use
|
|
echo ================================================================================
|
|
echo.
|
|
echo Port 7777 is currently in use by another process.
|
|
echo.
|
|
echo Options:
|
|
echo 1. Kill the process using port 7777 and restart server
|
|
echo 2. Use a different port (you will be prompted to enter one)
|
|
echo 3. Cancel and exit
|
|
echo.
|
|
|
|
choice /C 123 /N /M "Select option (1-3): "
|
|
set choice=%errorlevel%
|
|
|
|
if %choice%==1 goto kill_process
|
|
if %choice%==2 goto change_port
|
|
if %choice%==3 goto exit_script
|
|
|
|
:kill_process
|
|
echo.
|
|
echo Finding process using port 7777...
|
|
for /f "tokens=5" %%a in ('netstat -aon ^| find ":7777"') do (
|
|
set PID=%%a
|
|
)
|
|
|
|
if defined PID (
|
|
echo Killing process with PID !PID!...
|
|
taskkill /PID !PID! /F >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo ERROR: Could not kill process. Try running this script as Administrator.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
echo Process killed successfully.
|
|
echo.
|
|
echo Waiting for port to be released...
|
|
timeout /t 2 /nobreak
|
|
echo.
|
|
echo Restarting server...
|
|
call start.bat
|
|
) else (
|
|
echo Could not determine which process is using port 7777.
|
|
echo Try:
|
|
echo - Restarting your computer
|
|
echo - Running as Administrator
|
|
echo - Or choose option 2 to use a different port
|
|
pause
|
|
exit /b 1
|
|
)
|
|
goto end
|
|
|
|
:change_port
|
|
echo.
|
|
set /p NEW_PORT="Enter desired port (1024-65535, default is 7777): "
|
|
|
|
if "!NEW_PORT!"=="" (
|
|
set NEW_PORT=7777
|
|
)
|
|
|
|
REM Validate port is a number between 1024 and 65535
|
|
for /f "delims=0123456789" %%A in ("!NEW_PORT!") do (
|
|
echo ERROR: Port must be a number.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
if !NEW_PORT! lss 1024 (
|
|
echo ERROR: Port must be 1024 or higher.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
if !NEW_PORT! gtr 65535 (
|
|
echo ERROR: Port must be 65535 or lower.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
echo.
|
|
echo Updating commonwealth-server.json to use port !NEW_PORT!...
|
|
|
|
REM Create new config with updated port
|
|
(
|
|
echo {
|
|
echo "host": "0.0.0.0",
|
|
echo "port": !NEW_PORT!,
|
|
echo "server_name": "Commonwealth Online Server",
|
|
echo "max_players": 16,
|
|
echo "log_verbosity": "info"
|
|
echo }
|
|
) > commonwealth-server.json
|
|
|
|
echo Config updated. Starting server on port !NEW_PORT!...
|
|
echo.
|
|
python consumer_server_cli.py serve --config commonwealth-server.json
|
|
|
|
goto end
|
|
|
|
:exit_script
|
|
echo.
|
|
echo Cancelled.
|
|
exit /b 0
|
|
|
|
:end
|
|
pause
|