Skip to content

Instantly share code, notes, and snippets.

@marchershey
Created May 22, 2020 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marchershey/e34416f3480c19bc3fa81b48b92b7f89 to your computer and use it in GitHub Desktop.
Save marchershey/e34416f3480c19bc3fa81b48b92b7f89 to your computer and use it in GitHub Desktop.
@echo off
setlocal enableextensions enabledelayedexpansion
:: ------------------------------------------------
:: Variables
:: ------------------------------------------------
SET Title=Prison Island Server
SET SteamLogin=bdzserver BDZserver123
SET DayZBranch=223350
SET ServerExe=DayZServer_x64.exe
SET DZSAExe=DZSALModServer.exe
SET DayZServerPath=%cd%
SET Mods=-mod=@CF,
SET DayZParams=-instanceId=001 -config=serverDZ.cfg -profiles=cache -bePath=%cd%\battleye -port=2302 -cpuCount=4 -limitFPS=100 -noFilePatching -dologs -adminlog -freezecheck
SET SteamCMDPath="%cd%/steamcmd"
SET looptime=10
SET #=
SET white=
SET error=
SET success=
SET warn=
SET info=
SET line=--------------------------------
Title %Title%
cd %DayZServerPath%
goto :init
:: ------------------------------------------------
:: Init
:: ------------------------------------------------
:init
call :showtitle
call :wait 1
echo %white%Initializing %Title%...
call :wait 1
echo.
goto :checkserver
tasklist /FI "IMAGENAME eq %ServerExe%" 2>NUL | find /I /N "%ServerExe%">NUL
if "%ERRORLEVEL%"=="0" (
:: server running
goto :checkserver
) else (
:: server is not running
echo %warn% Server is not online. Fixing...%#%
echo.
echo %line%
echo.
goto :updateserver
)
:: ------------------------------------------------
:: Server Check: check if the server is running
:: ------------------------------------------------
:checkserver
cls
call :showtitle
echo %white%Server status:%#%
tasklist /FI "IMAGENAME eq %ServerExe%" 2>NUL | find /I /N "%ServerExe%">NUL
if "%ERRORLEVEL%"=="0" (
:: server running
echo %success%Server is online. %white%[ %#%Last checked: !time:~0,8!%white% ]
echo.
goto :loop
) else (
:: server is not running
echo %warn%Server is not online. Fixing...
echo.
goto :updateserver
)
:: ------------------------------------------------
:: Server Restart: restart the server
:: ------------------------------------------------
:restartserver
cls
call :showtitle
echo %white%Stopping Server...
tasklist /FI "IMAGENAME eq %ServerExe%" 2>NUL | find /I /N "%ServerExe%">NUL
if "%ERRORLEVEL%"=="0" (
:: server running
echo %warn%Stopping existing server processes...%#%
echo.
echo %line%
taskkill /f /im %ServerExe%
taskkill /f /im %DZSAExe%
echo %line%
echo.
call :wait 1
echo %white% Completed. Waiting...
echo.
call :wait 5
goto :startserver
) else (
:: server is not running
goto :startserver
)
:: ------------------------------------------------
:: Server Start: start the server
:: ------------------------------------------------
:startserver
cls
call :showtitle
echo %white%Starting Server...
tasklist /FI "IMAGENAME eq %ServerExe%" 2>NUL | find /I /N "%ServerExe%">NUL
if "%ERRORLEVEL%"=="0" (
:: server running
goto :loop
) else (
:: server is not running
echo %warn%Executing %DZSAExe%... %#%
echo.
call :wait 1
echo %line%
echo SUCCESS: The process "%DZSAExe%" has been executed.
start /min %DZSAExe% %DayZParams%
echo %line%
call :wait 1
echo.
call :wait 1
echo %white% Completed. Checking status...
call :wait 10
echo.
goto :checkserver
)
:: ------------------------------------------------
:: Server Update: update the server
:: ------------------------------------------------
:updateserver
echo %warn%Updating Server...%#%
echo.
call :wait 1
echo %line%
%SteamCMDPath%\steamcmd.exe +login %SteamLogin% +force_install_dir %DayZServerPath% +"app_update %DayZBranch%" +quit
echo %line%
cls
call :showtitle
echo %warn%Fetching latest version from github...%#%
echo.
call :wait 1
echo %line%
git pull
echo %line%
call :wait 1
cls
call :showtitle
echo %warn%Clearing cache and other stuff...%#%
call :wait 1
echo %line%
DEL /f /s /q %cd%\cache
DEL /f /s /q %cd%\mpmissions\prisonisland.chernarusplus\storage_1\*
echo %line%
call :wait 1
echo %white% Completed. Waiting...
echo.
call :wait 1
goto :startserver
:: ------------------------------------------------
:: Check Loop: check the server every 30 seconds
:: ------------------------------------------------
:loop
echo %white%
CHOICE /T %looptime% /C CPR /D C /N /M "You can [C]heck status now, [P]ause, or [R]estart the server: "
if "%ERRORLEVEL%"=="1" goto :checkserver
if "%ERRORLEVEL%"=="2" pause & goto :checkserver
if "%ERRORLEVEL%"=="3" goto :looprestart
:looprestart
choice /C YN /M "Are you sure you want to restart the server?"
if %ERRORLEVEL%=="1" goto :restartserver
if %ERRORLEVEL%=="2" goto :loop
:: ------------------------------------------------
:: Functions
:: ------------------------------------------------
:wait
timeout /t %~1 > NUL
goto :eof
:showtitle
echo.
echo %white%%line%
echo %white%%Title%
echo %white%%line%
echo.
goto :eof
:: --------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment