Open sandain opened 8 years ago
I think the query command could use a format we can parse with JavaScript like json so it would be easier to use the output. Or maybe make another perl script that will convert the output to json.
Why don't we add an option to the query
command, say query json
, that returns the same query data in json format. I imagine the conversion code would be fairly minimal. We could define the option raw
as the default format that is currently returned.
I have something working I think:
$ mscs query-json alpha
{"motd":"Thisisamultiple\nlineMOTD","gametype":"SMP","gameid":"MINECRAFT","version":"1.9","plugins":"","map":"alpha","numplayers":0,"maxplayers":20,"hostport":"25567","hostip":"127.0.0.1","players":""}
Is that what you were thinking of? Do I need to add whitespace? I could convert players
to an array, but I don't have a second account to play with and don't know if it is comma separated or what
Here is the main part of the code:
# Send a detailed status query to the Minecraft query server and return the
# data in JSON format.
#
# @param 1 The world server of interest.
# @return Query values in JSON format.
queryDetailedStatusJSON() {
local STATUS JSON
STATUS=$(queryDetailedStatus $1)
if [ -n "$STATUS" ]; then
JSON='{
"motd": "'$(printf "%s" "$STATUS" | cut -f 7)'",
"gametype": "'$(printf "%s" "$STATUS" | cut -f 9)'",
"gameid": "'$(printf "%s" "$STATUS" | cut -f 11)'",
"version": "'$(printf "%s" "$STATUS" | cut -f 13)'",
"plugins": "'$(printf "%s" "$STATUS" | cut -f 15)'",
"map": "'$(printf "%s" "$STATUS" | cut -f 17)'",
"numplayers": '$(printf "%s" "$STATUS" | cut -f 19)',
"maxplayers": '$(printf "%s" "$STATUS" | cut -f 21)',
"hostport": "'$(printf "%s" "$STATUS" | cut -f 23)'",
"hostip": "'$(printf "%s" "$STATUS" | cut -f 25)'",
"players": "'$(printf "%s" "$STATUS" | cut -f 30)'"
}'
else
JSON="{}"
fi
printf "%s" $JSON
}
White space is not needed and is more efficient without it. Arrays or objects would be preferred for multi value elements.
Commit MinecraftServerControl/mscs@772116caff575ee228fd1caba8d3a7a7fa9c9711 added the query-json
command to mscs.
Commit MinecraftServerControl/mscs@ecf61a3e894ccb8930e119f86fb218c69ab57954 added the status-json
command to mscs.
What else do we need from mscs?
My local branch is currently using
ls
and the newquery
command.