@echo Off
SET SatisfactoryServer_Directory=C:\Your\Satisfactory\Server\Directory
echo Master Server Handler will check for updates daily, start the Satisfactory Server, check for
echo unexpected self termination, and will restart the server automatically.
echo -
timeout 10 > nul
set "last_update_file=%SatisfactoryServer_Directory%\last_update.txt"
set "steamcmd_path=.\steamcmd.exe"
set "install_dir=%SatisfactoryServer_Directory%"
set "version_file=%SatisfactoryServer_Directory%\Engine\Binaries\Win64\FactoryServer-Win64-Shipping.version"
set "config_file=%SatisfactoryServer_Directory%\config.txt"
set "settings_ini=%SatisfactoryServer_Directory%\FactoryGame\Saved\Config\WindowsServer\GameUserSettings.ini"
set "temp_file=%SatisfactoryServer_Directory%\temp_config.ini"
set "temp_file2=%SatisfactoryServer_Directory%\temp_config.txt"
set "init_pause_off=mIntValues=(("FG.DSAutoPause", 0))"
set "init_pause_on=mIntValues=(("FG.DSAutoPause", 1))"
set "scripts=FactoryServer.exe"
set "found_build_id=0"
set "version_found=0"
set "say_once=0"
setlocal enabledelayedexpansion
if exist "%last_update_file%" (
set "version_found=1"
if not exist "%config_file%" (
echo Server configuration is missing or has been deleted. Please answer the config questions again.
)
)
if not exist "%config_file%" (
if not exist "%last_update_file%" (
echo This appears to be the first time running the server.
)
)
:: Check if config.txt exists
if not exist "%config_file%" (
timeout 5 /nobreak > nul
echo Do you want the Server Handler to automatically restart the server at midnight after updates have been downloaded?
:ask_restart
set /p restart_server="Type 'Yes' or 'No': "
:: Trim spaces from input
for /f "tokens=* delims= " %%a in ("!restart_server!") do set "restart_server=%%a"
:: Validate user input
if /i "!restart_server!" neq "Yes" if /i "!restart_server!" neq "No" (
echo Invalid input. Please type "Yes" or "No".
goto ask_restart
)
echo -
:: Ask user for custom port number or default
echo Would you like to set a custom Server Port or use the utterly stupid default 7777 Server Port?
echo If you are opening this server through your router to the public internet I highly advise against
echo using the default 7777 port.
:ask_port
set /p server_port="Type 'Default' for 7777 or type a custom Port number above 9000: "
:: Trim spaces from input
for /f "tokens=* delims= " %%a in ("!server_port!") do set "server_port=%%a"
:: Validate user input for port
if /i "!server_port!" equ "Default" (
set "server_port=7777"
) else (
rem Check if the input is a number and within the valid port range
for /f "delims=0123456789" %%a in ("!server_port!") do set "invalid_input=1"
if defined invalid_input (
echo Invalid input. Please enter 'Default' or a number between 9000 and 65535.
set "invalid_input="
goto ask_port
)
if !server_port! lss 9000 (
echo Invalid port. The port number must be greater than 9000.
goto ask_port
)
if !server_port! gtr 65535 (
echo Invalid port. The port number must be less than or equal to 65535.
goto ask_port
)
)
echo -
:: Ask if user wants to enable 24/7 game clock
echo By default, the server will pause gameplay when no players are connected.
echo Would you like to enable 24/7 game clock? The game will continue to run while no players are connected.
:ask_game_clock
set /p enable_game_clock="Type 'Yes' or 'No': "
:: Trim spaces from input and set variable
for /f "tokens=* delims= " %%a in ("%enable_game_clock%") do set "enable_game_clock=%%a"
:: Ensure no leading/trailing spaces and case-insensitive comparison
set "enable_game_clock=!enable_game_clock:~0,3!"
:: Check user input for valid values
if /i "!enable_game_clock!" neq "Yes" if /i "!enable_game_clock!" neq "No" (
echo Invalid input. Please type 'Yes' or 'No'.
goto ask_game_clock
)
echo -
:: Save user input to config.txt
echo RESTART_SERVER=!restart_server!> "%config_file%"
echo SERVER_PORT=!server_port!>> "%config_file%"
echo Configuration has been saved. You will not be asked these questions again. If you change your mind go to
echo your Satisfactory server directory and delete the 'config.txt' file, then restart this console.
timeout 10 /nobreak > nul
echo -
) else (
:: Read config from config.txt
for /f "tokens=2 delims==" %%a in ('findstr /B "RESTART_SERVER" "%config_file%"') do set "restart_server=%%a"
for /f "tokens=2 delims==" %%a in ('findstr /B "SERVER_PORT" "%config_file%"') do set "server_port=%%a"
)
echo Getting ready to start the server...
timeout 4 /nobreak > nul
:loop
:: Read the buildId from config
for /f "tokens=2 delims==" %%a in ('findstr /B "BUILD_ID" "%config_file%"') do set "last_build_id=%%a"
set "build_id=%last_build_id%"
:: Get today's date in YYYYMMDD format
for /f "tokens=2 delims==" %%a in ('wmic os get localdatetime /value') do set "current_date=%%a"
set "current_date=%current_date:~0,8%"
:: Check if the update file exists and read its content
if exist "%last_update_file%" (
set /p last_update=<%last_update_file%
) else (
echo Server version data does not exist. Creating it.
echo -
timeout 3 /nobreak > nul
echo 00000000 > "%last_update_file%"
set "last_update=00000000"
)
:: Only run the update if the date has changed
if "%current_date%" NEQ "%last_update%" (
set "say_once=0"
echo Checking for any server updates.
echo -
timeout 3 /nobreak > nul
"%steamcmd_path%" +force_install_dir "%install_dir%" +login anonymous +app_update 1690800 -beta public validate +quit
echo %current_date%>"%last_update_file%"
:: Extract BuildId from version file
for /f "tokens=2 delims=:" %%a in ('findstr /C:"BuildId" "%version_file%"') do (
set "line=%%a"
rem Remove leading spaces and trailing quotes
set "line=!line:~1!"
set "line=!line:"=!"
rem Store the BuildId value in a variable
set "build_id=!line!"
)
:: Write BuildID to the config
for /f "usebackq delims=" %%a in ("%config_file%") do (
set "line=%%a"
echo !line! | findstr /r "^BUILD_ID=[0-9]*" >nul
if not errorlevel 1 (
echo BUILD_ID=!build_id!>>"%temp_file2%"
set "found_build_id=1"
) else (
echo !line!>>"%temp_file2%"
)
)
if "!found_build_id!"=="0" (
echo BUILD_ID=!build_id!>>"%temp_file2%"
)
move /Y "%temp_file2%" "%config_file%"
echo BuildId: !build_id!
echo -
timeout 3 /nobreak > nul
)
if "!version_found!"=="1" (
if /i "!enable_game_clock!"=="Yes" (
echo Server configuration has been changed by the user.
timeout 3 /nobreak > nul
for %%i in (%scripts%) do (
set "script=%%i"
set "task=%%~ni"
rem Check if the script is running under cmd.exe
tasklist /FI "IMAGENAME eq FactoryServer.exe" /V | find /I "%%~ni" > nul
if not errorlevel 1 (
echo Stopping server to prepare for changes.
taskkill /F /IM FactoryServer-Win64-Shipping-Cmd.exe
timeout 3 /nobreak > nul
)
)
:: Create a temporary file to store the modified content
set "temp_file=%SatisfactoryServer_Directory%\temp_config.ini"
:: Ensure the temp file is empty before use
> "%temp_file%" echo.
:: Loop through each line in the settings .ini file
for /f "usebackq delims=" %%a in ("%settings_ini%") do (
set "line=%%a"
if "!line!"=="mIntValues=()" (
echo !init_pause_off!>>"%temp_file%"
) else (
if "!line!"=="mIntValues=(("FG.DSAutoPause", 1))" (
echo !init_pause_off!>>"%temp_file%"
) else (
echo !line!>>"%temp_file%"
)
)
)
echo User has enabled 24/7 game clock. Modifying server config.
timeout 2 /nobreak > nul
:: Replace original file with modified one
move /Y "%temp_file%" "%settings_ini%"
set "enable_game_clock="
echo Server config updated successfully.
timeout 2 /nobreak > nul
:: Extract BuildId from version file
for /f "tokens=2 delims=:" %%a in ('findstr /C:"BuildId" "%version_file%"') do (
set "line=%%a"
rem Remove leading spaces and trailing quotes
set "line=!line:~1!"
set "line=!line:"=!"
rem Store the BuildId value in a variable
set "build_id=!line!"
)
:: Write BuildID to the config
for /f "usebackq delims=" %%a in ("%config_file%") do (
set "line=%%a"
echo !line! | findstr /r "^BUILD_ID=[0-9]*" >nul
if not errorlevel 1 (
echo BUILD_ID=!build_id!>>"%temp_file2%"
set "found_build_id=1"
) else (
echo !line!>>"%temp_file2%"
)
)
if "!found_build_id!"=="0" (
echo BUILD_ID=!build_id!>>"%temp_file2%"
)
move /Y "%temp_file2%" "%config_file%"
)
if /i "!enable_game_clock!"=="No" (
echo Server configuration has been changed by the user.
timeout 3 /nobreak > nul
for %%i in (%scripts%) do (
set "script=%%i"
set "task=%%~ni"
rem Check if the script is running under cmd.exe
tasklist /FI "IMAGENAME eq FactoryServer.exe" /V | find /I "%%~ni" > nul
if not errorlevel 1 (
echo Stopping server to prepare for changes.
taskkill /F /IM FactoryServer-Win64-Shipping-Cmd.exe
timeout 3 /nobreak > nul
)
)
:: Create a temporary file to store the modified content
set "temp_file=%SatisfactoryServer_Directory%\temp_config.ini"
:: Ensure the temp file is empty before use
> "%temp_file%" echo.
:: Loop through each line in the settings .ini file
for /f "usebackq delims=" %%a in ("%settings_ini%") do (
set "line=%%a"
if "!line!"=="mIntValues=()" (
echo !init_pause_on!>>"%temp_file%"
) else (
if "!line!"=="mIntValues=(("FG.DSAutoPause", 0))" (
echo !init_pause_on!>>"%temp_file%"
) else (
echo !line!>>"%temp_file%"
)
)
)
:: Replace original file with modified one
move /Y "%temp_file%" "%settings_ini%"
set "enable_game_clock="
echo Server config updated successfully.
timeout 2 /nobreak > nul
:: Extract BuildId from version file
for /f "tokens=2 delims=:" %%a in ('findstr /C:"BuildId" "%version_file%"') do (
set "line=%%a"
rem Remove leading spaces and trailing quotes
set "line=!line:~1!"
set "line=!line:"=!"
rem Store the BuildId value in a variable
set "build_id=!line!"
)
:: Write BuildID to the config
for /f "usebackq delims=" %%a in ("%config_file%") do (
set "line=%%a"
echo !line! | findstr /r "^BUILD_ID=[0-9]*" >nul
if not errorlevel 1 (
echo BUILD_ID=!build_id!>>"%temp_file2%"
set "found_build_id=1"
) else (
echo !line!>>"%temp_file2%"
)
)
if "!found_build_id!"=="0" (
echo BUILD_ID=!build_id!>>"%temp_file2%"
)
move /Y "%temp_file2%" "%config_file%"
)
)
if "%say_once%"=="0" (
echo Checking server status...
timeout 2 /nobreak > nul
)
for %%i in (%scripts%) do (
set "script=%%i"
set "task=%%~ni"
rem Check if the script is running under cmd.exe
tasklist /FI "IMAGENAME eq FactoryServer.exe" /V | find /I "%%~ni" > nul
if errorlevel 1 (
echo %%i is not running. Starting %%i.
echo -
start "" "%SatisfactoryServer_Directory%\%%i" +Port=%server_port% +unattended
timeout 15 /nobreak > nul
if "!say_once!"=="1" (
echo -
echo Press any key to force the server to check for updates...
)
) else (
if "!say_once!"=="0" (
echo %%i is already running.
echo -
)
if "!restart_server!"=="Yes" (
if "!build_id!" NEQ "!last_build_id!" (
timeout 3 /nobreak > nul
echo New server version detected.
timeout 2 /nobreak > nul
echo Restarting FactoryServer.exe...
taskkill /F /IM FactoryServer-Win64-Shipping-Cmd.exe
timeout 5 /nobreak > nul
start "" "%SatisfactoryServer_Directory%\%%i" +Port=%server_port% +unattended
echo Starting server...
echo -
timeout 5 /nobreak > nul
)
)
)
)
:: Check if user wants to enable the 24/7 game clock
if /i "!enable_game_clock!"=="Yes" (
echo User has enabled 24/7 game clock. Modifying server config.
timeout 2 /nobreak > nul
:: Create a temporary file to store the modified content
set "temp_file=%SatisfactoryServer_Directory%\temp_config.ini"
:: Ensure the temp file is empty before use
> "%temp_file%" echo.
:: Loop through each line in the settings .ini file
for /f "usebackq delims=" %%a in ("%settings_ini%") do (
set "line=%%a"
if "!line!"=="mIntValues=()" (
echo !init_pause_off!>>"%temp_file%"
) else (
if "!line!"=="mIntValues=(("FG.DSAutoPause", 1))" (
echo !init_pause_off!>>"%temp_file%"
) else (
echo !line!>>"%temp_file%"
)
)
)
:: Replace original file with modified one
move /Y "%temp_file%" "%settings_ini%"
echo Server config updated successfully.
set "enable_game_clock="
timeout 3 /nobreak > nul
echo Restarting the server to apply 24/7 game clock...
taskkill /F /IM FactoryServer-Win64-Shipping-Cmd.exe
timeout 5 /nobreak > nul
start "" "%SatisfactoryServer_Directory%\FactoryServer.exe" +Port=%server_port% +unattended
echo Server started...
timeout 5 /nobreak > nul
echo -
echo -
echo Server Handler will now monitor the Satisfactory Server status.
echo -
timeout 3 /nobreak > nul
echo Press any key to force the server to check for updates...
set "say_once=1"
)
if "!say_once!"=="0" (
echo -
echo Server Handler will now monitor the Satisfactory Server status.
echo -
timeout 3 /nobreak > nul
echo Press any key to force the server to check for updates...
set "say_once=1"
)
timeout -t 30 |findstr "\<0\>" >nul && goto loop || echo 00000000 > "%last_update_file%"
goto loop