mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-18 17:15:13 +01:00
Fix malformed data errors
This commit is contained in:
parent
d145dd595b
commit
9f5a214b60
@ -77,8 +77,8 @@ class Server:
|
|||||||
class Players(list):
|
class Players(list):
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
super().__init__(Player(x) for x in data.get("sample", []))
|
super().__init__(Player(x) for x in data.get("sample", []))
|
||||||
self.max = data["max"]
|
self.max = data.get("max", 0)
|
||||||
self.online = data["online"]
|
self.online = data.get("online", 0)
|
||||||
|
|
||||||
def report(self):
|
def report(self):
|
||||||
players = []
|
players = []
|
||||||
@ -93,8 +93,8 @@ class Players(list):
|
|||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.id = data["id"]
|
self.id = data.get("id", "")
|
||||||
self.name = data["name"]
|
self.name = data("name", "Anonymous")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@ -174,7 +174,7 @@ def ping(ip, port):
|
|||||||
logger.debug(f"Server reports this data on ping: {data}")
|
logger.debug(f"Server reports this data on ping: {data}")
|
||||||
try:
|
try:
|
||||||
return Server(json.loads(data))
|
return Server(json.loads(data))
|
||||||
except KeyError:
|
except (KeyError, json.decoder.JSONDecodeError):
|
||||||
return {}
|
return {}
|
||||||
finally:
|
finally:
|
||||||
sock.close()
|
sock.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user