From f224730d3f9e3eb5220d27d9ad50aef53d352f11 Mon Sep 17 00:00:00 2001 From: "Jason M. Wood" Date: Sun, 2 Nov 2014 22:36:18 -0700 Subject: [PATCH] query: merge queryDetailedStatus and querySendDetailedInformationPacket --- minecraft_server | 65 ++++++++---------------------------------------- 1 file changed, 10 insertions(+), 55 deletions(-) diff --git a/minecraft_server b/minecraft_server index 0278419..0a96748 100755 --- a/minecraft_server +++ b/minecraft_server @@ -1512,56 +1512,6 @@ querySendInformationPacket() { printf "$RESPONSE\n" } -# --------------------------------------------------------------------------- -# Send a detailed information request packet to the Minecraft query server. -# -# @param 1 The world server of interest. -# @param 2 The challenge token. -# @return Tab separated values: -# type - The packet type. -# id - The packet identifier. -# * - The string 'splitnum'. -# * - The value 128. -# * - The value 0. -# * - The string 'hostname'. -# MOTD - The world's message of the day. -# * - The string 'gametype'. -# gametype - The world's game type, hardcoded to 'SMP'. -# * - The string 'game_id'. -# gameid - The world's game ID, hardcoded to 'MINECRAFT'. -# * - The string 'version'. -# version - The world's Minecraft version. -# * - The string 'plugins'. -# plugins - The world's plugins. -# * - The string 'map'. -# map - The world's name. -# * - The string 'numplayers'. -# numplayers - The world's current number of players. -# * - The string 'maxplayers'. -# maxplayers - The world's maximum number of players. -# * - The string 'hostport'. -# hostport - The world's host port. -# * - The string 'hostip'. -# hostip - The world's host IP address. -# * - The value 0. -# * - The value 1. -# * - The string 'player_'. -# * - The value 0. -# players - The players currently logged onto the world. -# --------------------------------------------------------------------------- -querySendDetailedInformationPacket() { - local ID PACKET RESPONSE - # The packet identifier. - ID="00000001" - # Use the challenge token for the packet, with the ID on the end. - PACKET=$(printf "%.8x%s" $2 $ID) - # Send the information request packet to the Minecraft query server. - RESPONSE=$(querySendPacket "$1" "00" "$PACKET" \ - "Cl>Z*CCZ*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*CCZ*C(Z*)*") - # Return the response. - printf "$RESPONSE\n" -} - # --------------------------------------------------------------------------- # Send a status query to the Minecraft query server. # @@ -1628,13 +1578,18 @@ queryStatus() { # players - The players currently logged onto the world. # --------------------------------------------------------------------------- queryDetailedStatus() { - local TOKEN RESPONSE + local CHALLENGE ID PACKET RESPONSE TOKEN if [ "$(getPropertiesValue $1 'enable-query')" = "true" ]; then # Send a challenge packet to the Minecraft query server. - TOKEN=$(querySendChallengePacket $1 | cut -f 3) - if [ -n "$TOKEN" ]; then - # Send an information request packet to the Minecraft query server. - RESPONSE=$(querySendDetailedInformationPacket $1 $TOKEN) + CHALLENGE=$(querySendChallengePacket $1) + ID=$(echo "$CHALLENGE" | cut -f 2) + TOKEN=$(echo "$CHALLENGE" | cut -f 3) + if [ -n "$ID" ] && [ -n "$TOKEN" ]; then + # Use the challenge token for the packet, with the ID on the end. + PACKET=$(printf "%.8x%.8x" $TOKEN $ID) + # Send the information request packet to the Minecraft query server. + RESPONSE=$(querySendPacket "$1" "00" "$PACKET" \ + "Cl>Z*CCZ*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*CCZ*C(Z*)*") fi fi # Return the response.