From dc053ff9368fef3edc4fef8ed96bffc680f0d9b5 Mon Sep 17 00:00:00 2001 From: Jimmy Maple <38733055+jimmyatSplunk@users.noreply.github.com> Date: Sun, 12 Apr 2020 23:23:15 -0400 Subject: [PATCH 1/9] fix(bug): gamedig not using correct JSON object Command to output the results for player count was looking at the wrong object in the tree. This change corrects it to the right objects. --- lgsm/functions/query_gamedig.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/query_gamedig.sh b/lgsm/functions/query_gamedig.sh index 4f1bc5638..bfe38b937 100644 --- a/lgsm/functions/query_gamedig.sh +++ b/lgsm/functions/query_gamedig.sh @@ -30,7 +30,7 @@ if [ "$(command -v gamedig 2>/dev/null)" ]&&[ "$(command -v jq 2>/dev/null)" ]; fi # numplayers. - gdplayers=$(echo -e "${gamedigraw}" | jq -re '.players') + gdplayers=$(echo -e "${gamedigraw}" | jq -re '.raw.vanilla.raw.players.online') if [ "${gdplayers}" == "null" ]; then unset gdplayers elif [ "${gdplayers}" == "[]" ]; then From 4b16cb26c58c676b519071fbae31fc765fe59f74 Mon Sep 17 00:00:00 2001 From: Jimmy Maple <38733055+jimmyatSplunk@users.noreply.github.com> Date: Sun, 12 Apr 2020 23:57:06 -0400 Subject: [PATCH 2/9] feat(monitor): Include bot count in monitor output Update to include bot count in monitor output from Gamedig. --- lgsm/functions/command_monitor.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lgsm/functions/command_monitor.sh b/lgsm/functions/command_monitor.sh index 5c4ead99a..8b644b30c 100644 --- a/lgsm/functions/command_monitor.sh +++ b/lgsm/functions/command_monitor.sh @@ -12,7 +12,7 @@ local function_selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")") fn_monitor_check_lockfile(){ # Monitor does not run it lockfile is not found. - if [ ! -f "${lockdir}/${selfname}.lock" ]; then + if [ ! -f "${rootdir}/${lockselfname}" ]; then fn_print_dots "Checking lockfile: " fn_print_checking_eol fn_script_log_info "Checking lockfile: CHECKING" @@ -21,13 +21,13 @@ fn_monitor_check_lockfile(){ fn_print_error_eol_nl fn_script_log_error "Checking lockfile: No lockfile found: ERROR" fn_sleep_time - echo -en "* Start ${selfname} to run monitor." + echo -e "* Start ${selfname} to run monitor." core_exit.sh fi # Fix if lockfile is not unix time or contains letters - if [[ "$(cat "${lockdir}/${selfname}.lock")" =~ [A-Za-z] ]]; then - date '+%s' > "${lockdir}/${selfname}.lock" + if [[ "$(cat "${rootdir}/${lockselfname}")" =~ [A-Za-z] ]]; then + date '+%s' > "${rootdir}/${lockselfname}" fi } @@ -108,7 +108,7 @@ for queryattempt in {1..5}; do fn_script_log_info "Querying port: ${querymethod}: ${ip}:${queryport} : ${queryattempt} : QUERYING" fn_sleep_time # querydelay - if [ "$(cat "${lockdir}/${selfname}.lock")" -gt "$(date "+%s" -d "${querydelay} mins ago")" ]; then + if [ "$(cat "${rootdir}/${lockselfname}")" -gt "$(date "+%s" -d "${querydelay} mins ago")" ]; then fn_print_ok "Querying port: ${querymethod}: ${ip}:${queryport} : ${totalseconds}/${queryattempt}: " fn_print_delay_eol_nl fn_script_log_info "Querying port: ${querymethod}: ${ip}:${queryport} : ${queryattempt} : DELAY" @@ -147,6 +147,9 @@ for queryattempt in {1..5}; do if [ "${gdplayers}" ]; then fn_script_log_info "Players: ${gdplayers}/${gdmaxplayers}" fi + if [ "${gdbots}" ]; then + fn_script_log_info "Bots: ${gdbots}" + fi if [ "${gdmap}" ]; then fn_script_log_info "Map: ${gdmap}" fi @@ -236,7 +239,6 @@ info_parms.sh # query pre-checks fn_monitor_check_lockfile -check_last_update.sh fn_monitor_check_update fn_monitor_check_session # Monitor will not continue if session only check. From a2eb7f66e4a6149e85e95222771d9edf43570cb7 Mon Sep 17 00:00:00 2001 From: Jimmy Maple <38733055+jimmyatSplunk@users.noreply.github.com> Date: Sun, 12 Apr 2020 23:59:58 -0400 Subject: [PATCH 3/9] fix(messages): Fix to set proper component logging Fixed issue where messages from different actions weren't logging correctly due to using the wrong variable in when crafting the log message --- lgsm/functions/core_messages.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lgsm/functions/core_messages.sh b/lgsm/functions/core_messages.sh index da90ebc43..386ff1c7c 100644 --- a/lgsm/functions/core_messages.sh +++ b/lgsm/functions/core_messages.sh @@ -47,7 +47,7 @@ fn_sleep_time(){ fn_script_log(){ if [ -d "${lgsmlogdir}" ]; then if [ "${modulename}" ]; then - echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: ${commandname}: ${1}" >> "${lgsmlog}" + echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: ${commandaction}: ${1}" >> "${lgsmlog}" else echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: ${1}" >> "${lgsmlog}" fi @@ -59,7 +59,7 @@ fn_script_log_pass(){ if [ -d "${lgsmlogdir}" ]; then if [ "${modulename}" ]; then - echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: ${commandname}: PASS: ${1}" >> "${lgsmlog}" + echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: ${commandaction}: PASS: ${1}" >> "${lgsmlog}" else echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: PASS: ${1}" >> "${lgsmlog}" fi @@ -83,7 +83,7 @@ fn_script_log_fatal(){ fn_script_log_error(){ if [ -d "${lgsmlogdir}" ]; then if [ "${modulename}" ]; then - echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: ${commandname}: ERROR: ${1}" >> "${lgsmlog}" + echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: ${commandaction}: ERROR: ${1}" >> "${lgsmlog}" else echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: ERROR: ${1}" >> "${lgsmlog}" fi @@ -95,7 +95,7 @@ fn_script_log_error(){ fn_script_log_warn(){ if [ -d "${lgsmlogdir}" ]; then if [ "${modulename}" ]; then - echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: ${commandname}: WARN: ${1}" >> "${lgsmlog}" + echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: ${commandaction}: WARN: ${1}" >> "${lgsmlog}" else echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: WARN: ${1}" >> "${lgsmlog}" fi @@ -107,7 +107,7 @@ fn_script_log_warn(){ fn_script_log_info(){ if [ -d "${lgsmlogdir}" ]; then if [ "${modulename}" ]; then - echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: ${commandname}: INFO: ${1}" >> "${lgsmlog}" + echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: ${commandaction}: INFO: ${1}" >> "${lgsmlog}" else echo -e "$(date '+%b %d %H:%M:%S.%3N') ${selfname}: INFO: ${1}" >> "${lgsmlog}" fi From b0f782a6532a10cdebecc23cc91f4cb19a3bb08e Mon Sep 17 00:00:00 2001 From: Jimmy Maple Date: Mon, 13 Apr 2020 18:32:54 -0400 Subject: [PATCH 4/9] Confirm commit for changes made Commit changes made after pull change submiited. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 25996581a..6fecaea1a 100644 --- a/README.md +++ b/README.md @@ -60,3 +60,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! + From a6c2352ebc526d8a972b679d8c3996361e782ebf Mon Sep 17 00:00:00 2001 From: Jimmy Maple Date: Sun, 19 Apr 2020 00:28:19 -0400 Subject: [PATCH 5/9] fix(command_backup): Correct path for exludedir variable The current implementation doesn't use the full file path to determine the existence of the backup directory in relation to the server which means the current stats just looks for the "lgsm/backup" directory. That may work if you're already in the root directory for the server but if you're scripting the backups via cron, you're not likely going to be invoking the backup from the root directory. --- lgsm/functions/command_backup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lgsm/functions/command_backup.sh b/lgsm/functions/command_backup.sh index 5e84d76d1..99cd1237c 100644 --- a/lgsm/functions/command_backup.sh +++ b/lgsm/functions/command_backup.sh @@ -132,7 +132,7 @@ fn_backup_compression(){ excludedir=$(fn_backup_relpath) # Check that excludedir is a valid path. - if [ ! -d "${excludedir}" ] ; then + if [ ! -d "${rootdir}/${excludedir}" ] ; then fn_print_fail_nl "Problem identifying the previous backup directory for exclusion." fn_script_log_fatal "Problem identifying the previous backup directory for exclusion" core_exit.sh From f14600796f3d5ed511490ed97ad76cfb2c729675 Mon Sep 17 00:00:00 2001 From: Jimmy Maple Date: Tue, 2 Jun 2020 14:59:08 -0400 Subject: [PATCH 6/9] fix: query_gamedig.sh tuning for correct player count Reworked the jq flags to produce a count of players based on the length of the original JSON key used. However, I've found that while things like TF2 will produce the proper value, the Minecraft plugin will have an extra user online that is empty. See example below: "players": [ { "id": "81eeda65-9002-4f0d-9d3f-b4872e2a2042", "name": "iamjack1221" }, {} ] --- lgsm/functions/query_gamedig.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lgsm/functions/query_gamedig.sh b/lgsm/functions/query_gamedig.sh index 285cf0805..6e3a9122a 100644 --- a/lgsm/functions/query_gamedig.sh +++ b/lgsm/functions/query_gamedig.sh @@ -32,11 +32,15 @@ if [ "$(command -v gamedig 2>/dev/null)" ]&&[ "$(command -v jq 2>/dev/null)" ]; fi # numplayers. - gdplayers=$(echo "${gamedigraw}" | jq -re '.raw.vanilla.raw.players.online') + if [ "${querytype}" == "minecraft" ]; then + gdplayers=$(echo "${gamedigraw}" | jq -re '.players | length-1') + else + gdplayers=$(echo "${gamedigraw}" | jq -re '.players | length') + fi if [ "${gdplayers}" == "null" ]; then unset gdplayers - elif [ "${gdplayers}" == "[]" ]; then - gdplayers=0 + elif [ "${gdplayers}" == "[]" ] || [ "${gdplayers}" == "-1" ]; then + gdplayers=0 fi # maxplayers. @@ -60,7 +64,7 @@ if [ "$(command -v gamedig 2>/dev/null)" ]&&[ "$(command -v jq 2>/dev/null)" ]; fi # numbots. - gdbots=$(echo "${gamedigraw}" | jq -re '.raw.numbots') + gdbots=$(echo "${gamedigraw}" | jq -re '.bots | length') if [ "${gdbots}" == "null" ]||[ "${gdbots}" == "0" ]; then unset gdbots fi From 42758c8ae49a20142e7f43cafee6cf2267d50b54 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 17 Jun 2020 21:03:12 +0100 Subject: [PATCH 7/9] correct else --- lgsm/functions/query_gamedig.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lgsm/functions/query_gamedig.sh b/lgsm/functions/query_gamedig.sh index 6e3a9122a..29d5175a0 100644 --- a/lgsm/functions/query_gamedig.sh +++ b/lgsm/functions/query_gamedig.sh @@ -33,14 +33,14 @@ if [ "$(command -v gamedig 2>/dev/null)" ]&&[ "$(command -v jq 2>/dev/null)" ]; # numplayers. if [ "${querytype}" == "minecraft" ]; then - gdplayers=$(echo "${gamedigraw}" | jq -re '.players | length-1') - else - gdplayers=$(echo "${gamedigraw}" | jq -re '.players | length') + gdplayers=$(echo "${gamedigraw}" | jq -re '.players | length-1') + else + gdplayers=$(echo "${gamedigraw}" | jq -re '.players | length') fi if [ "${gdplayers}" == "null" ]; then unset gdplayers elif [ "${gdplayers}" == "[]" ] || [ "${gdplayers}" == "-1" ]; then - gdplayers=0 + gdplayers=0 fi # maxplayers. From 72db1e4ef84c36a6f2304383b1b56b02a4860a79 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Wed, 17 Jun 2020 21:04:54 +0100 Subject: [PATCH 8/9] space --- lgsm/functions/query_gamedig.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/lgsm/functions/query_gamedig.sh b/lgsm/functions/query_gamedig.sh index 29d5175a0..071645b49 100644 --- a/lgsm/functions/query_gamedig.sh +++ b/lgsm/functions/query_gamedig.sh @@ -22,7 +22,6 @@ if [ "$(command -v gamedig 2>/dev/null)" ]&&[ "$(command -v jq 2>/dev/null)" ]; gamedigcmd=$(echo -e "gamedig --type \"${querytype}\" --host \"${ip}\" --port \"${queryport}\"|jq") gamedigraw=$(gamedig --type "${querytype}" --host "${ip}" --port "${queryport}") querystatus=$(echo "${gamedigraw}" | jq '.error|length') - fi # server name. From 6f91a262bbc95a8aea4c9b090ab0e56a8a310581 Mon Sep 17 00:00:00 2001 From: Jimmy Maple <38733055+codingWithJimmy@users.noreply.github.com> Date: Tue, 31 Dec 2024 18:03:58 -0500 Subject: [PATCH 9/9] Update query_gamedig.sh - Re-worked if statement for Minecraft servers to not subtract 1 from the length of the player count. --- lgsm/functions/query_gamedig.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/lgsm/functions/query_gamedig.sh b/lgsm/functions/query_gamedig.sh index 071645b49..82939e917 100644 --- a/lgsm/functions/query_gamedig.sh +++ b/lgsm/functions/query_gamedig.sh @@ -32,8 +32,6 @@ if [ "$(command -v gamedig 2>/dev/null)" ]&&[ "$(command -v jq 2>/dev/null)" ]; # numplayers. if [ "${querytype}" == "minecraft" ]; then - gdplayers=$(echo "${gamedigraw}" | jq -re '.players | length-1') - else gdplayers=$(echo "${gamedigraw}" | jq -re '.players | length') fi if [ "${gdplayers}" == "null" ]; then