Skip to content

Commit

Permalink
add helper function get_player_count
Browse files Browse the repository at this point in the history
  • Loading branch information
Luatan committed Feb 11, 2024
1 parent 5cd2b38 commit 220db5b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions scripts/auto_reboot.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/bash
# shellcheck source=/dev/null
source "/home/steam/server/helper_functions.sh"

if [ "${RCON_ENABLED,,}" = true ]; then
if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then
players_count=$(rcon-cli -c /home/steam/server/rcon.yaml showplayers)
players_count=$(get_player_count)

if [ "$(echo -n "$players_count" | wc -l)" -gt 0 ]; then
if [ "$players_count" -gt 0 ]; then
echo "There are ${players_count} players online. Skipping auto reboot."
exit 1
fi
Expand Down
11 changes: 11 additions & 0 deletions scripts/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,14 @@ isExecutable() {
fi
return "$return_val"
}

# Checks how many players are currently connected
# Returns 0 if RCON is not enabled
# Returns the player count if rcon is enabled
get_player_count() {
if [ "${RCON_ENABLED,,}" != true ]; then
return 0
fi
PLAYERLIST=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers")
return "$(echo -n "$PLAYERLIST" | wc -l)"
}
5 changes: 3 additions & 2 deletions scripts/update.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash
# shellcheck source=/dev/null
source "/home/steam/server/helper_functions.sh"

if [ "${UPDATE_ON_BOOT}" = false ]; then
echo "Update on Boot needs to be enabled for auto updating"
Expand Down Expand Up @@ -42,8 +44,7 @@ if [ "$CURRENTBUILD" != "$TARGETBUILD" ]; then
echo "New Build was found. Updating the server from $CURRENTBUILD to $TARGETBUILD."
rm /palworld/steamapps/appmanifest_2394010.acf

PLAYERLIST=$(rcon-cli -c /home/steam/server/rcon.yaml "ShowPlayers")
if [ "$(echo -n "$PLAYERLIST" | wc -l)" -gt 0 ]; then
if [ "$(get_player_count)" -gt 0 ]; then
if [ -n "${DISCORD_WEBHOOK_URL}" ]; then
/home/steam/server/discord.sh "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes" "info" &
fi
Expand Down

0 comments on commit 220db5b

Please sign in to comment.