@Echo off
title RW Windows Server Installer V4.0 - Java Updater By Yahgiggle
color 1b
echo ------------------------------------
echo -  RW Auto Server Installer v4.0   -
echo -           By Yahgiggle           -
echo -  Auto Update, Backup and reboot  -
echo ------------------------------------
setlocal enableDelayedExpansion

:timer
Echo server running cheak
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 "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
set "fullstamp=%YYYY%-%MM%-%DD%_%HH%:%Min%.%Sec%"

tasklist /fi "imagename eq rw_server.exe" |find ":" > nul
if not errorlevel 1 echo restarting the server %fullstamp%
if not errorlevel 1 echo restarted the server datetime - %fullstamp% >> %Serverdrive%:\%ServerFolder%\Server\report.txt
if not errorlevel 1 Start %Serverdrive%:\%ServerFolder%\Server\rw_server.exe

echo Auto update countdown started
timeout /t %Update% /NOBREAK 
goto updater
pause

:updater
echo Cheaking for updates and if server is running
%Serverdrive%:\%ServerFolder%\steamcmd\steamcmd.exe +login anonymous +force_install_dir %Serverdrive%:\%ServerFolder%\Server +app_update 339010 validate +quit
FC %Serverdrive%:\%ServerFolder%\Server\Version %Serverdrive%:\%ServerFolder%\Server\RWVersion\Version>nul 
if errorlevel 1 goto rebooter
goto timer
pause

:rebooter
echo rebooting server for update
timeout /t 3 /NOBREAK

taskkill /IM rw_server.exe /t /F
echo updating then booting the server back up
%Serverdrive%:\%ServerFolder%\steamcmd\steamcmd.exe +login anonymous +force_install_dir %Serverdrive%:\%ServerFolder%\Server +app_update 339010 validate +quit
timeout /t 3 /NOBREAK
cd/
%Serverdrive%:
cd %ServerFolder%\Server
COPY Version "%Serverdrive%:\%ServerFolder%\Server\RWVersion"
echo Server mismatch server was updated - %fullstamp% >> %Serverdrive%:\%ServerFolder%\Server\report.txt
goto timer
pause
