Преглед изворни кода

fix(query): query_gamedig.sh tuning for correct player count (#2913)

* 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.

* feat(monitor): Include bot count in monitor output

Update to include bot count in monitor output from Gamedig.

* 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

* Confirm commit for changes made

Commit changes made after pull change submiited.

* 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.

* 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"
    },
    {}
  ]

* correct else

* space

Co-authored-by: Daniel Gibbs <me@danielgibbs.co.uk>
Jimmy Maple пре 6 година
родитељ
комит
dc70753ead
1 измењених фајлова са 7 додато и 4 уклоњено
  1. 7 4
      lgsm/functions/query_gamedig.sh

+ 7 - 4
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.
@@ -32,10 +31,14 @@ 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
+		elif [ "${gdplayers}" == "[]" ] || [ "${gdplayers}" == "-1" ]; then
 			gdplayers=0
 		fi
 
@@ -60,7 +63,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