From b0e2d5152fe4a4e9565a2891c44fefd366b84819 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 22 Feb 2024 10:28:34 -0500 Subject: [PATCH 1/3] Switched back to comm --- scripts/player_logging.sh | 69 +++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/scripts/player_logging.sh b/scripts/player_logging.sh index 371229300..95ffb9c38 100644 --- a/scripts/player_logging.sh +++ b/scripts/player_logging.sh @@ -12,47 +12,46 @@ get_playername(){ echo "${player_info}" | sed -E 's/,([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][0-9]//g' } -old_player_list=( ) while true; do mapfile -t server_pids < <(pgrep PalServer-Linux) 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 | 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 ) - - # Go through the list of changes - for player in "${players_change_list[@]}"; do - # Steam ID to check since names are not unique in game - player_steamid=$(get_steamid "${player}") - - # Searching players who have joined - for new_player in "${new_player_list[@]}"; do - new_player_steamid=$(get_steamid "${new_player}") - # If in new player list then they joined - if [ "$new_player_steamid" = "$player_steamid" ]; then - player_name=$( get_playername "${player}" ) - LogInfo "${player_name} has joined" - broadcast_command "${player_name} has joined" - continue 2 - fi - done - - # Searching players who have left - for old_player in "${old_player_list[@]}"; do - old_player_steamid=$(get_steamid "${old_player}") - # If in old player list then they left - if [ "$old_player_steamid" = "$player_steamid" ]; then - player_name=$( get_playername "${player}" ) - LogInfo "${player_name} has left" - broadcast_command "${player_name} has left" - continue 2 - fi - done + mapfile -t current_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' | sort ) + + # If there are current players then some may have joined + if [ "${#current_player_list[@]}" -gt 0 ]; then + # Get list of players who have joined + mapfile -t players_who_joined_list < <( comm -13 \ + <(printf '%s\n' "${old_player_list[@]}") \ + <(printf '%s\n' "${current_player_list[@]}") ) + fi + + # If there are old players then some may have left + if [ "${#old_player_list[@]}" -gt 0 ]; then + # Get list of players who have left + mapfile -t players_who_left_list < <( comm -23 \ + <(printf '%s\n' "${old_player_list[@]}") \ + <(printf '%s\n' "${current_player_list[@]}") ) + fi + + # Log all players who have left + for player in "${players_who_left_list[@]}"; do + player_name=$( get_playername "${player}" ) + LogInfo "${player_name} has left" + broadcast_command "${player_name} has left" done - old_player_list=("${new_player_list[@]}") + + # Log all players who have joined + for player in "${players_who_joined_list[@]}"; do + player_name=$( get_playername "${player}" ) + LogInfo "${player_name} has joined" + broadcast_command "${player_name} has joined" + done + + old_player_list=("${current_player_list[@]}") + players_who_left_list=( ) + players_who_joined_list=( ) fi sleep "${PLAYER_LOGGING_POLL_PERIOD}" done From 91334f890b153f911ef4582280fa20d33d50c51f Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 22 Feb 2024 11:09:28 -0500 Subject: [PATCH 2/3] Check if rcon is enabled before starting player logging --- scripts/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/start.sh b/scripts/start.sh index 8f71dffb5..4e014c90c 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -143,7 +143,7 @@ default: password: "${ADMIN_PASSWORD}" EOL -if [ "${ENABLE_PLAYER_LOGGING,,}" = true ] && [[ "${PLAYER_LOGGING_POLL_PERIOD}" =~ ^[0-9]+$ ]]; then +if [ "${ENABLE_PLAYER_LOGGING,,}" = true ] && [[ "${PLAYER_LOGGING_POLL_PERIOD}" =~ ^[0-9]+$ ]] && [ "${RCON_ENABLED,,}" = true ]; then if [[ "$(id -u)" -eq 0 ]]; then su steam -c /home/steam/server/player_logging.sh & else From 96ff316c62638575eddbf6c6171628044c3b74ee Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 22 Feb 2024 21:05:15 -0500 Subject: [PATCH 3/3] Switched from pgrep to pidof --- scripts/player_logging.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/player_logging.sh b/scripts/player_logging.sh index 95ffb9c38..166b0cc4a 100644 --- a/scripts/player_logging.sh +++ b/scripts/player_logging.sh @@ -13,8 +13,8 @@ get_playername(){ } while true; do - mapfile -t server_pids < <(pgrep PalServer-Linux) - if [ "${#server_pids[@]}" -ne 0 ]; then + server_pid=$(pidof PalServer-Linux-Test) + if [ -n "${server_pid}" ]; 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 current_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' | sort )