Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player Logging Improvement #431

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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