-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrlol.py
executable file
·150 lines (131 loc) · 4.47 KB
/
drlol.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
146
147
148
149
#!/usr/bin/python3
import configparser
from datetime import timedelta
import requests
import requests_cache
import json
from collections import OrderedDict
import cgi
from filelock import FileLock
from jsonmerge import merge, Merger
# store our config somewhere safe :)
path = '../../'
redis_store = 'drlol'
allowed_maps = {
'miami-lights',
'bell-labs',
'lapocalypse',
'gates-of-hell',
'campaign',
'bud-light-2017-tryouts',
'ohio-crash-site',
'ohio-crash-site-confirm-nor-deny',
'ohio-crash-site-restricted-area',
'gates-of-hell-shipyard',
'gates-of-hell-city',
'gates-of-hell-woods',
'bell-labs-project-noob',
'bell-labs-trinity-test',
'detroit',
'drl-sandbox',
'drl-sandbox-straight-line'
}
drl_map = cgi.FieldStorage().getvalue('map')
if drl_map is None:
print('Content-Type: application/json')
print()
print('{"code": 200, "maps": [\n"', end='')
print('",\n"'.join(allowed_maps), end='')
print('"')
print(']}')
sys.exit(0)
if not drl_map in allowed_maps:
print('Content-Type: application/json')
print()
print('{"code":404, "nope":true}')
sys.exit(0)
config = configparser.ConfigParser()
config.read(path + 'drlol.conf')
username = config['drlol']['username']
password = config['drlol']['password']
cache_time = timedelta(seconds=int(config['drlol']['cache_time']))
requests_cache.install_cache(redis_store, backend='redis', allowable_methods=('GET', 'POST'), expire_after=cache_time)
title_id = "891F"
login_url = 'https://' + title_id + '.playfabapi.com/Client/LoginWithPlayFab'
login_headers = {
'Host': title_id + '.playfabapi.com',
'User-Agent': 'UnityPlayer/5.4.0f3 (http://unity3d.com)',
'Accept': '*/*',
'Accept-Encoding': 'identity',
'Content-Type': 'application/json',
'X-PlayFabSDK': 'UnitySDK-2.5.160815',
'X-ReportErrorAsSuccess': 'true',
'X-Unity-Version': '5.4.0f3'
}
# if we don't order these, caching doesn't work as python dicts have aribtrary order
login_headers = OrderedDict(sorted(login_headers.items()))
login_payload = {
'TitleId': title_id,
'Username': username,
'Password': password,
'InfoRequestParameters': 'null'
}
login_payload = OrderedDict(sorted(login_payload.items()))
with FileLock("login.lock"):
r = requests.post(login_url, headers=login_headers, data=json.dumps(login_payload))
r = r.json()
session_ticket = r['data']['SessionTicket']
leaderboard_url = 'https://' + title_id + '.playfabapi.com/Client/GetLeaderBoard'
leaderboard_headers = {
'Host': title_id + '.playfabapi.com',
'Content-Type': 'application/json',
'X-Authorization': session_ticket,
'X-PlayFabSDK': 'UnitySDK-2.5.160815',
'X-ReportErrorAsSuccess': 'true',
'X-Unity-Version': '5.4.0f3'
}
leaderboard_headers = OrderedDict(sorted(leaderboard_headers.items()))
if drl_map == 'campaign':
drl_map_full = 'SP.CP.TotalTime'
elif drl_map == 'bud-light-2017-tryouts':
drl_map_full = 'SP.TO.A21.TotalTime'
elif drl_map == 'gates-of-hell-shipyard':
drl_map_full = 'SP.RC.gates-of-hell.race-01.TotalTime'
elif drl_map == 'gates-of-hell-city':
drl_map_full = 'SP.RC.gates-of-hell.race-02.TotalTime'
elif drl_map == 'gates-of-hell-woods':
drl_map_full = 'SP.RC.gates-of-hell.race-03.TotalTime'
elif drl_map == 'bell-labs-project-noob':
drl_map_full = 'SP.RC.bell-labs.race-01.TotalTime'
elif drl_map == 'bell-labs-trinity-test':
drl_map_full = 'SP.RC.bell-labs.race-02.TotalTime'
elif drl_map == 'drl-sandbox-straight-line':
drl_map_full = 'SP.RC.drl-sandbox.straigh-line.TotalTime'
elif drl_map == 'ohio-crash-site-confirm-nor-deny':
drl_map_full = 'SP.RC.ohio-crash-site.race-01.TotalTime'
elif drl_map == 'ohio-crash-site-restricted-area':
drl_map_full = 'SP.RC.ohio-crash-site.race-02.TotalTime'
else:
drl_map_full = 'SP.RC.' + drl_map + '.race.TotalTime'
# magic
schema = { 'properties': { 'data': { 'properties': { 'Leaderboard': { 'mergeStrategy': 'append' }}}}}
merger = Merger(schema)
full_leaderboard = None
start_position = 0
pilots = 99
while (pilots == 99):
# anything over 99 gives back an error ¯\_(ツ)_/¯
leaderboard_payload = {
'StatisticName': drl_map_full,
'StartPosition': start_position,
'MaxResultsCount': 99
}
leaderboard_payload = OrderedDict(sorted(leaderboard_payload.items()))
r = requests.post(leaderboard_url, headers=leaderboard_headers, data=json.dumps(leaderboard_payload))
r = r.json()
full_leaderboard = merger.merge(full_leaderboard, r)
start_position = start_position + 99
pilots = len(r['data']['Leaderboard'])
print("Content-Type: application/json")
print()
print(json.dumps(full_leaderboard))