From 04b0a1ab9331684fcfb7bb8d958d13c2536fe1a2 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Thu, 13 Apr 2023 09:30:43 +0100 Subject: [PATCH] ini improvements --- lgsm/modules/command_dev_details.sh | 88 +++++++++++++++++++---------- lgsm/modules/info_game.sh | 9 +-- 2 files changed, 62 insertions(+), 35 deletions(-) diff --git a/lgsm/modules/command_dev_details.sh b/lgsm/modules/command_dev_details.sh index 38996ec4b..41e165253 100644 --- a/lgsm/modules/command_dev_details.sh +++ b/lgsm/modules/command_dev_details.sh @@ -3,39 +3,69 @@ # Author: Daniel Gibbs # Contributors: http://linuxgsm.com/contrib # Website: https://linuxgsm.com -# Description: Dev only: Displays all parsed details. +# Description: Dev only: Enables debugging log to be saved to dev-debug.log. + +info_game.sh + +carriagereturn=$(file -b "${servercfgfullpath}" | grep -q CRLF && echo "${red}CRLF${default}" || echo "${lightgreen}LF${default}") echo -e "" -echo -e "${lightgreen}Details List${default}" +echo -e "${lightgreen}Server Details${default}" echo -e "==================================================================" echo -e "" + echo -e "Game: ${gamename}" -echo -e "Short Name: ${shortname}" -echo -e "Config: ${servercfgfullpath}" -echo -e "Config Type: ${configtype}" -echo -e "" -echo -e "${lightgreen}Ports${default}" -echo -e "=================================" -echo -e "Port: ${port}" -echo -e "Query Port: ${queryport}" +echo -e "Config type: ${configtype}" +echo -e "Config file: ${servercfgfullpath}" +echo -e "Carriage Return: ${carriagereturn}" + +# Create an associative array of the server details. +declare -A server_details=( + ['Admin Password']="${adminpassword}" + ['Config IP']="${configip}" + ['Default Map']="${defaultmap}" + ['Game Mode']="${gamemode}" + ['Game Type']="${gametype}" + ['ip']="${ip}" + ['Maxplayers']="${maxplayers}" + ['Port']="${port}" + ['Query Port']="${queryport}" + ['RCON Enabled']="${rconenabled}" + ['RCON Password']="${rconpassword}" + ['RCON Port']="${rconport}" + ['Reserved Slots']="${reservedslots}" + ['Server Password']="${serverpassword}" + ['Servername']="${servername}" + ['Tickrate']="${tickrate}" + ['Web Admin Enabled']="${webadminenabled}" + ['Web Admin Password']="${webadminpassword}" + ['Web Admin User']="${webadminuser}" + ['World Name']="${worldname}" + ['World Type']="${worldtype}" +) + +# Initialize a variable to keep track of missing server details. +missing_details="" + +# Loop through the server details and output them. echo -e "" -echo -e "${lightgreen}Server Details${default}" +echo -e "${lightgreen}Available Server Details${default}" echo -e "=================================" -echo -e "Servername: ${servername} ${servernameorigin}" -echo -e "Server Password: ${serverpassword}" -echo -e "RCON Password: ${rconpassword}" -echo -e "Admin Password: ${adminpassword}" -echo -e "Maxplayers: ${maxplayers}" -echo -e "Tickrate: ${tickrate}" -echo -e "Default Map: ${defaultmap}" -echo -e "Game Mode: ${gamemode}" -echo -e "Game Type: ${gametype}" -echo -e "RCON Enabled: ${rconenabled}" -echo -e "RCON Password: ${rconpassword}" -echo -e "Config IP: ${configip}" -echo -e "Web Admin Enabled: ${webadminenabled}" -echo -e "Web Admin User: ${webadminuser}" -echo -e "Web Admin Password: ${webadminpassword}" -echo -e "Reserved Slots: ${reservedslots}" -echo -e "World Name: ${worldname}" -echo -e "World Type: ${worldtype}" +for key in "${!server_details[@]}"; do + value=${server_details[$key]} + if [ -z "$value" ]; then + missing_details+="\n${key}" + else + echo -e "$key: $value " + fi +done + +# Output the missing server details if there are any. +if [ -n "$missing_details" ]; then + echo -e "" + echo -e "${lightgreen}Missing Server Details${default}" + echo -e "=================================" + echo -e "${missing_details}" +fi + +core_exit.sh diff --git a/lgsm/modules/info_game.sh b/lgsm/modules/info_game.sh index 21e15834d..342314516 100644 --- a/lgsm/modules/info_game.sh +++ b/lgsm/modules/info_game.sh @@ -6,7 +6,7 @@ # Description: Gathers various game server information. # shellcheck disable=SC2317 -modulesselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" +moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" ## Examples of filtering to get info from config files. # sed 's/foo//g' - remove foo @@ -29,8 +29,7 @@ fn_info_game_ini() { if [ -n "${3}" ]; then servercfgfullpath="${3}" fi - eval "${1}"="$(sed -n "/^[[:space:]]*\<${2}\>/ { s/.*= *//p;q }" "${servercfgfullpath}")" - eval "${1}origin"="config" + eval "${1}"="\"$(sed -n "/^[[:space:]]*\<${2}\>/ { s/.*= *//p;q }" "${servercfgfullpath}" | tr -d "\r")\"" configtype="ini" } @@ -180,13 +179,11 @@ fn_info_game_btl() { # Filetype: ini fn_info_game_cmw() { if [ -f "${servercfgfullpath}" ]; then - fn_info_game_ini "adminpassword" "AdminPassword" fn_info_game_ini "maxplayers" "MaxPlayers" - fn_info_game_ini "rconport" "RConPort" "${servercfgdir}/DefaultGame.ini" fn_info_game_ini "servername" "ServerName" fn_info_game_ini "serverpassword" "GamePassword" + fn_info_game_ini "rconport" "RConPort" "${servercfgdir}/DefaultGame.ini" fi - adminpassword="${adminpassword:-"NOT SET"}" defaultmap="${defaultmap:-"NOT SET"}" maxplayers="${maxplayers:-"0"}" port="${port:-"0"}"