Fix typing error and small rename

This commit is contained in:
Kevin Tindall
2022-02-06 08:08:04 -06:00
parent f7c9350ee7
commit 0d5173d8a8

View File

@@ -136,11 +136,12 @@ class QueryResponse:
while True:
key = response.read_ascii()
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
if key == "hostname": # hostname is actually motd in the query protocol
match = re.search(b"(.*)\x00gametype", response.received, flags=re.DOTALL)
motd = match.group(1) if match else ""
# Since the query protocol does not properly support unicode, the motd is still not resolved
# correctly; however, this will avoid other parameter parsing errors.
data[key] = response.read(len(name)).decode("ISO-8859-1")
data[key] = response.read(len(motd)).decode("ISO-8859-1")
response.read(1) # ignore null byte
elif len(key) == 0:
response.read(1)
@@ -152,9 +153,9 @@ class QueryResponse:
response.read(len("player_") + 1 + 1)
while True:
name = response.read_ascii()
if len(name) == 0:
motd = response.read_ascii()
if len(motd) == 0:
break
players.append(name)
players.append(motd)
return cls(data, players)