mirror of
https://github.com/Dinnerbone/mcstatus.git
synced 2026-04-06 03:51:23 +08:00
fix2 motd unicode parse error
https://github.com/Dinnerbone/mcstatus/pull/192#discussion_r800116287
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import random
|
import random
|
||||||
import struct
|
import struct
|
||||||
|
import re
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from mcstatus.protocol.connection import Connection
|
from mcstatus.protocol.connection import Connection
|
||||||
@@ -128,27 +129,18 @@ class QueryResponse:
|
|||||||
data = {}
|
data = {}
|
||||||
players = []
|
players = []
|
||||||
|
|
||||||
# If hostname is set to unicode, using other parameters of read_ascii() may be in the wrong order
|
|
||||||
key = response.received[:8].decode('ISO-8859-1')
|
|
||||||
if key == 'hostname':
|
|
||||||
response.read_ascii()
|
|
||||||
name = bytearray()
|
|
||||||
while True:
|
|
||||||
c = response.read(1)
|
|
||||||
name += c
|
|
||||||
if c[0] == 0:
|
|
||||||
if response.received[:8].decode('ISO-8859-1') == 'gametype':
|
|
||||||
name.pop()
|
|
||||||
break
|
|
||||||
# Since the minecraft protocol does not support unicode, the hostname is still not resolved correctly
|
|
||||||
# However, this will avoid other parameter parsing errors
|
|
||||||
data[key] = name.decode('ISO-8859-1')
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
key = response.read_ascii()
|
key = response.read_ascii()
|
||||||
if len(key) == 0:
|
if key == "hostname":
|
||||||
|
name = re.search(b"(.*)\x00gametype", response.received, flags=re.DOTALL).group(1)
|
||||||
|
# Since the query protocol does not properly support unicode, the hostname is still not resolved
|
||||||
|
# correctly; however, this will avoid other parameter parsing errors.
|
||||||
|
data[key] = response.read(len(name)).decode("ISO-8859-1")
|
||||||
|
response.read(1) # ignore null byte
|
||||||
|
elif len(key) == 0:
|
||||||
response.read(1)
|
response.read(1)
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
value = response.read_ascii()
|
value = response.read_ascii()
|
||||||
data[key] = value
|
data[key] = value
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user