Skip to content

Commit

Permalink
Merge branch 'main' into rm-temp-file-in-update-required-if-error
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsvanloef authored Feb 23, 2024
2 parents 3e34b4a + 8f4ff78 commit a8a88b6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 44 deletions.
73 changes: 36 additions & 37 deletions scripts/player_logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 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
10 changes: 4 additions & 6 deletions scripts/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@ 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 /dev/null
fi
LogSuccess "Shutdown Complete"
LogSuccess "Shutdown Complete"

trap - ERR

Expand Down
2 changes: 1 addition & 1 deletion scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a8a88b6

Please sign in to comment.