From 81c447e2952547ea986b2fc1b27045d742d6293d Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Tue, 20 Feb 2024 15:54:42 -0500 Subject: [PATCH] Added get players list functions --- scripts/helper_functions.sh | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 41921f1c7..6646db392 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -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" } #