Skip to content

Commit

Permalink
Moved rcon-cli to utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
Phelms215 committed Feb 17, 2024
1 parent 6d81cb0 commit ce5e967
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
6 changes: 3 additions & 3 deletions scripts/auto_reboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ fi

if [[ "${AUTO_REBOOT_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then
for ((i = "${AUTO_REBOOT_WARN_MINUTES}" ; i > 0 ; i--)); do
rcon-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_reboot_in_${i}_Minutes"
RCON "broadcast The_Server_will_reboot_in_${i}_Minutes"
sleep "1m"
done
rcon-cli -c /home/steam/server/rcon.yaml save
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
RCON save
RCON "shutdown 1"
exit 0
fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "/home/steam/server/helper_functions.sh"

DiscordMessage "Creating backup..." "in-progress"
if [ "${RCON_ENABLED,,}" = true ]; then
rcon-cli -c /home/steam/server/rcon.yaml save
RCON save
fi

DATE=$(date +"%Y-%m-%d_%H-%M-%S")
Expand Down
19 changes: 12 additions & 7 deletions scripts/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ get_player_count() {
echo 0
return 0
fi
player_list=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers")
player_list=$(RCON "ShowPlayers")
echo -n "${player_list}" | wc -l
}

Expand Down Expand Up @@ -128,6 +128,11 @@ DiscordMessage() {
fi
}

# RCON Call
RCON() {
local args="$1"
echo rcon-cli -c /home/steam/server/rcon.yaml "$args"
}


# Returns 0 if Update Required
Expand All @@ -138,9 +143,9 @@ LogAction "Checking for new update"

temp_file=$(mktemp)
http_code=$(curl https://api.steamcmd.net/v1/info/2394010 --output "$temp_file" --silent --location --write-out "%{http_code}")
TARGET_MANIFEST=$(grep -Po '"2394012".*"gid": "\d+"' <"$temp_file" | sed -r 's/.*("[0-9]+")$/\1/')

CURRENTBUILD=$(awk '/buildid/{ print $2 }' < /palworld/steamapps/appmanifest_2394010.acf)
TARGETBUILD=$(grep -P '"public": {"buildid": "\d+"' -o <"$temp_file" | sed -r 's/.*("[0-9]+")$/\1/')
CURRENT_MANIFEST=$(awk '/manifest/{count++} count==2 {print $2; exit}' /palworld/steamapps/appmanifest_2394010.acf)
rm "$temp_file"

if [ "$http_code" -ne 200 ]; then
Expand All @@ -149,16 +154,16 @@ if [ "$http_code" -ne 200 ]; then
return 2
fi

if [ -z "$TARGETBUILD" ]; then
if [ -z "$TARGET_MANIFEST" ]; then
LogError "The server response does not contain the expected BuildID. Unable to check for updates!"
DiscordMessage "Steam servers response does not contain the expected BuildID. Unable to check for updates!" "failure"
return 2
fi

if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then
if [ "$CURRENT_MANIFEST" != "$TARGET_MANIFEST" ]; then
LogInfo "An Update Is Available."
LogInfo "Current Version: $CURRENTBUILD"
LogInfo "Latest Version: $TARGETBUILD."
LogInfo "Current Version: $CURRENT_MANIFEST"
LogInfo "Latest Version: $TARGET_MANIFEST."
return 0
fi

Expand Down
4 changes: 2 additions & 2 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ term_handler() {
DiscordMessage "${DISCORD_PRE_SHUTDOWN_MESSAGE}" "in-progress"

if [ "${RCON_ENABLED,,}" = true ]; then
rcon-cli save
rcon-cli "shutdown 1"
RCON save
RCON "shutdown 1"
else # Does not save
kill -SIGTERM "$(pidof PalServer-Linux-Test)"
fi
Expand Down
4 changes: 2 additions & 2 deletions scripts/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ if [ -f "$BACKUP_FILE" ]; then

if [ "${RCON_ENABLED}" = true ]; then
LogAction "Shutting Down Server"
rcon-cli -c /home/steam/server/rcon.yaml save
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
RCON save
RCON "shutdown 1"
else
LogWarn "RCON is not enabled. Please enable RCON to use this feature. Unable to restore backup."
exit 1
Expand Down
4 changes: 2 additions & 2 deletions scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ 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-cli -c /home/steam/server/rcon.yaml "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes"
RCON "broadcast The_Server_will_update_in_${AUTO_UPDATE_WARN_MINUTES}_Minutes"
sleep "${AUTO_UPDATE_WARN_MINUTES}m"
fi

rm /palworld/steamapps/appmanifest_2394010.acf
backup
rcon-cli -c /home/steam/server/rcon.yaml "shutdown 1"
RCON "shutdown 1"

0 comments on commit ce5e967

Please sign in to comment.