|
@echo off |
|
|
|
rem ######################################################################### |
|
rem ################## # DEFINE VARS # ##################################### |
|
|
|
rem Save as zomboid_updatemods.bat or whatever you prefer and call from a scheduled task every 10 or so minutes |
|
rem Rcon needs to be local on the server since the script also reads a log file |
|
|
|
rem Path to start the PZ Server: usually StartServer65.bat |
|
set PZ_Start_DIR=D:\PATH\StartServer64.bat |
|
|
|
rem The rcon password and port |
|
set Rcon_Pwd=Password123 |
|
set Rcon_Port=27015 |
|
|
|
rem Location to directory containing rcon.exe from https://github.com/gorcon/rcon-cli |
|
set RconCMD_Dir=D:\rcon |
|
|
|
rem Location to directory containing *_DebugLog-server.txt |
|
set Zomboid_LogDir=C:\PATH\Zomboid\Logs |
|
|
|
rem TIME TO WAIT BETWEEN CHECKS |
|
set /A time_wait=600 |
|
|
|
rem ### LOGGING ### |
|
set "my_log_Dir=C:\PATH\Desktop\Project Zomboid" |
|
set "my_log_file=LOG_PZ_ModUpdate.txt" |
|
|
|
rem ######################################################################### |
|
rem ###################### SCRIPT EXECUTION ################################# |
|
|
|
for /f "delims=" %%i in ('%RconCMD_Dir%\rcon.exe -a 127.0.0.1:%Rcon_Port% -p %Rcon_Pwd% "checkModsNeedUpdate"') do set temp=%%i |
|
CALL :LOG RCON: %temp% |
|
set "temp=" |
|
|
|
rem Wait a little while to give the game some time to check. |
|
timeout /t 10 /nobreak |
|
|
|
for /F "delims=|" %%I IN ('DIR "%Zomboid_LogDir%\*DebugLog-server.txt" /B /A-D /O:D') DO SET "NewestFile=%%I" |
|
if defined NewestFile ( |
|
for /F "delims=" %%G IN ('findstr /C:"CheckModsNeedUpdate" "%Zomboid_LogDir%\%NewestFile%"') DO SET "LastOccur=%%G" |
|
) else ( |
|
CALL :LOG No log found. No update. |
|
) |
|
|
|
if defined LastOccur ( |
|
echo [%Date_Time%] - "%LastOccur%"|findstr /C:"CheckModsNeedUpdate: Mods updated." >nul |
|
if errorlevel 1 ( |
|
CALL :LOG Command output found and mods need to be updated. |
|
%RconCMD_Dir%\rcon.exe -a 127.0.0.1:%Rcon_Port% -p %Rcon_Pwd% "servermsg \"Mod Update Detected. Server will restart for mods in 5 minutes\"" |
|
CALL :LOG Warning 5 Minutes |
|
timeout /t 180 |
|
%RconCMD_Dir%\rcon.exe -a 127.0.0.1:%Rcon_Port% -p %Rcon_Pwd% "servermsg \"Mod Update Detected. Server will restart for mods in 2 minutes\"" |
|
CALL :LOG Warning 2 Minutes |
|
timeout /t 60 |
|
%RconCMD_Dir%\rcon.exe -a 127.0.0.1:%Rcon_Port% -p %Rcon_Pwd% "servermsg \"Mod Update Detected. Server will restart for mods in 1 minute\"" |
|
%RconCMD_Dir%\rcon.exe -a 127.0.0.1:%Rcon_Port% -p %Rcon_Pwd% "save" |
|
CALL :LOG Warning 1 Minute and Save |
|
timeout /t 30 /nobreak |
|
%RconCMD_Dir%\rcon.exe -a 127.0.0.1:%Rcon_Port% -p %Rcon_Pwd% "servermsg \"Mod Update Detected. Server will restart for mods in 30 seconds\"" |
|
CALL :LOG Warning 30 Seconds |
|
timeout /t 20 /nobreak |
|
%RconCMD_Dir%\rcon.exe -a 127.0.0.1:%Rcon_Port% -p %Rcon_Pwd% "servermsg \"Mod Update Detected. Server will restart for mods in 10 seconds\"" |
|
CALL :LOG Warning 10 Seconds |
|
timeout /t 10 /nobreak |
|
%RconCMD_Dir%\rcon.exe -a 127.0.0.1:%Rcon_Port% -p %Rcon_Pwd% "quit" |
|
CALL :LOG Server Shutdown |
|
timeout /t 60 /nobreak |
|
start %PZ_Start_DIR% |
|
CALL :LOG Server Startup |
|
timeout /t 120 /nobreak |
|
call %0 |
|
exit |
|
) else ( |
|
CALL :LOG Mods are up to date. |
|
) |
|
) else ( |
|
CALL :LOG Log found but no CheckModsNeedUpdate line found. Did rcon not send the command? |
|
) |
|
|
|
rem CALL :LOG Will check again in %time_wait% seconds... |
|
Timeout /t %time_wait% |
|
call %0 |
|
|
|
exit |
|
|
|
rem ######################################################################### |
|
rem ################## ## FUNCTIONS ## ##################################### |
|
|
|
rem ################## LOG WITH DATE_TIME ################################### |
|
REM Log function to output line in console + logfile with Current Timestamp |
|
REM Example: CALL :LOG "MESSAGE" |
|
|
|
:LOG |
|
rem ### DateTime Stuff |
|
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" |
|
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%" |
|
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%" |
|
set "Date_Time=%YYYY%%MM%%DD%_%HH%:%Min%:%Sec%" |
|
|
|
rem ### Output Stuff |
|
set "message=[%Date_Time%] - %*" |
|
echo %message% >> "%my_log_Dir%\%my_log_file%" |
|
echo %message% |
|
|
|
EXIT /B 0 |
|
rem ###################### |
|
|
|
|