Skip to content

Commit

Permalink
Using mapfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Dashboy1998 committed Feb 21, 2024
1 parent f620614 commit ab9632b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scripts/player_logging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ while true; do
mapfile -t server_pids < <(pgrep PalServer-Linux)
if [ "${#server_pids[@]}" -ne 0 ]; then
# Player IDs are usally 7 digits however when a player joins for the first time for a given boot their ID is temporary 00000000 (8x zeros)
new_player_list=( $(get_players_list | sed -E 's/,([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|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])/,\2/g' ) )
mapfile -t new_player_list < <(get_players_list | sed -E 's/,([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|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])/,\2/g' )
# No players
if [ "${#new_player_list[@]}" -gt 0 ] && [ "${#old_player_list[@]}" -gt 0 ]; then
players_change_list=( $( comm -23 \
mapfile -t players_change_list < <( comm -23 \
<(printf '%s\n' "${old_player_list[@]}" | sort) \
<(printf '%s\n' "${new_player_list[@]}" | sort) ))
<(printf '%s\n' "${new_player_list[@]}" | sort) )

# All have joined
elif [ "${#new_player_list[@]}" -gt 0 ]; then
Expand Down

0 comments on commit ab9632b

Please sign in to comment.