diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 1698b2cf7..ac8a0cd2f 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -4,12 +4,7 @@ source "/home/steam/server/helper_functions.sh" if [ "${RCON_ENABLED,,}" != true ]; then LogWarn "Unable to reboot. RCON is required." - exit 0 -fi - -if [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then - LogError "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is empty." - exit 0 + exit 1 fi if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then @@ -20,13 +15,18 @@ if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then fi fi -if [[ "${AUTO_REBOOT_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then - for ((i = "${AUTO_REBOOT_WARN_MINUTES}" ; i > 0 ; i--)); do - broadcast_command "The Server will reboot in ${i} minutes" - sleep "1m" - done - shutdown_server - exit 0 -fi - -LogError "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" \ No newline at end of file +countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "Server will reboot" +countdown_exit_code=$? +case "${countdown_exit_code}" in + 0 ) + shutdown_server + ;; + 1 ) + LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is empty" + exit 1 + ;; + 2 ) + LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}" + exit 1 + ;; +esac diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index ea8e5f214..8e5f36a03 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -85,8 +85,7 @@ get_players_list() { return_val=1 fi - # tail -n +2 removes the header "name,playeruid,steamid" - RCON "ShowPlayers" | tail -n +2 + RCON "ShowPlayers" return "$return_val" } @@ -202,3 +201,58 @@ shutdown_server() { fi return "$return_val" } + +# Given an amount of time in minutes and a message prefix +# Will skip countdown if no players are in the server, Will only check the mtime if there are players in the server +# Returns 0 on success +# Returns 1 if mtime is empty +# Returns 2 if mtime is not an integer +countdown_message() { + local mtime="$1" + local message_prefix="$2" + local return_val=0 + + # Only do countdown if there are players + if [ "$(get_player_count)" -gt 0 ]; then + if [[ "${mtime}" =~ ^[0-9]+$ ]]; then + for ((i = "${mtime}" ; i > 0 ; i--)); do + case "$i" in + 1 ) + broadcast_command "${message_prefix} in ${i} minute" + sleep 30s + broadcast_command "${message_prefix} in 30 seconds" + sleep 20s + broadcast_command "${message_prefix} in 10 seconds" + sleep 10s + ;; + 2 ) + ;& + 3 ) + ;& + 10 ) + ;& + 15 ) + ;& + "$mtime" ) + broadcast_command "${message_prefix} in ${i} minutes" + ;& + * ) + sleep 1m + # Checking for players every minute + # Checking after sleep since it is ran in the beginning of the function + if [ "$(get_player_count)" -eq 0 ]; then + break + fi + ;; + esac + done + # If there are players but mtime is empty + elif [ -z "${mtime}" ]; then + return_val=1 + # If there are players but mtime is not an integer + else + return_val=2 + fi + fi + return "$return_val" +} diff --git a/scripts/player_logging.sh b/scripts/player_logging.sh index a3a0ea2c8..371229300 100644 --- a/scripts/player_logging.sh +++ b/scripts/player_logging.sh @@ -18,7 +18,7 @@ while true; do if [ "${#server_pids[@]}" -ne 0 ]; then # Player IDs are usally 9 or 10 digits however when a player joins for the first time for a given boot their ID is temporary 00000000 (8x zeros) while loading # Player ID is also 00000000 (8x zeros) when in character creation - mapfile -t new_player_list < <( get_players_list | sed '/,00000000,[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/d' ) + mapfile -t new_player_list < <( get_players_list | tail -n +2 | sed '/,00000000,[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/d' ) # See players whose states have changed mapfile -t players_change_list < <( printf '%s\n' "${old_player_list[@]}" "${new_player_list[@]}" | sort | uniq -u ) diff --git a/scripts/update.sh b/scripts/update.sh index 0eaf94a98..c0b033872 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -13,25 +13,38 @@ if [ "$updateRequired" != 0 ]; then exit 0 fi -if [ "${UPDATE_ON_BOOT}" = false ]; then +if [ "${UPDATE_ON_BOOT,,}" != true ]; then LogWarn "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating" DiscordMessage "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating" "warn" exit 1 fi -if [ "${RCON_ENABLED,,}" = false ]; then +if [ "${RCON_ENABLED,,}" != true ]; then LogWarn "An update is available however auto updating without rcon is not supported" DiscordMessage "An update is available however auto updating without rcon is not supported" "warn" exit 1 fi -if [ "$(get_player_count)" -gt 0 ]; then - LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." - DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" - broadcast_command "The Serverwill update in ${AUTO_UPDATE_WARN_MINUTES} minutes" - sleep "${AUTO_UPDATE_WARN_MINUTES}m" +if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then + DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" fi -rm /palworld/steamapps/appmanifest_2394010.acf -backup -RCON "shutdown 1" \ No newline at end of file +countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server will update" +countdown_exit_code=$? +case "${countdown_exit_code}" in + 0 ) + LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST." + rm /palworld/steamapps/appmanifest_2394010.acf + + backup + shutdown_server + ;; + 1 ) + LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is empty." + exit 1 + ;; + 2 ) + LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}" + exit 1 + ;; +esac