-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmhserverresponse.py
More file actions
63 lines (53 loc) · 1.53 KB
/
mhserverresponse.py
File metadata and controls
63 lines (53 loc) · 1.53 KB
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
#!/usr/bin/python
# Author: shade (Copyright C 2013)
#
# License: http://www.wtfpl.net/txt/copying/
import json
class MHServerResponse:
status = None
error = None
# data --
# |-- have_bait
# |-- time_to_horn
# |-- catch -------
# |-- status
# |-- mouse
# |-- loot
# |-- gold
# |-- points
# |-- damage
# |-- player
# |-- TBD
#
# data will be raw response in case of errors
data = None
def __init__(self, response):
response = json.loads(response.rstrip())
if "error" in response:
if response['error']['code'] == 100:
self.status = "login"
self.error = response['error']['message']
elif response['error']['code'] == 400:
self.status = "warn"
self.error = response['error']['message']
elif response['error']['code'] == 80:
self.status = "update"
self.error = "Need game version update"
else:
self.status = "ok"
if "user" not in response:
self.status = "error"
self.error = "No user object present. Somethign is wrong"
self.data = raw_response
else:
self.data = {
"have_bait": response["user"]["trap"]["bait_id"] is not None,
"time_to_horn": response["user"]["next_activeturn_seconds"],
"catch": {
"status": response["user"]["trap"]["last_activity"]["class_name"],
"mouse": response["user"]["trap"]["last_activity"]["mouse"],
"gold": response["user"]["trap"]["last_activity"]["gold"],
"points": response["user"]["trap"]["last_activity"]["points"],
"loot": response["user"]["trap"]["last_activity"]["loot"]
}
}