Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip count down when players left #428

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions scripts/auto_reboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ source "/home/steam/server/helper_functions.sh"

if [ "${RCON_ENABLED,,}" != true ]; then
LogWarn "Unable to reboot. RCON is required."
exit 0
fi

if [ -z "${AUTO_REBOOT_WARN_MINUTES}" ]; then
LogError "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is empty."
exit 0
exit 1
fi

if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then
Expand All @@ -20,13 +15,18 @@ if [ "${AUTO_REBOOT_EVEN_IF_PLAYERS_ONLINE,,}" != true ]; then
fi
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"
sleep "1m"
done
shutdown_server
exit 0
fi

LogError "Unable to auto reboot, AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}"
countdown_message "${AUTO_REBOOT_WARN_MINUTES}" "Server will reboot"
countdown_exit_code=$?
case "${countdown_exit_code}" in
0 )
shutdown_server
;;
1 )
LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is empty"
exit 1
;;
2 )
LogError "Unable to auto reboot, the server is not empty and AUTO_REBOOT_WARN_MINUTES is not an integer: ${AUTO_REBOOT_WARN_MINUTES}"
exit 1
;;
esac
58 changes: 56 additions & 2 deletions scripts/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ get_players_list() {
return_val=1
fi

# tail -n +2 removes the header "name,playeruid,steamid"
RCON "ShowPlayers" | tail -n +2
RCON "ShowPlayers"
return "$return_val"
}

Expand Down Expand Up @@ -202,3 +201,58 @@ shutdown_server() {
fi
return "$return_val"
}

# Given an amount of time in minutes and a message prefix
# Will skip countdown if no players are in the server, Will only check the mtime if there are players in the server
# Returns 0 on success
# Returns 1 if mtime is empty
# Returns 2 if mtime is not an integer
countdown_message() {
local mtime="$1"
local message_prefix="$2"
local return_val=0

# Only do countdown if there are players
if [ "$(get_player_count)" -gt 0 ]; then
if [[ "${mtime}" =~ ^[0-9]+$ ]]; then
for ((i = "${mtime}" ; i > 0 ; i--)); do
case "$i" in
1 )
broadcast_command "${message_prefix} in ${i} minute"
sleep 30s
broadcast_command "${message_prefix} in 30 seconds"
sleep 20s
broadcast_command "${message_prefix} in 10 seconds"
sleep 10s
;;
2 )
;&
3 )
;&
10 )
;&
15 )
;&
"$mtime" )
broadcast_command "${message_prefix} in ${i} minutes"
;&
* )
sleep 1m
# Checking for players every minute
# Checking after sleep since it is ran in the beginning of the function
if [ "$(get_player_count)" -eq 0 ]; then
break
fi
;;
esac
done
# If there are players but mtime is empty
elif [ -z "${mtime}" ]; then
return_val=1
# If there are players but mtime is not an integer
else
return_val=2
fi
fi
return "$return_val"
}
2 changes: 1 addition & 1 deletion scripts/player_logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ while true; do
if [ "${#server_pids[@]}" -ne 0 ]; then
# Player IDs are usally 9 or 10 digits however when a player joins for the first time for a given boot their ID is temporary 00000000 (8x zeros) while loading
# Player ID is also 00000000 (8x zeros) when in character creation
mapfile -t new_player_list < <( get_players_list | sed '/,00000000,[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/d' )
mapfile -t new_player_list < <( get_players_list | tail -n +2 | sed '/,00000000,[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/d' )

# See players whose states have changed
mapfile -t players_change_list < <( printf '%s\n' "${old_player_list[@]}" "${new_player_list[@]}" | sort | uniq -u )
Expand Down
33 changes: 23 additions & 10 deletions scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,38 @@ if [ "$updateRequired" != 0 ]; then
exit 0
fi

if [ "${UPDATE_ON_BOOT}" = false ]; then
if [ "${UPDATE_ON_BOOT,,}" != true ]; then
LogWarn "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating"
DiscordMessage "An update is available however, UPDATE_ON_BOOT needs to be enabled for auto updating" "warn"
exit 1
fi

if [ "${RCON_ENABLED,,}" = false ]; then
if [ "${RCON_ENABLED,,}" != true ]; then
LogWarn "An update is available however auto updating without rcon is not supported"
DiscordMessage "An update is available however auto updating without rcon is not supported" "warn"
exit 1
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 Serverwill update in ${AUTO_UPDATE_WARN_MINUTES} minutes"
sleep "${AUTO_UPDATE_WARN_MINUTES}m"
if [[ "${AUTO_UPDATE_WARN_MINUTES}" =~ ^[0-9]+$ ]]; then
DiscordMessage "Server will update in ${AUTO_UPDATE_WARN_MINUTES} minutes"
fi

rm /palworld/steamapps/appmanifest_2394010.acf
backup
RCON "shutdown 1"
countdown_message "${AUTO_UPDATE_WARN_MINUTES}" "Server will update"
countdown_exit_code=$?
case "${countdown_exit_code}" in
0 )
LogAction "Updating the server from $CURRENT_MANIFEST to $TARGET_MANIFEST."
rm /palworld/steamapps/appmanifest_2394010.acf

backup
shutdown_server
;;
1 )
LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is empty."
exit 1
;;
2 )
LogWarn "Unable to auto update, the server is not empty and AUTO_UPDATE_WARN_MINUTES is not an integer: ${AUTO_UPDATE_WARN_MINUTES}"
exit 1
;;
esac