This repository has been archived by the owner on Oct 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.py
75 lines (71 loc) · 2.34 KB
/
data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import json
from datetime import datetime
class ActiveServer():
def __init__(self) -> None:
self.server_name = ""
self.host = ""
self.machine_address = ""
self.player_count = 0
self.player_limit = 0
self.server_port = 0
self.server_motd_preview = ""
self.server_motd_content = ""
self.custom_password = False
self.ttl = 0
self.authorization = ""
# True if accepted,
# False if they're trying to pull a fast one on us
def fromJson(self, _json):
data = json.loads(_json)
if "PlayerCount" not in data or type(data["PlayerCount"]) is not int:
print("bad playercount")
return False
if "PlayerLimit" not in data or type(data["PlayerLimit"]) is not int:
print("bad playerlimit")
return False
if "CustomPassword" not in data or type(data["CustomPassword"]) is not bool:
print("missing custompassword")
return False
if "ServerPort" not in data or type(data["ServerPort"]) is not int:
print("missing serverport")
return False
if "Authorization" not in data:
print("missing authorization")
return False
if "MotdContent" not in data:
print("missing motdcontent")
return False
if "MotdPreview" not in data:
print("missing motdpreview")
return False
if "ServerName" not in data:
print("missing servername")
return False
if "Host" not in data:
print("missing host")
return False
self.server_name = data["ServerName"]
self.server_motd_content = data["MotdContent"]
self.server_motd_preview = data["MotdPreview"]
self.player_count = data["PlayerCount"]
self.player_limit = data["PlayerLimit"]
self.authorization = data["Authorization"]
self.custom_password = data["CustomPassword"]
self.ttl = datetime.now().timestamp() + 120
self.host = data["Host"]
self.server_port = data["ServerPort"]
return True
def toJson(self) -> str:
obj = {
"ServerName": self.server_name,
"MotdContent": self.server_motd_content,
"MotdPreview": self.server_motd_preview,
"PlayerCount": self.player_count,
"PlayerLimit": self.player_limit,
"CustomPassword": self.custom_password,
"MachineAddress": self.machine_address,
"ServerPort": self.server_port,
"Host": self.host,
"GUID": "x"
}
return json.dumps(obj)