Skip to content

Commit

Permalink
Merge pull request #411 from Dashboy1998/create-broadcast-function
Browse files Browse the repository at this point in the history
Create broadcast function
  • Loading branch information
thijsvanloef authored Feb 21, 2024
2 parents 0f02311 + 297270c commit e183027
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scripts/auto_reboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions scripts/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e183027

Please sign in to comment.