Skip to content

Commit

Permalink
Added get players list functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dashboy1998 committed Feb 20, 2024
1 parent 83a86c9 commit 81c447e
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions scripts/helper_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,32 @@ isExecutable() {
return "$return_val"
}

# Lists players
# Outputs nothing if RCON is not enabled and returns 1
# Outputs player list if RCON is enabled and returns 0
get_players_list() {
local return_val=0
if [ "${RCON_ENABLED,,}" != true ]; then
return_val=1
fi

# tail -n +2 removes the header "name,playeruid,steamid"
RCON "ShowPlayers" | tail -n +2
return "$return_val"
}

# Checks how many players are currently connected
# Outputs 0 if RCON is not enabled
# Outputs the player count if rcon is enabled
# Outputs 0 if RCON is not enabled and returns 1
# Outputs the player count if rcon is enabled and returns 0
get_player_count() {
local player_list
if [ "${RCON_ENABLED,,}" != true ]; then
echo 0
return 0
local return_val=0
if ! player_list=$(get_players_list); then
return_val=1
fi
player_list=$(RCON "ShowPlayers")

echo -n "${player_list}" | wc -l
return "$return_val"
}

#
Expand Down

0 comments on commit 81c447e

Please sign in to comment.