From 9d6eb174e437b99490abd0a43924d2b0c0b17abf Mon Sep 17 00:00:00 2001 From: Callum Dickinson Date: Thu, 4 Apr 2024 19:45:22 +1300 Subject: [PATCH 1/4] RCON broadcast with spaces This incorporates the ideas from https://github.com/jammsen/docker-palworld-dedicated-server/pull/243, but updates the existing `rconcli` script to perform the conversion to non-breaking spaces, instead of using a customised `rcon` command. To make the implementation nicer, in `rconcli` the command and any additional values have been split into separate arguments. The first argument to the script is the desired command (e.g. `broadcast`), and any following arguments will be value (e.g. `Saving done`). The result (from the `rcon` command's perspective) will be: ``` broadcast Savingdone ``` The following changes are also included (some from the above PR): * Convert all RCON broadcasts to use spaces, instead of dashes, and make them otherwise look nicer. * Do not remove spaces from player names in broadcasts, as these are now handled correctly. * Add timestamps to all RCON broadcasts, to make it easier to tell when a broadcast was made. * When using the RCON `showplayers` command, redirect `stderr` to `/dev/null` to prevent log errors caused by players with special characters in their names. * Fix typos. * Remove trailing spaces on lines in some files. --- Dockerfile | 2 +- default.env | 2 +- includes/playerdetection.sh | 18 +++++++------- includes/rcon.sh | 47 ++++++++++++++++++------------------- scripts/backupmanager.sh | 15 ++++++------ scripts/rconcli.sh | 12 ++++++++-- scripts/restart.sh | 15 ++++++------ 7 files changed, 58 insertions(+), 53 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9752e7b..9c597a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -71,7 +71,7 @@ ENV DEBIAN_FRONTEND=noninteractive \ RESTART_ENABLED=false \ RESTART_DEBUG_OVERRIDE=false \ RESTART_CRON_EXPRESSION="0 18 * * *" \ - # RCON-Playerdection - NEEDS RCON ENABLED! + # RCON-Playerdetection - NEEDS RCON ENABLED! RCON_PLAYER_DETECTION=true \ RCON_PLAYER_DETECTION_STARTUP_DELAY=60 \ RCON_PLAYER_DETECTION_CHECK_INTERVAL=15 \ diff --git a/default.env b/default.env index 1e5223a..7b0956c 100644 --- a/default.env +++ b/default.env @@ -14,7 +14,7 @@ BACKUP_RETENTION_AMOUNT_TO_KEEP=72 RESTART_ENABLED=false RESTART_DEBUG_OVERRIDE=false RESTART_CRON_EXPRESSION="0 18 * * *" -# RCON-Playerdection - NEEDS RCON ENABLED! +# RCON-Playerdetection - NEEDS RCON ENABLED! RCON_PLAYER_DETECTION=true RCON_PLAYER_DETECTION_STARTUP_DELAY=60 RCON_PLAYER_DETECTION_CHECK_INTERVAL=15 diff --git a/includes/playerdetection.sh b/includes/playerdetection.sh index cba9fb8..f9c3a6a 100644 --- a/includes/playerdetection.sh +++ b/includes/playerdetection.sh @@ -9,19 +9,19 @@ player_detection_loop() { while true; do compare_players sleep "$RCON_PLAYER_DETECTION_CHECK_INTERVAL" - done + done } # Function to compare current and previous player lists compare_players() { local old_players=("${current_players[@]}") - readarray -t current_players < <(rcon showplayers | tail -n +2) + readarray -t current_players < <(rcon showplayers 2> /dev/null | tail -n +2) for player_info in "${current_players[@]}"; do # Extract player name, UID, and Steam ID from player info - # This part sets the Internal Field Separator (IFS) variable to ','. - # In Bash, the IFS variable determines how Bash recognizes word boundaries. - # By default, it includes space, tab, and newline characters. + # This part sets the Internal Field Separator (IFS) variable to ','. + # In Bash, the IFS variable determines how Bash recognizes word boundaries. + # By default, it includes space, tab, and newline characters. # By setting it to ',', we're telling Bash to split input lines at commas. # https://tldp.org/LDP/abs/html/internalvariables.html#IFSREF IFS=',' read -r -a player_data <<< "$player_info" @@ -89,7 +89,7 @@ announce_join() { send_info_notification "$message" fi if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then - broadcast_player_join "${1// /\-}" + broadcast_player_join "${1}" fi } @@ -102,7 +102,7 @@ announce_name_change() { send_info_notification "$message" fi if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then - broadcast_player_name_change "${1// /\-}" "${2// /\-}" + broadcast_player_name_change "${1}" "${2}" fi } @@ -115,6 +115,6 @@ announce_leave() { send_info_notification "$message" fi if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then - broadcast_player_leave "${1// /\-}" + broadcast_player_leave "${1}" fi -} \ No newline at end of file +} diff --git a/includes/rcon.sh b/includes/rcon.sh index 3f869b2..84f8d72 100644 --- a/includes/rcon.sh +++ b/includes/rcon.sh @@ -1,57 +1,56 @@ # shellcheck disable=SC2148 +function get_time() { + date '+[%H:%M:%S]' +} + function save_and_shutdown_server() { - rconcli 'broadcast Server-shutdown-was-requested-init-saving' - rconcli 'save' - rconcli 'broadcast Done-saving-server-shuts-down-now' + rconcli broadcast "$(get_time) Server shutdown requested. Saving..." + rconcli save + rconcli broadcast "$(get_time) Saving done. Server shutting down..." } function broadcast_automatic_restart() { - time=$(date '+%H:%M:%S') + time= for ((counter=1; counter<=15; counter++)); do rconcli "broadcast ${time}-AUTOMATIC-RESTART-IN-$counter-MINUTES" sleep 1 done - rconcli 'broadcast Saving-world-before-restart...' - rconcli 'save' - rconcli 'broadcast Saving-done' - rconcli 'broadcast Creating-backup' + rconcli broadcast "$(get_time) Saving world before restart..." + rconcli save + rconcli broadcast "$(get_time) Saving done" + rconcli broadcast "$(get_time) Creating backup..." rcon "Shutdown 10" } function broadcast_backup_start() { - time=$(date '+%H:%M:%S') - - rconcli "broadcast ${time}-Saving-in-5-seconds" + rconcli broadcast "$(get_time) Saving in 5 seconds..." sleep 5 - rconcli 'broadcast Saving-world...' - rconcli 'save' - rconcli 'broadcast Saving-done' - rconcli 'broadcast Creating-backup' + rconcli broadcast "$(get_time) Saving world..." + rconcli save + rconcli broadcast "$(get_time) Saving done" + rconcli broadcast "$(get_time) Creating backup..." } function broadcast_backup_success() { - rconcli 'broadcast Backup-done' + rconcli broadcast "$(get_time) Backup done" } function broadcast_backup_failed() { - rconcli 'broadcast Backup-failed' + rconcli broadcast "$(get_time) Backup failed" } function broadcast_player_join() { - time=$(date '+%H:%M:%S') - rconcli "broadcast ${time}-$1-joined-the-server" + rconcli broadcast "$(get_time) $1 joined the server" } function broadcast_player_name_change() { - time=$(date '+%H:%M:%S') - rconcli "broadcast ${time}-$1-renamed-to-$2" + rconcli broadcast "$(get_time) $1 renamed to $2" } function broadcast_player_leave() { - time=$(date '+%H:%M:%S') - rconcli "broadcast ${time}-$1-left-the-server" + rconcli broadcast "$(get_time) $1 left the server" } function check_is_server_empty() { @@ -61,4 +60,4 @@ function check_is_server_empty() { else return 1 # Server not empty fi -} \ No newline at end of file +} diff --git a/scripts/backupmanager.sh b/scripts/backupmanager.sh index 5f55575..aa72d6b 100644 --- a/scripts/backupmanager.sh +++ b/scripts/backupmanager.sh @@ -128,18 +128,17 @@ function create_backup() { check_required_directories date=$(date +%Y%m%d_%H%M%S) - time=$(date +%H-%M-%S) backup_file_name="saved-${date}.tar.gz" mkdir -p "${LOCAL_BACKUP_PATH}" - rconcli "broadcast ${time}-Saving-in-5-seconds" + rconcli broadcast "$(get_time) Saving in 5 seconds..." sleep 5 - rconcli 'broadcast Saving-world...' - rconcli 'save' - rconcli 'broadcast Saving-done' + rconcli broadcast "$(get_time) Saving world..." + rconcli save + rconcli broadcast "$(get_time) Saving done" sleep 15 - rconcli 'broadcast Creating-backup' + rconcli broadcast "$(get_time) Creating backup..." if ! tar cfz "${LOCAL_BACKUP_PATH}/${backup_file_name}" -C "${LOCAL_GAME_PATH}/" "Saved" ; then broadcast_backup_failed @@ -147,7 +146,7 @@ function create_backup() { else broadcast_backup_success es ">>> Backup '${backup_file_name}' created successfully" - fi + fi if [[ -n ${LOCAL_BACKUP_RETENTION_POLICY} ]] && [[ ${LOCAL_BACKUP_RETENTION_POLICY} == "true" ]] && [[ ${LOCAL_BACKUP_RETENTION_AMOUNT_TO_KEEP} =~ ^[0-9]+$ ]]; then ls -1t "${LOCAL_BACKUP_PATH}"/saved-*.tar.gz | tail -n +"$(($LOCAL_BACKUP_RETENTION_AMOUNT_TO_KEEP + 1))" | xargs -d '\n' rm -f -- @@ -208,7 +207,7 @@ function clean_backups() { ei "> No files in the backup directory ${LOCAL_BACKUP_PATH}. Exiting..." exit 0 fi - + files=$(ls -1t "${LOCAL_BACKUP_PATH}"/saved-*.tar.gz) files_to_delete=$(echo "${files}" | tail -n +"$(($num_files_to_keep + 1))") num_files=$(echo -n "${files}" | grep -c '^') diff --git a/scripts/rconcli.sh b/scripts/rconcli.sh index 3ad2dca..f494343 100644 --- a/scripts/rconcli.sh +++ b/scripts/rconcli.sh @@ -8,12 +8,20 @@ source /includes/colors.sh # Arguments: # Example: run_rcon_cli "showplayers" run_rcon_cli() { - local cmd=$* if [[ -z ${RCON_ENABLED+x} ]] || [[ "$RCON_ENABLED" != "true" ]]; then ew ">>> RCON is not enabled. Aborting RCON command ..." exit fi - output=$(rcon -c "$RCON_CONFIG_FILE" "${cmd}") + local command=$1 + shift + if [ $# -ge 1 ]; then + # In the command value, replace ASCII space characters with + # unicode non-breaking space characters. + full_command="$command $(echo "$@" | tr ' ' '\240')" + else + full_command=$command + fi + output=$(rcon -c "$RCON_CONFIG_FILE" "$full_command" | tr -d '\0') ei_nn "> RCON: "; e "${output}" } diff --git a/scripts/restart.sh b/scripts/restart.sh index 357ed9b..675f650 100644 --- a/scripts/restart.sh +++ b/scripts/restart.sh @@ -22,23 +22,22 @@ function schedule_restart() { send_restart_now_notification fi break - else + else ew ">>> Server has still players" fi - time=$(date '+%H:%M:%S') - rconcli "broadcast ${time}-AUTOMATIC-RESTART-IN-$counter-MINUTES" + rconcli broadcast "$(get_time) AUTOMATIC RESTART IN $counter MINUTES" fi if [[ -n $RESTART_DEBUG_OVERRIDE ]] && [[ $RESTART_DEBUG_OVERRIDE == "true" ]]; then sleep 1 else sleep 60 - fi + fi done if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then - rconcli 'broadcast Saving-world-before-restart...' - rconcli 'save' - rconcli 'broadcast Saving-done' + rconcli broadcast "$(get_time) Saving world before restart..." + rconcli save + rconcli broadcast "$(get_time) Saving done" sleep 15 kill -SIGTERM "${PLAYER_DETECTION_PID}" rcon "Shutdown 10" @@ -58,4 +57,4 @@ function schedule_restart() { fi } -schedule_restart \ No newline at end of file +schedule_restart From 8dfc2da0acfe6f18e2c21eafedff897d83af4b55 Mon Sep 17 00:00:00 2001 From: Callum Dickinson Date: Thu, 4 Apr 2024 19:45:22 +1300 Subject: [PATCH 2/4] RCON broadcast with spaces This incorporates the ideas from https://github.com/jammsen/docker-palworld-dedicated-server/pull/243, but updates the existing `rconcli` script to perform the conversion to non-breaking spaces, instead of using a customised `rcon` command. To make the implementation nicer, in `rconcli` the command and any additional values have been split into separate arguments. The first argument to the script is the desired command (e.g. `broadcast`), and any following arguments will be value (e.g. `Saving done`). The result (from the `rcon` command's perspective) will be: ``` broadcast Savingdone ``` The following changes are also included (some from the above PR): * Convert all RCON broadcasts to use spaces, instead of dashes, and make them otherwise look nicer. * Do not remove spaces from player names in broadcasts, as these are now handled correctly. * Add timestamps to all RCON broadcasts, to make it easier to tell when a broadcast was made. * When using the RCON `showplayers` command, redirect `stderr` to `/dev/null` to prevent log errors caused by players with special characters in their names. * Fix typos. * Remove trailing spaces on lines in some files. --- Dockerfile | 2 +- default.env | 2 +- includes/playerdetection.sh | 18 +++++++------- includes/rcon.sh | 47 +++++++++++++++++-------------------- scripts/backupmanager.sh | 15 ++++++------ scripts/rconcli.sh | 12 ++++++++-- scripts/restart.sh | 16 ++++++------- 7 files changed, 58 insertions(+), 54 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9752e7b..9c597a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -71,7 +71,7 @@ ENV DEBIAN_FRONTEND=noninteractive \ RESTART_ENABLED=false \ RESTART_DEBUG_OVERRIDE=false \ RESTART_CRON_EXPRESSION="0 18 * * *" \ - # RCON-Playerdection - NEEDS RCON ENABLED! + # RCON-Playerdetection - NEEDS RCON ENABLED! RCON_PLAYER_DETECTION=true \ RCON_PLAYER_DETECTION_STARTUP_DELAY=60 \ RCON_PLAYER_DETECTION_CHECK_INTERVAL=15 \ diff --git a/default.env b/default.env index 1e5223a..7b0956c 100644 --- a/default.env +++ b/default.env @@ -14,7 +14,7 @@ BACKUP_RETENTION_AMOUNT_TO_KEEP=72 RESTART_ENABLED=false RESTART_DEBUG_OVERRIDE=false RESTART_CRON_EXPRESSION="0 18 * * *" -# RCON-Playerdection - NEEDS RCON ENABLED! +# RCON-Playerdetection - NEEDS RCON ENABLED! RCON_PLAYER_DETECTION=true RCON_PLAYER_DETECTION_STARTUP_DELAY=60 RCON_PLAYER_DETECTION_CHECK_INTERVAL=15 diff --git a/includes/playerdetection.sh b/includes/playerdetection.sh index cba9fb8..f9c3a6a 100644 --- a/includes/playerdetection.sh +++ b/includes/playerdetection.sh @@ -9,19 +9,19 @@ player_detection_loop() { while true; do compare_players sleep "$RCON_PLAYER_DETECTION_CHECK_INTERVAL" - done + done } # Function to compare current and previous player lists compare_players() { local old_players=("${current_players[@]}") - readarray -t current_players < <(rcon showplayers | tail -n +2) + readarray -t current_players < <(rcon showplayers 2> /dev/null | tail -n +2) for player_info in "${current_players[@]}"; do # Extract player name, UID, and Steam ID from player info - # This part sets the Internal Field Separator (IFS) variable to ','. - # In Bash, the IFS variable determines how Bash recognizes word boundaries. - # By default, it includes space, tab, and newline characters. + # This part sets the Internal Field Separator (IFS) variable to ','. + # In Bash, the IFS variable determines how Bash recognizes word boundaries. + # By default, it includes space, tab, and newline characters. # By setting it to ',', we're telling Bash to split input lines at commas. # https://tldp.org/LDP/abs/html/internalvariables.html#IFSREF IFS=',' read -r -a player_data <<< "$player_info" @@ -89,7 +89,7 @@ announce_join() { send_info_notification "$message" fi if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then - broadcast_player_join "${1// /\-}" + broadcast_player_join "${1}" fi } @@ -102,7 +102,7 @@ announce_name_change() { send_info_notification "$message" fi if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then - broadcast_player_name_change "${1// /\-}" "${2// /\-}" + broadcast_player_name_change "${1}" "${2}" fi } @@ -115,6 +115,6 @@ announce_leave() { send_info_notification "$message" fi if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then - broadcast_player_leave "${1// /\-}" + broadcast_player_leave "${1}" fi -} \ No newline at end of file +} diff --git a/includes/rcon.sh b/includes/rcon.sh index 3f869b2..77ab0a7 100644 --- a/includes/rcon.sh +++ b/includes/rcon.sh @@ -1,57 +1,54 @@ # shellcheck disable=SC2148 +function get_time() { + date '+[%H:%M:%S]' +} + function save_and_shutdown_server() { - rconcli 'broadcast Server-shutdown-was-requested-init-saving' - rconcli 'save' - rconcli 'broadcast Done-saving-server-shuts-down-now' + rconcli broadcast "$(get_time) Server shutdown requested. Saving..." + rconcli save + rconcli broadcast "$(get_time) Saving done. Server shutting down..." } function broadcast_automatic_restart() { - time=$(date '+%H:%M:%S') - for ((counter=1; counter<=15; counter++)); do rconcli "broadcast ${time}-AUTOMATIC-RESTART-IN-$counter-MINUTES" sleep 1 done - rconcli 'broadcast Saving-world-before-restart...' - rconcli 'save' - rconcli 'broadcast Saving-done' - rconcli 'broadcast Creating-backup' + rconcli broadcast "$(get_time) Saving world before restart..." + rconcli save + rconcli broadcast "$(get_time) Saving done" + rconcli broadcast "$(get_time) Creating backup..." rcon "Shutdown 10" } function broadcast_backup_start() { - time=$(date '+%H:%M:%S') - - rconcli "broadcast ${time}-Saving-in-5-seconds" + rconcli broadcast "$(get_time) Saving in 5 seconds..." sleep 5 - rconcli 'broadcast Saving-world...' - rconcli 'save' - rconcli 'broadcast Saving-done' - rconcli 'broadcast Creating-backup' + rconcli broadcast "$(get_time) Saving world..." + rconcli save + rconcli broadcast "$(get_time) Saving done" + rconcli broadcast "$(get_time) Creating backup..." } function broadcast_backup_success() { - rconcli 'broadcast Backup-done' + rconcli broadcast "$(get_time) Backup done" } function broadcast_backup_failed() { - rconcli 'broadcast Backup-failed' + rconcli broadcast "$(get_time) Backup failed" } function broadcast_player_join() { - time=$(date '+%H:%M:%S') - rconcli "broadcast ${time}-$1-joined-the-server" + rconcli broadcast "$(get_time) $1 joined the server" } function broadcast_player_name_change() { - time=$(date '+%H:%M:%S') - rconcli "broadcast ${time}-$1-renamed-to-$2" + rconcli broadcast "$(get_time) $1 renamed to $2" } function broadcast_player_leave() { - time=$(date '+%H:%M:%S') - rconcli "broadcast ${time}-$1-left-the-server" + rconcli broadcast "$(get_time) $1 left the server" } function check_is_server_empty() { @@ -61,4 +58,4 @@ function check_is_server_empty() { else return 1 # Server not empty fi -} \ No newline at end of file +} diff --git a/scripts/backupmanager.sh b/scripts/backupmanager.sh index 5f55575..aa72d6b 100644 --- a/scripts/backupmanager.sh +++ b/scripts/backupmanager.sh @@ -128,18 +128,17 @@ function create_backup() { check_required_directories date=$(date +%Y%m%d_%H%M%S) - time=$(date +%H-%M-%S) backup_file_name="saved-${date}.tar.gz" mkdir -p "${LOCAL_BACKUP_PATH}" - rconcli "broadcast ${time}-Saving-in-5-seconds" + rconcli broadcast "$(get_time) Saving in 5 seconds..." sleep 5 - rconcli 'broadcast Saving-world...' - rconcli 'save' - rconcli 'broadcast Saving-done' + rconcli broadcast "$(get_time) Saving world..." + rconcli save + rconcli broadcast "$(get_time) Saving done" sleep 15 - rconcli 'broadcast Creating-backup' + rconcli broadcast "$(get_time) Creating backup..." if ! tar cfz "${LOCAL_BACKUP_PATH}/${backup_file_name}" -C "${LOCAL_GAME_PATH}/" "Saved" ; then broadcast_backup_failed @@ -147,7 +146,7 @@ function create_backup() { else broadcast_backup_success es ">>> Backup '${backup_file_name}' created successfully" - fi + fi if [[ -n ${LOCAL_BACKUP_RETENTION_POLICY} ]] && [[ ${LOCAL_BACKUP_RETENTION_POLICY} == "true" ]] && [[ ${LOCAL_BACKUP_RETENTION_AMOUNT_TO_KEEP} =~ ^[0-9]+$ ]]; then ls -1t "${LOCAL_BACKUP_PATH}"/saved-*.tar.gz | tail -n +"$(($LOCAL_BACKUP_RETENTION_AMOUNT_TO_KEEP + 1))" | xargs -d '\n' rm -f -- @@ -208,7 +207,7 @@ function clean_backups() { ei "> No files in the backup directory ${LOCAL_BACKUP_PATH}. Exiting..." exit 0 fi - + files=$(ls -1t "${LOCAL_BACKUP_PATH}"/saved-*.tar.gz) files_to_delete=$(echo "${files}" | tail -n +"$(($num_files_to_keep + 1))") num_files=$(echo -n "${files}" | grep -c '^') diff --git a/scripts/rconcli.sh b/scripts/rconcli.sh index 3ad2dca..f494343 100644 --- a/scripts/rconcli.sh +++ b/scripts/rconcli.sh @@ -8,12 +8,20 @@ source /includes/colors.sh # Arguments: # Example: run_rcon_cli "showplayers" run_rcon_cli() { - local cmd=$* if [[ -z ${RCON_ENABLED+x} ]] || [[ "$RCON_ENABLED" != "true" ]]; then ew ">>> RCON is not enabled. Aborting RCON command ..." exit fi - output=$(rcon -c "$RCON_CONFIG_FILE" "${cmd}") + local command=$1 + shift + if [ $# -ge 1 ]; then + # In the command value, replace ASCII space characters with + # unicode non-breaking space characters. + full_command="$command $(echo "$@" | tr ' ' '\240')" + else + full_command=$command + fi + output=$(rcon -c "$RCON_CONFIG_FILE" "$full_command" | tr -d '\0') ei_nn "> RCON: "; e "${output}" } diff --git a/scripts/restart.sh b/scripts/restart.sh index 357ed9b..65e7e0e 100644 --- a/scripts/restart.sh +++ b/scripts/restart.sh @@ -4,6 +4,7 @@ set -e source /includes/colors.sh +source /includes/rcon.sh source /includes/server.sh source /includes/webhook.sh @@ -22,23 +23,22 @@ function schedule_restart() { send_restart_now_notification fi break - else + else ew ">>> Server has still players" fi - time=$(date '+%H:%M:%S') - rconcli "broadcast ${time}-AUTOMATIC-RESTART-IN-$counter-MINUTES" + rconcli broadcast "$(get_time) AUTOMATIC RESTART IN $counter MINUTES" fi if [[ -n $RESTART_DEBUG_OVERRIDE ]] && [[ $RESTART_DEBUG_OVERRIDE == "true" ]]; then sleep 1 else sleep 60 - fi + fi done if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then - rconcli 'broadcast Saving-world-before-restart...' - rconcli 'save' - rconcli 'broadcast Saving-done' + rconcli broadcast "$(get_time) Saving world before restart..." + rconcli save + rconcli broadcast "$(get_time) Saving done" sleep 15 kill -SIGTERM "${PLAYER_DETECTION_PID}" rcon "Shutdown 10" @@ -58,4 +58,4 @@ function schedule_restart() { fi } -schedule_restart \ No newline at end of file +schedule_restart From 6bd8ed4bbe5dc8c97e181d728a7e2fd83a0a0e17 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt <2270806+jammsen@users.noreply.github.com> Date: Thu, 4 Apr 2024 22:28:05 +0200 Subject: [PATCH 3/4] added little fixed and touches --- includes/playerdetection.sh | 6 +++--- includes/rcon.sh | 4 +--- scripts/backupmanager.sh | 4 ++++ scripts/restart.sh | 4 ++++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/includes/playerdetection.sh b/includes/playerdetection.sh index f9c3a6a..0817b61 100644 --- a/includes/playerdetection.sh +++ b/includes/playerdetection.sh @@ -82,7 +82,7 @@ compare_players() { # Function to announce a player join announce_join() { - time=$(date '+%H:%M:%S') + time=$(date '+[%H:%M:%S]') message="Player $1 has joined the server." echo "${time}: $message" if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then @@ -95,7 +95,7 @@ announce_join() { # Function to announce a player join announce_name_change() { - time=$(date '+%H:%M:%S') + time=$(date '+[%H:%M:%S]') message="Player $1 has changed their name to $2." echo "${time}: $message" if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then @@ -108,7 +108,7 @@ announce_name_change() { # Function to announce a player leave announce_leave() { - time=$(date '+%H:%M:%S') + time=$(date '+[%H:%M:%S]') message="Player $1 has left the server." echo "${time}: $message" if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then diff --git a/includes/rcon.sh b/includes/rcon.sh index 84f8d72..12a40d6 100644 --- a/includes/rcon.sh +++ b/includes/rcon.sh @@ -11,10 +11,8 @@ function save_and_shutdown_server() { } function broadcast_automatic_restart() { - time= - for ((counter=1; counter<=15; counter++)); do - rconcli "broadcast ${time}-AUTOMATIC-RESTART-IN-$counter-MINUTES" + rconcli "broadcast $(get_time)-AUTOMATIC-RESTART-IN-$counter-MINUTES" sleep 1 done rconcli broadcast "$(get_time) Saving world before restart..." diff --git a/scripts/backupmanager.sh b/scripts/backupmanager.sh index aa72d6b..733d2dc 100644 --- a/scripts/backupmanager.sh +++ b/scripts/backupmanager.sh @@ -11,6 +11,10 @@ LOCAL_GAME_SAVE_PATH=${GAME_SAVE_PATH} # Directory where the game save files are LOCAL_BACKUP_RETENTION_POLICY=${BACKUP_RETENTION_POLICY} # Number of backup files to keep LOCAL_BACKUP_RETENTION_AMOUNT_TO_KEEP=${BACKUP_RETENTION_AMOUNT_TO_KEEP} # Number of backup files to keep +function get_time() { + date '+[%H:%M:%S]' +} + function print_usage() { script_name=$(basename "$0") echo "Usage:" diff --git a/scripts/restart.sh b/scripts/restart.sh index 675f650..295eb21 100644 --- a/scripts/restart.sh +++ b/scripts/restart.sh @@ -7,6 +7,10 @@ source /includes/colors.sh source /includes/server.sh source /includes/webhook.sh +function get_time() { + date '+[%H:%M:%S]' +} + function schedule_restart() { ew ">>> Automatic restart was triggered..." PLAYER_DETECTION_PID=$( Date: Thu, 4 Apr 2024 22:44:00 +0200 Subject: [PATCH 4/4] removed include --- scripts/restart.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/restart.sh b/scripts/restart.sh index ea684b4..295eb21 100644 --- a/scripts/restart.sh +++ b/scripts/restart.sh @@ -4,7 +4,6 @@ set -e source /includes/colors.sh -source /includes/rcon.sh source /includes/server.sh source /includes/webhook.sh