Skip to content

Commit

Permalink
#287 added more complex handling of read timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
jammsen committed Jan 9, 2025
1 parent 1fffb15 commit ba584e8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ ENV DEBIAN_FRONTEND=noninteractive \
RESTART_CRON_EXPRESSION="0 18 * * *" \
# RCON-Playerdetection - NEEDS RCON ENABLED!
RCON_PLAYER_DETECTION=true \
RCON_PLAYER_DEBUG=false \
RCON_PLAYER_DETECTION_STARTUP_DELAY=60 \
RCON_PLAYER_DETECTION_CHECK_INTERVAL=15 \
# Webhook-settings
Expand Down
1 change: 1 addition & 0 deletions default.env
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RESTART_DEBUG_OVERRIDE=false
RESTART_CRON_EXPRESSION="0 18 * * *"
# RCON-Playerdetection - NEEDS RCON ENABLED!
RCON_PLAYER_DETECTION=true
RCON_PLAYER_DEBUG=false
RCON_PLAYER_DETECTION_STARTUP_DELAY=60
RCON_PLAYER_DETECTION_CHECK_INTERVAL=15
# Webhook-settings
Expand Down
Empty file modified docker-build.sh
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions docs/ENV_VARS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ These settings control the behavior of the Docker container:
| RESTART_DEBUG_OVERRIDE | Automatic restarts down to 15 seconds instead of 15 minutes | false | Boolean |
| RESTART_CRON_EXPRESSION | Needs a Cron-Expression - See [Cron expression](#cron-expression) | 0 3,15 * * * | Cron-Expression |
| RCON_PLAYER_DETECTION | Set to enabled will send player join and leaves to console, rcon and webhooks, NEEDS `RCON_ENABLED` | true | Boolean |
| RCON_PLAYER_DEBUG | Set to enabled will post debug messages to the console output | false | Boolean |
| RCON_PLAYER_DETECTION_STARTUP_DELAY | Initial delay for start checking for players, consider steam-updates and server start up in seconds | 60 | Integer |
| RCON_PLAYER_DETECTION_CHECK_INTERVAL | Interval in seconds to wait for next check in the infinite loop | 15 | Integer |
| WEBHOOK_ENABLED | Set to enabled will send webhook notifications, NEEDS `WEBHOOK_URL` | false | Boolean |
Expand Down
32 changes: 30 additions & 2 deletions includes/playerdetection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,23 @@ rcon_showplayers_with_retry() {

for ((i=0; i<amount_of_retries; i++)); do
command_output=$(rcon showplayers 2> /dev/null)
if [[ -n $RCON_PLAYER_DEBUG ]] && [[ $RCON_PLAYER_DEBUG == "true" ]]; then
ew "Debug: command_output = '$command_output'"
fi
if [[ $? -eq 0 ]]; then
# Check if the command executed successfully, regardless of content
if [[ -n "$command_output" ]]; then
if [[ -n "$command_output" && "$(echo "$command_output" | wc -l)" -gt 1 ]]; then
# If there is output, process it into current_players
readarray -t current_players <<< "$(echo "$command_output" | tail -n +2)"
if [[ -n $RCON_PLAYER_DEBUG ]] && [[ $RCON_PLAYER_DEBUG == "true" ]]; then
ew "Debug: current_players = ${current_players[*]}"
fi
else
# If there is no output, clear the current_players array
# No player data
current_players=()
if [[ -n $RCON_PLAYER_DEBUG ]] && [[ $RCON_PLAYER_DEBUG == "true" ]]; then
ew "Debug: No player data available."
fi
fi
return 0
fi
Expand All @@ -48,19 +57,38 @@ compare_players() {
return
fi

if [[ -n $RCON_PLAYER_DEBUG ]] && [[ $RCON_PLAYER_DEBUG == "true" ]]; then
ew "Debug: current_players = ${current_players[*]}"
fi
if [[ ${#current_players[@]} -eq 0 ]]; then
e "No players currently on the server."
return
fi


# Do we need a case where current_players is empty?
# if [[ ${#current_players[@]} -eq 0 ]]; then
# echo "No players currently on the server."
# fi

for player_info in "${current_players[@]}"; do
if [[ -n $RCON_PLAYER_DEBUG ]] && [[ $RCON_PLAYER_DEBUG == "true" ]]; then
ew "For-Loop-Debug: player_info = '$player_info'"
fi
# 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"

# Ensure player_data has the expected number of elements
if [[ ${#player_data[@]} -lt 3 ]]; then
ew "Error: Malformed player data: '$player_info'"
continue
fi

local steamid="${player_data[-1]}"
local playeruid="${player_data[-2]}"
local name="${player_data[*]::${#player_data[@]}-2}"
Expand Down
4 changes: 2 additions & 2 deletions scripts/servermanager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ do
player_detection_loop &
PLAYER_DETECTION_PID="$!"
echo $PLAYER_DETECTION_PID > PLAYER_DETECTION.PID
e "> Player detection thread started with pid ${PLAYER_DETECTION_PID}"
ew "> Player detection thread started with pid ${PLAYER_DETECTION_PID}"
fi

e "> Server main thread started with pid ${START_MAIN_PID}"
ew "> Server main thread started with pid ${START_MAIN_PID}"
wait ${START_MAIN_PID}

if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then
Expand Down

0 comments on commit ba584e8

Please sign in to comment.