-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayloadparser.py
145 lines (137 loc) · 6.73 KB
/
payloadparser.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
class PayloadParser:
def parse_payload(self, payload, gamestate_manager):
change_flags = {}
# Parse round information
if "round" in payload and "phase" in payload["round"]:
roundchanged = False
if payload["round"]["phase"] != gamestate_manager.gamestate.round_phase:
gamestate_manager.gamestate.update_round_phase(
payload["round"]["phase"]
)
roundchanged = True
if payload["round"]["phase"] != "live" and not roundchanged:
return None
# Parse map information
if "map" in payload:
map_info = payload["map"]
if "mode" in map_info:
gamestate_manager.gamestate.map.mode = map_info["mode"]
if "name" in map_info:
gamestate_manager.gamestate.map.name = map_info["name"]
if "phase" in map_info:
gamestate_manager.gamestate.map.phase = map_info["phase"]
if "round" in map_info:
gamestate_manager.gamestate.map.round = map_info["round"]
if "team_ct" in map_info:
ct_info = map_info["team_ct"]
if "score" in ct_info:
gamestate_manager.gamestate.map.team_ct.score = ct_info["score"]
if "timeouts_remaining" in ct_info:
gamestate_manager.gamestate.map.team_ct.timeouts_remaining = (
ct_info["timeouts_remaining"]
)
if "matches_won_this_series" in ct_info:
gamestate_manager.gamestate.map.team_ct.matches_won_this_series = (
ct_info["matches_won_this_series"]
)
if "team_t" in map_info:
t_info = map_info["team_t"]
if "score" in t_info:
gamestate_manager.gamestate.map.team_t.score = t_info["score"]
if "timeouts_remaining" in t_info:
gamestate_manager.gamestate.map.team_t.timeouts_remaining = t_info[
"timeouts_remaining"
]
if "matches_won_this_series" in t_info:
gamestate_manager.gamestate.map.team_t.matches_won_this_series = (
t_info["matches_won_this_series"]
)
if "num_matches_to_win_series" in map_info:
gamestate_manager.gamestate.map.num_matches_to_win_series = map_info[
"num_matches_to_win_series"
]
if "current_spectators" in map_info:
gamestate_manager.gamestate.map.current_spectators = map_info[
"current_spectators"
]
if "souvenirs_total" in map_info:
gamestate_manager.gamestate.map.souvenirs_total = map_info[
"souvenirs_total"
]
# Parse player information
if "player" in payload:
player_info = payload["player"]
if "steamid" in player_info:
gamestate_manager.gamestate.player.steamid = player_info["steamid"]
if "name" in player_info:
gamestate_manager.gamestate.player.name = player_info["name"]
if "observer_slot" in player_info:
gamestate_manager.gamestate.player.observer_slot = player_info[
"observer_slot"
]
if "activity" in player_info:
gamestate_manager.gamestate.player.activity = player_info["activity"]
if "state" in player_info:
state_info = player_info["state"]
if "health" in state_info:
gamestate_manager.gamestate.player.state.health = state_info[
"health"
]
if "armor" in state_info:
gamestate_manager.gamestate.player.state.armor = state_info["armor"]
if "helmet" in state_info:
gamestate_manager.gamestate.player.state.helmet = state_info[
"helmet"
]
if "flashed" in state_info:
gamestate_manager.gamestate.player.state.flashed = state_info[
"flashed"
]
if "smoked" in state_info:
gamestate_manager.gamestate.player.state.smoked = state_info[
"smoked"
]
if "burning" in state_info:
gamestate_manager.gamestate.player.state.burning = state_info[
"burning"
]
if "money" in state_info:
gamestate_manager.gamestate.player.state.money = state_info["money"]
if "round_kills" in state_info:
kills = int(state_info["round_kills"])
if gamestate_manager.gamestate.player.state.round_kills != kills:
gamestate_manager.gamestate.update_round_kills(kills)
if "round_killhs" in state_info:
gamestate_manager.gamestate.player.state.round_killhs = state_info[
"round_killhs"
]
if "equip_value" in state_info:
gamestate_manager.gamestate.player.state.equip_value = state_info[
"equip_value"
]
if "weapons" in player_info:
gamestate_manager.gamestate.player.weapons = player_info["weapons"]
if player_info["weapons"] != gamestate_manager.gamestate.player.weapons:
gamestate_manager.gamestate.player.weapons = player_info["weapons"]
if "match_stats" in player_info:
match_stats = player_info["match_stats"]
if "kills" in match_stats:
gamestate_manager.gamestate.player.match_stats.kills = match_stats[
"kills"
]
if "assists" in match_stats:
gamestate_manager.gamestate.player.match_stats.assists = (
match_stats["assists"]
)
if "deaths" in match_stats:
gamestate_manager.gamestate.player.match_stats.deaths = match_stats[
"deaths"
]
if "mvps" in match_stats:
gamestate_manager.gamestate.player.match_stats.mvps = match_stats[
"mvps"
]
if "score" in match_stats:
gamestate_manager.gamestate.player.match_stats.score = match_stats[
"score"
]