From b17bdec320495d262ab7ac300e37a8ebafb39af4 Mon Sep 17 00:00:00 2001 From: ineed bots Date: Tue, 3 Jan 2023 15:20:41 -0600 Subject: [PATCH] more scripts --- .gitignore | 2 ++ z_server.bat | 9 ++++++--- z_server_updater.bat | 12 ++++++++++++ z_server_watchdog.bat | 43 +++++++++++++++++++++++++++++++++++++++++++ z_server_wine.sh | 18 +++++++++++++++++- 5 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 z_server_updater.bat create mode 100644 z_server_watchdog.bat diff --git a/.gitignore b/.gitignore index f899794..856c3c6 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ !/.gitattributes !/z_server.bat +!/z_server_updater.bat +!/z_server_watchdog.bat !/z_server_wine.sh !/README.md !/out diff --git a/z_server.bat b/z_server.bat index 402d52e..7abb181 100644 --- a/z_server.bat +++ b/z_server.bat @@ -13,10 +13,13 @@ set port=28968 set ip=0.0.0.0 ::Mod name (default "") set mod= -::Only change this when you don't want to keep the bat files in the game folder. MOST WON'T NEED TO EDIT THIS! -set gamepath=%cd% +:: current dir of this .bat file +SET mypath=%~dp0 +SET mypath=%mypath:~0,-1% +::Only change this when you don't want to keep the bat files in the game folder. MOST WON'T NEED TO EDIT THIS! %cd% +set gamepath=%mypath% ::Your plutonium install path (leave default!) -set pluto_path=%LOCALAPPDATA%\Plutonium +set pluto_path=%gamepath%\Plutonium :: Gamemode; oneof t4sp, t4mp, t5sp, t5mp, iw5mp, t6mp, t6zm set pluto_game_mode=t4mp :: Other things to send to cmd diff --git a/z_server_updater.bat b/z_server_updater.bat new file mode 100644 index 0000000..11725c5 --- /dev/null +++ b/z_server_updater.bat @@ -0,0 +1,12 @@ +@echo off +:: current dir of this .bat file +SET mypath=%~dp0 +SET mypath=%mypath:~0,-1% + +:: %cd% +set gamepath=%mypath% + +:: %LOCALAPPDATA%\Plutonium +set pluto_path=%gamepath%\Plutonium + +"%gamepath%\plutonium.exe" -install-dir "%pluto_path%" -update-only diff --git a/z_server_watchdog.bat b/z_server_watchdog.bat new file mode 100644 index 0000000..7e4f1a7 --- /dev/null +++ b/z_server_watchdog.bat @@ -0,0 +1,43 @@ +@echo off +::Name +set name=PT4MP Bot Warfare Server Watchdog +::Exe of the server +set server_exe=plutonium-bootstrapper-win32.exe +::The regex search for the window name of the server Windows 11 reports "N/A" as window name?? or is it Windows terminal?? +set server_title_regex=Plutonium r.* +:: current dir of this .bat file +SET mypath=%~dp0 +SET mypath=%mypath:~0,-1% +::Only change this when you don't want to keep the bat files in the game folder. MOST WON'T NEED TO EDIT THIS! %cd% +set gamepath=%mypath% +::Rate to check if server is hung +set check_rate=300 +::Server log location +set log_path=%gamepath%\Plutonium\storage\t4\main +set log_file=games_mp.log + +title Plutonium - %name% - Server watchdog +echo Visit plutonium.pw / Join the Discord (a6JM2Tv) for NEWS and Updates! +echo (%date%) - (%time%) %name% server watchdog start. + +::https://superuser.com/questions/699769/batch-file-last-modification-time-with-seconds +dir "%log_path%"\"%log_file%" > nul +for /f "delims=" %%i in ('"forfiles /p "%log_path%" /m "%log_file%" /c "cmd /c echo @ftime" "') do set modif_time_temp=%%i + +:Server + set modif_time=%modif_time_temp% + + timeout /t %check_rate% /nobreak > nul + + dir "%log_path%"\"%log_file%" > nul + for /f "delims=" %%i in ('"forfiles /p "%log_path%" /m "%log_file%" /c "cmd /c echo @ftime" "') do set modif_time_temp=%%i + + if "%modif_time_temp%" == "%modif_time%" ( + echo "(%date%) - (%time%) WARNING: %name% server hung, killing server..." + ::https://stackoverflow.com/questions/26552368/windows-batch-file-taskkill-if-window-title-contains-text + for /f "tokens=2 delims=," %%a in (' + tasklist /fi "imagename eq %server_exe%" /v /fo:csv /nh + ^| findstr /r /c:"%server_title_regex%" + ') do taskkill /pid %%a /f + ) +goto Server diff --git a/z_server_wine.sh b/z_server_wine.sh index 67d9396..3a967d7 100644 --- a/z_server_wine.sh +++ b/z_server_wine.sh @@ -21,7 +21,23 @@ export WINE_LOCATION="/home/deck/.var/app/net.lutris.Lutris/data/lutris/runners/ # which bat to execute export SERVER_BAT_LOCATION="./z_server.bat" +export SERVER_UPDATER_BAT_LOCATION="./z_server_updater.bat" +export SERVER_WATCHDOG_BAT_LOCATION="./z_server_watchdog.bat" + + +case "$1" in +server) export BAT_LOCATION=$SERVER_BAT_LOCATION + ;; +update) export BAT_LOCATION=$SERVER_UPDATER_BAT_LOCATION + ;; +watchdog) export BAT_LOCATION=$SERVER_WATCHDOG_BAT_LOCATION + ;; +*) export BAT_LOCATION=$SERVER_BAT_LOCATION + me=`basename "$0"` + echo "Usage: $me (server|update|watchdog)" + ;; +esac # exec it -$WINE_LOCATION $SERVER_BAT_LOCATION +$WINE_LOCATION $BAT_LOCATION