From ca65fcd3a7971d41843decb5a4a45b4d4eb47fd2 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 19 Feb 2024 19:09:05 -0500 Subject: [PATCH 1/3] Add broadcast function --- scripts/helper_functions.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 41921f1c7..478609f3b 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -134,6 +134,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 From 87b31da4afa877625cf35d1467a89fc285d23229 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 19 Feb 2024 19:10:34 -0500 Subject: [PATCH 2/3] Changed broadcast to use function --- scripts/auto_reboot.sh | 2 +- scripts/update.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 13f1de424..8d3b07347 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/update.sh b/scripts/update.sh index 5489bf5c9..35d1c06f7 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_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes" sleep "${AUTO_UPDATE_WARN_MINUTES}m" fi From 63929c3453227c341b7990c740d58e9866a1327f Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Mon, 19 Feb 2024 19:43:37 -0500 Subject: [PATCH 3/3] Removed underscores from broadcast message --- scripts/auto_reboot.sh | 2 +- scripts/update.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/auto_reboot.sh b/scripts/auto_reboot.sh index 8d3b07347..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 - broadcast_command "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/update.sh b/scripts/update.sh index 35d1c06f7..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" - broadcast_command "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