diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 13f1de424..3bf8345e9 100644 --- a/scripts/auto_reboot.sh +++ b/scripts/auto_reboot.sh @@ -22,7 +22,7 @@ fi if [[ "${AUTO_REBOOT_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then for ((i = "${AUTO_REBOOT_WARN_MINUTES}" ; i > 0 ; i--)); do - RCON "broadcast The_Server_will_reboot_in_${i}_Minutes" + broadcast_command "The Server will reboot in ${i} minutes" sleep "1m" done RCON save diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index ca18581e6..15995dee6 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -144,6 +144,23 @@ RCON() { rcon-cli -c /home/steam/server/rcon.yaml "$args" } +# Given a message this will broadcast in game +# Since RCON does not support spaces this will replace all spaces with underscores +# Returns 0 on success +# Returns 1 if not able to broadcast +broadcast_command() { + local return_val=0 + # Replaces spaces with underscore + local message="${1// /_}" + if [[ $TEXT = *[![:ascii:]]* ]]; then + LogWarn "Unable to broadcast since the message contains non-ascii characters: \"${message}\"" + return_val=1 + elif ! RCON "broadcast ${message}"; then + return_val=1 + fi + return "$return_val" +} + # Helper Functions for installation & updates # shellcheck source=/dev/null source "/home/steam/server/helper_install.sh" \ No newline at end of file diff --git a/scripts/update.sh b/scripts/update.sh index 5489bf5c9..efd9360dc 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -24,7 +24,7 @@ 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" - RCON "broadcast The_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" fi