From 3471df75b285a7e7160aec7a6e3057cabcf76092 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 22 Feb 2024 10:28:34 -0500 Subject: [PATCH 1/6] 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 b2deb3a44d683538118f9557e1cab7b30cbaf63d Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 22 Feb 2024 11:09:28 -0500 Subject: [PATCH 2/6] 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 5c1ac15c0f91a7c0f06ce7e09a318691229f7f24 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 22 Feb 2024 20:57:30 -0500 Subject: [PATCH 3/6] Switch to pidof in restore --- scripts/restore.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/restore.sh b/scripts/restore.sh index 792487fdb..072b63b49 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -69,12 +69,10 @@ if [ -f "$BACKUP_FILE" ]; then exit 1 fi - mapfile -t server_pids < <(pgrep PalServer-Linux-Test) - if [ "${#server_pids[@]}" -ne 0 ]; then + server_pid=$(pidof PalServer-Linux-Test) + if [ -n "${server_pid}" ]; then LogInfo "Waiting for Palworld to exit.." - for pid in "${server_pids[@]}"; do - tail --pid="$pid" -f 2>/dev/null - done + tail --pid="${server_pid}" -f 2>/dev/null fi LogSuccess "Shutdown Complete" From 755cb42a0883d51b16ac9a8f66a6001f7ddb063e Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 22 Feb 2024 21:05:15 -0500 Subject: [PATCH 4/6] 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 ) From 2d02b564789dcabba5c434f54745bb28c5e25523 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 22 Feb 2024 21:35:44 -0500 Subject: [PATCH 5/6] Updated redirect --- scripts/restore.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/restore.sh b/scripts/restore.sh index 072b63b49..6ab36f29d 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -72,7 +72,7 @@ if [ -f "$BACKUP_FILE" ]; then server_pid=$(pidof PalServer-Linux-Test) if [ -n "${server_pid}" ]; then LogInfo "Waiting for Palworld to exit.." - tail --pid="${server_pid}" -f 2>/dev/null + tail --pid="${server_pid}" -f /dev/null fi LogSuccess "Shutdown Complete" From 091111cbfbc78c561048cfa0d5e868a5043894c7 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Thu, 22 Feb 2024 21:41:43 -0500 Subject: [PATCH 6/6] Fixed spacing issue --- scripts/restore.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/restore.sh b/scripts/restore.sh index 6ab36f29d..87fd3be32 100644 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -74,7 +74,7 @@ if [ -f "$BACKUP_FILE" ]; then LogInfo "Waiting for Palworld to exit.." tail --pid="${server_pid}" -f /dev/null fi - LogSuccess "Shutdown Complete" + LogSuccess "Shutdown Complete" trap - ERR