Added server version checking to .mcping
This commit is contained in:
parent
a500cead3b
commit
4cbf4df572
1 changed files with 6 additions and 5 deletions
|
@ -8,15 +8,16 @@ def mcping_connect(host, port):
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
try:
|
try:
|
||||||
sock.connect((host, port))
|
sock.connect((host, port))
|
||||||
sock.send('\xfe')
|
sock.send('\xfe\x01')
|
||||||
response = sock.recv(1)
|
response = sock.recv(1)
|
||||||
if response != '\xff':
|
|
||||||
|
if response[0] != '\xff':
|
||||||
return "Server gave invalid response: " + repr(response)
|
return "Server gave invalid response: " + repr(response)
|
||||||
length = struct.unpack('!h', sock.recv(2))[0]
|
length = struct.unpack('!h', sock.recv(2))[0]
|
||||||
values = sock.recv(length * 2).decode('utf-16be').split(u'\xa7')
|
values = sock.recv(length * 2).decode('utf-16be').split(u'\x00')
|
||||||
|
|
||||||
sock.close()
|
sock.close()
|
||||||
return "%s - %d/%d players"\
|
return u"{} - Minecraft {} - {}/{} players".format(values[3], values[2], values[4], values[5])
|
||||||
% (values[0], int(values[1]), int(values[2]))
|
|
||||||
except:
|
except:
|
||||||
return "Error pinging " + host + ":" + str(port) +\
|
return "Error pinging " + host + ":" + str(port) +\
|
||||||
", is it up? Double-check your address!"
|
", is it up? Double-check your address!"
|
||||||
|
|
Reference in a new issue