From af35ec3a8f8bfbf8f637c01a3ed1cf213ee8f1ec Mon Sep 17 00:00:00 2001 From: ineedbots Date: Sun, 24 Oct 2021 02:17:14 -0600 Subject: [PATCH] Update to use findstr --- z_server_pvbrust_watchdog.bat | 14 +++++++++++--- z_server_pvbvote_watchdog.bat | 14 +++++++++++--- z_server_watchdog.bat | 16 ++++++++++++---- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/z_server_pvbrust_watchdog.bat b/z_server_pvbrust_watchdog.bat index c896dff..92140a6 100644 --- a/z_server_pvbrust_watchdog.bat +++ b/z_server_pvbrust_watchdog.bat @@ -1,6 +1,10 @@ @echo off -::Name of the server's title -set name=Bot Warfare Players vs bots 24/7 Rust 10x +::Name +set name=IW4x Bot Warfare PvB Rust +::Exe of the server +set server_exe=iw4x.exe +::The regex search for the window name of the server +set server_title_regex=Bot Warfare Players vs bots 24/7 Rust 10x ::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% ::Rate to check if server is hung @@ -25,6 +29,10 @@ for /f "delims=" %%i in ('"forfiles /p "%log_path%" /m "%log_file%" /c "cmd /c e if "%modif_time_temp%" == "%modif_time%" ( echo "(%date%) - (%time%) WARNING: %name% server hung, killing server..." - taskkill /FI "WINDOWTITLE eq %name%" /F + ::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_pvbvote_watchdog.bat b/z_server_pvbvote_watchdog.bat index b1f9042..d0d58b8 100644 --- a/z_server_pvbvote_watchdog.bat +++ b/z_server_pvbvote_watchdog.bat @@ -1,6 +1,10 @@ @echo off -::Name of the server's title -set name=Bot Warfare Players vs bots Mapvote 10x +::Name +set name=IW4x Bot Warfare PvB Vote +::Exe of the server +set server_exe=iw4x.exe +::The regex search for the window name of the server +set server_title_regex=Bot Warfare Players vs bots Mapvote 10x ::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% ::Rate to check if server is hung @@ -25,6 +29,10 @@ for /f "delims=" %%i in ('"forfiles /p "%log_path%" /m "%log_file%" /c "cmd /c e if "%modif_time_temp%" == "%modif_time%" ( echo "(%date%) - (%time%) WARNING: %name% server hung, killing server..." - taskkill /FI "WINDOWTITLE eq %name%" /F + ::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_watchdog.bat b/z_server_watchdog.bat index bf2d268..89c5508 100644 --- a/z_server_watchdog.bat +++ b/z_server_watchdog.bat @@ -1,10 +1,14 @@ @echo off -::Name of the server's title -set name=Bot Warfare 24/7 Rust 10x +::Name +set name=IW4x Bot Warfare Server +::Exe of the server +set server_exe=iw4x.exe +::The regex search for the window name of the server +set server_title_regex=Bot Warfare 24/7 Rust 10x ::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% ::Rate to check if server is hung -set check_rate=300 +set check_rate=3 ::Server log location set log_path=%gamepath%\userraw\logs\server set log_file=games_mp.log @@ -25,6 +29,10 @@ for /f "delims=" %%i in ('"forfiles /p "%log_path%" /m "%log_file%" /c "cmd /c e if "%modif_time_temp%" == "%modif_time%" ( echo "(%date%) - (%time%) WARNING: %name% server hung, killing server..." - taskkill /FI "WINDOWTITLE eq %name%" /F + ::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