Skip to content

Commit

Permalink
msctl: fix spacing in query results
Browse files Browse the repository at this point in the history
  • Loading branch information
sandain committed Jun 24, 2018
1 parent 6ee2e55 commit 37a4258
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions msctl
Original file line number Diff line number Diff line change
Expand Up @@ -1849,10 +1849,19 @@ queryDetailedStatus() {
# @return Query values in JSON format.
# ---------------------------------------------------------------------------
queryDetailedStatusJSON() {
local STATUS JSON PLAYERS COUNTER
local STATUS JSON MOTD GAMETYPE GAMEID VERSION PLUGINS MAP NUMPLAYERS MAXPLAYERS HOSTPORT HOSTIP PLAYERS COUNTER
STATUS=$(queryDetailedStatus $1)
if [ -n "$STATUS" ]; then
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)
if [ $NUMPLAYERS -gt 0 ]; then
PLAYERS=$(printf "%s\"" "$PLAYERS" $(printf "%s" "$STATUS" | cut -f $((30))))
COUNTER=1
Expand All @@ -1861,23 +1870,11 @@ queryDetailedStatusJSON() {
COUNTER=$(($COUNTER+1))
done
fi
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": '$NUMPLAYERS',
"maxplayers": '$(printf "%s" "$STATUS" | cut -f 21)',
"hostport": "'$(printf "%s" "$STATUS" | cut -f 23)'",
"hostip": "'$(printf "%s" "$STATUS" | cut -f 25)'",
"players": ['$PLAYERS']
}'
JSON="{\"motd\":\"$MOTD\",\"gametype\":\"$GAMETYPE\",\"gameid\":\"$GAMEID\",\"version\":\"$VERSION\",\"plugins\":\"$PLUGINS\",\"map\":\"$MAP\",\"numplayers\":$NUMPLAYERS,\"maxplayers\":$MAXPLAYERS,\"hostport\":\"$HOSTPORT\",\"hostip\":\"$HOSTIP\",\"players\":[$PLAYERS]}"
else
JSON="{}"
fi
printf "%s" $JSON
printf "%s" "$JSON"
}

# ---------------------------------------------------------------------------
Expand Down

0 comments on commit 37a4258

Please sign in to comment.