Files

51 lines
1.5 KiB
Batchfile

@echo off
setlocal EnableExtensions EnableDelayedExpansion
cd /d "%~dp0"
echo.
echo ================================================================================
echo Commonwealth Online - Port 7777 in Use
echo ================================================================================
echo 1. Kill the process using TCP 7777 and restart
echo 2. Start the server on a different port
echo 3. Cancel
choice /C 123 /N /M "Select option (1-3): "
set choice=%errorlevel%
if %choice%==3 exit /b 0
if %choice%==2 goto change_port
set "PID="
for /f "tokens=5" %%A in ('netstat -aon ^| findstr /R /C:":7777 .*LISTENING"') do if not defined PID set "PID=%%A"
if not defined PID (
echo ERROR: Could not determine which process is using TCP 7777.
exit /b 1
)
echo Killing PID !PID!...
taskkill /PID !PID! /F >nul 2>&1 || (
echo ERROR: Could not kill PID !PID!. Try running as Administrator.
exit /b 1
)
timeout /t 2 /nobreak >nul
call start.bat
exit /b %ERRORLEVEL%
:change_port
set /p NEW_PORT="Enter desired port (1024-65535): "
for /f "delims=0123456789" %%A in ("!NEW_PORT!") do (
echo ERROR: Port must be numeric.
exit /b 1
)
if "!NEW_PORT!"=="" exit /b 1
if !NEW_PORT! lss 1024 (
echo ERROR: Port must be 1024 or higher.
exit /b 1
)
if !NEW_PORT! gtr 65535 (
echo ERROR: Port must be 65535 or lower.
exit /b 1
)
echo Starting on TCP/UDP !NEW_PORT!. This override does not rewrite commonwealth-server.json.
call start.bat --port !NEW_PORT!
exit /b %ERRORLEVEL%