From 7d58559efff127d9a8020d5f03de2faa9628291a Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt <2270806+jammsen@users.noreply.github.com> Date: Sat, 24 Feb 2024 11:03:28 +0100 Subject: [PATCH 1/2] Fixes #221 - Added extended restart mechanic to facilitate also instant restarts --- CHANGELOG.md | 5 +++++ Dockerfile | 5 +++-- includes/playerdetection.sh | 5 +++++ includes/rcon.sh | 10 +++++++++- includes/webhook.sh | 7 +++++-- scripts/restart.sh | 12 +++++++++++- 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be7e072..6e4eefe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ [Back to main](README.md#changelog) +## 2024-02-24 + +- Added new mechanic for auto-restart, where the player count will be checked, 15 minutes grace-period (for dungeons, boss-fights, etc.) will only used if a player is online, if not the restart will be initiated (#221) + - Renamed/extended webhook messages accordingly + ## 2024-02-23 - Added new SERVER_SETTINGS_MODE called "rcononly" this will only setup up RCON, everything else is still manually to set (#221) diff --git a/Dockerfile b/Dockerfile index 6fdcd70..c325577 100644 --- a/Dockerfile +++ b/Dockerfile @@ -84,8 +84,9 @@ ENV DEBIAN_FRONTEND=noninteractive \ WEBHOOK_INSTALL_TITLE="Installing server" \ WEBHOOK_INSTALL_DESCRIPTION="Server is being installed" \ WEBHOOK_INSTALL_COLOR="2849520" \ - WEBHOOK_RESTART_TITLE="Server is restarting soon" \ - WEBHOOK_RESTART_DESCRIPTION="The gameserver is restarting in 15 minutes" \ + WEBHOOK_RESTART_TITLE="Automatic restart" \ + WEBHOOK_RESTART_DELAYED_DESCRIPTION="The automatic gameserver restart has been triggered, if the server has still players, restart will be in 15 minutes" \ + WEBHOOK_RESTART_NOW_DESCRIPTION="The gameserver is empty, restarting now" \ WEBHOOK_RESTART_COLOR="15593515" \ WEBHOOK_START_TITLE="Server is starting" \ WEBHOOK_START_DESCRIPTION="The gameserver is starting" \ diff --git a/includes/playerdetection.sh b/includes/playerdetection.sh index d6d3e8f..80a48de 100644 --- a/includes/playerdetection.sh +++ b/includes/playerdetection.sh @@ -99,6 +99,11 @@ compare_players() { for player_info in "${current_players[@]}"; do # Extract player name, UID, and Steam ID from player info + # This part sets the Internal Field Separator (IFS) variable to ','. + # In Bash, the IFS variable determines how Bash recognizes word boundaries. + # By default, it includes space, tab, and newline characters. + # By setting it to ',', we're telling Bash to split input lines at commas. + # https://tldp.org/LDP/abs/html/internalvariables.html#IFSREF IFS=',' read -r -a player_data <<< "$player_info" local steamid="${player_data[-1]}" local playeruid="${player_data[-2]}" diff --git a/includes/rcon.sh b/includes/rcon.sh index 467bd57..3f869b2 100644 --- a/includes/rcon.sh +++ b/includes/rcon.sh @@ -20,7 +20,6 @@ function broadcast_automatic_restart() { rcon "Shutdown 10" } - function broadcast_backup_start() { time=$(date '+%H:%M:%S') @@ -53,4 +52,13 @@ function broadcast_player_name_change() { function broadcast_player_leave() { time=$(date '+%H:%M:%S') rconcli "broadcast ${time}-$1-left-the-server" +} + +function check_is_server_empty() { + num_players=$(rcon -c "$RCON_CONFIG_FILE" showplayers | tail -n +2 | wc -l) + if [ "$num_players" -eq 0 ]; then + return 0 # Server empty + else + return 1 # Server not empty + fi } \ No newline at end of file diff --git a/includes/webhook.sh b/includes/webhook.sh index 0ac3081..618500c 100644 --- a/includes/webhook.sh +++ b/includes/webhook.sh @@ -34,8 +34,11 @@ send_webhook_notification() { send_install_notification() { send_webhook_notification "$WEBHOOK_INSTALL_TITLE" "$WEBHOOK_INSTALL_DESCRIPTION" "$WEBHOOK_INSTALL_COLOR" } -send_restart_notification() { - send_webhook_notification "$WEBHOOK_RESTART_TITLE" "$WEBHOOK_RESTART_DESCRIPTION" "$WEBHOOK_RESTART_COLOR" +send_restart_planned_notification() { + send_webhook_notification "$WEBHOOK_RESTART_TITLE" "$WEBHOOK_RESTART_DELAYED_DESCRIPTION" "$WEBHOOK_RESTART_COLOR" +} +send_restart_now_notification() { + send_webhook_notification "$WEBHOOK_RESTART_TITLE" "$WEBHOOK_RESTART_NOW_DESCRIPTION" "$WEBHOOK_RESTART_COLOR" } send_start_notification() { send_webhook_notification "$WEBHOOK_START_TITLE" "$WEBHOOK_START_DESCRIPTION" "$WEBHOOK_START_COLOR" diff --git a/scripts/restart.sh b/scripts/restart.sh index bd234f4..357ed9b 100644 --- a/scripts/restart.sh +++ b/scripts/restart.sh @@ -8,13 +8,23 @@ source /includes/server.sh source /includes/webhook.sh function schedule_restart() { + ew ">>> Automatic restart was triggered..." PLAYER_DETECTION_PID=$(=1; counter--)); do if [[ -n $RCON_ENABLED ]] && [[ $RCON_ENABLED == "true" ]]; then + if check_is_server_empty; then + ew ">>> Server is empty, restarting now" + if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then + send_restart_now_notification + fi + break + else + ew ">>> Server has still players" + fi time=$(date '+%H:%M:%S') rconcli "broadcast ${time}-AUTOMATIC-RESTART-IN-$counter-MINUTES" fi From 09e9c2997d6662a591c1c75460d73cbad49530fa Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt <2270806+jammsen@users.noreply.github.com> Date: Sat, 24 Feb 2024 11:04:51 +0100 Subject: [PATCH 2/2] Wrong issue number - fixes #230 - Added extended restart mechanic to facilitate also instant restarts --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e4eefe..1b95b2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ## 2024-02-24 -- Added new mechanic for auto-restart, where the player count will be checked, 15 minutes grace-period (for dungeons, boss-fights, etc.) will only used if a player is online, if not the restart will be initiated (#221) +- Added new mechanic for auto-restart, where the player count will be checked, 15 minutes grace-period (for dungeons, boss-fights, etc.) will only used if a player is online, if not the restart will be initiated (#230) - Renamed/extended webhook messages accordingly ## 2024-02-23