Merge pull request #55 from blha303/develop
Add Minecraft colours to .mcping
This commit is contained in:
commit
6516caccdc
1 changed files with 11 additions and 2 deletions
|
@ -3,6 +3,14 @@ import socket
|
|||
import json
|
||||
import struct
|
||||
|
||||
def mccolorconvert(motd):
|
||||
empty = ""
|
||||
colors = [u"\x0300,\xa7f", u"\x0301,\xa70", u"\x0302,\xa71", u"\x0303,\xa72", u"\x0304,\xa7c", u"\x0305,\xa74", u"\x0306,\xa75", u"\x0307,\xa76", u"\x0308,\xa7e", u"\x0309,\xa7a", u"\x0310,\xa73", u"\x0311,\xa7b", u"\x0312,\xa71", u"\x0313,\xa7d", u"\x0314,\xa78", u"\x0315,\xa77", u"\x02,\xa7l", u"\x0310,\xa79", u"\x09,\xa7o", u"\x13,\xa7m", u"\x0f,\xa7r", u"\x15,\xa7n"];
|
||||
for s in colors:
|
||||
lcol = s.split(",")
|
||||
motd = motd.replace(lcol[1], lcol[0])
|
||||
motd = motd.replace(u"\xa7k", empty)
|
||||
return motd
|
||||
|
||||
def mcping_connect(host, port):
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
@ -25,7 +33,7 @@ def mcping_connect(host, port):
|
|||
message = u"{} - {}/{} players".format(data[0], data[1], data[2])
|
||||
else:
|
||||
# decoded data, server is using new format
|
||||
message = u"{} - {} - {}/{} players".format(data[3], data[2], data[4], data[5])
|
||||
message = u"{} \x0f- {} - {}/{} players".format(data[3], data[2], data[4], data[5])
|
||||
|
||||
sock.close()
|
||||
return message
|
||||
|
@ -107,4 +115,5 @@ def mcping(inp):
|
|||
else:
|
||||
host = inp
|
||||
port = 25565
|
||||
return mcping_connect(host, port)
|
||||
return mccolorconvert(mcping_connect(host, port))
|
||||
|
||||
|
|
Reference in a new issue