-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathgetUser.php
309 lines (270 loc) · 6.45 KB
/
getUser.php
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
include ("config.php");
if (empty($_GET)) {
print "ERROR: Wrong usage";
die();
}
if (!isset($_GET["appcode"])) {
print "ERROR: Wrong appcode";
die();
}
if ($_GET["appcode"] != $config["appcode"]) {
print "ERROR: Wrong appcode";
die();
}
if (!isset($_GET["id"]) && !isset($_GET["name"])) {
print "ERROR: Wrong usage";
die();
}
$loadProgression = $config["default-progression"];
if (isset($_GET["progression"]))
$loadProgression = $_GET["progression"];
if ($loadProgression != "true" && $loadProgression != "false")
$loadProgression = $config["default-progression"];
include ("UbiAPI.php");
$uapi = new UbiAPI($config["ubi-email"], $config["ubi-password"]);
$data = array();
$region = $config["default-region"];
$season = -1;
if (isset($_GET['season']))
$season = $_GET['season'];
$platform = $config["default-platform"];
if (isset($_GET['platform']))
$platform = $_GET['platform'];
if (isset($_GET['region']))
$region = $_GET['region'];
$notFound = [];
function printName($pid) {
global $uapi, $data, $id, $platform, $notFound;
$su = $uapi->searchUser("byid", $pid, $platform);
if ($su["error"] != true) {
$data[$su['pid']] = array(
"profile_id" => $su['pid'],
"user_id" => $su['uid'],
"nickname" => $su['nick']
);
} else {
$notFound[$pid] = [
"profile_id" => $pid,
"error" => [
"message" => "User not found!"
]
];
}
}
function printID($name) {
global $uapi, $data, $id, $platform, $notFound;
$su = $uapi->searchUser("bynick", $name, $platform);
if ($su["error"] != true) {
$data[$su['pid']] = array(
"profile_id" => $su['pid'],
"user_id" => $su['uid'],
"nickname" => $su['nick']
);
} else {
$notFound[$name] = [
"nickname" => $name,
"error" => [
"message" => "User not found!"
]
];
}
}
if (isset($_GET["id"])) {
$str = $_GET["id"];
if (strpos($str, ',') !== false)
$tocheck = explode(',', $str);
else {
$tocheck = array(
$str
);
}
foreach($tocheck as $value)
printName($value);
}
if (isset($_GET["name"])) {
$str = $_GET["name"];
if (strpos($str, ',') !== false)
$tocheck = explode(',', $str);
else {
$tocheck = array(
$str
);
}
foreach($tocheck as $value)
printID($value);
}
if (empty($data)) {
$error = $uapi->getErrorMessage();
if ($error === false) {
die(json_encode(array(
"players" => $notFound
)));
} else {
die(json_encode(array(
"players" => array(),
"error" => $error
)));
}
}
function getValue($user, $progression) {
foreach($progression as $usera) {
if ($usera["profile_id"] == $user)
return $usera;
}
return array();
}
$ids = "";
foreach($data as $value)
$ids = $ids . "," . $value["profile_id"];
$ids = substr($ids, 1);
$idresponse = json_decode($uapi->getRanking($ids, $season, $region, $platform), true);
if ($loadProgression == "true") {
$progressionJson = json_decode($uapi->getProgression($ids, $platform), true);
if (is_null($progressionJson) || !array_key_exists("player_profiles", $progressionJson)) {
die(json_encode(array(
"players" => $notFound
)));
}
$progression = $progressionJson["player_profiles"];
}
function getRankImage($rank, $png) {
return 'https://api.statsdb.net/r6/assets/ranks/' . ($png ? 'png/' : '') . $rank;
}
function getRankName($rank) {
switch($rank) {
case 0: return "Unranked";
case 1: return "Copper V";
case 2: return "Copper IV";
case 3: return "Copper III";
case 4: return "Copper II";
case 5: return "Copper I";
case 6: return "Bronze V";
case 7: return "Bronze IV";
case 8: return "Bronze III";
case 9: return "Bronze II";
case 10: return "Bronze I";
case 11: return "Silver V";
case 12: return "Silver IV";
case 13: return "Silver III";
case 14: return "Silver II";
case 15: return "Silver I";
case 16: return "Gold III";
case 17: return "Gold II";
case 18: return "Gold I";
case 19: return "Platinum III";
case 20: return "Platinum II";
case 21: return "Platinum I";
case 22: return "Diamond III";
case 23: return "Diamond II";
case 24: return "Diamond I";
case 25: return "Champion";
default: return null;
}
}
function getRankArray($rank, $png) {
return [
'image' => getRankImage($rank, $png),
'name' => getRankName($rank)
];
}
$final = array();
if (!isset($idresponse)) {
die(json_encode(array(
"players" => $notFound
)));
}
if (!array_key_exists("players", $idresponse)) {
die(json_encode(array(
"players" => $notFound
)));
}
function getSeasonName($seasonId) {
$season_name = "";
switch($seasonId) {
case 6:
$season_name = "Health";
break;
case 7:
$season_name = "Blood Orchid";
break;
case 8:
$season_name = "White Noise";
break;
case 9:
$season_name = "Chimera";
break;
case 10:
$season_name = "Para Bellum";
break;
case 11:
$season_name = "Grim Sky";
break;
case 12:
$season_name = "Wind Bastion";
break;
case 13:
$season_name = "Burnt Horizon";
break;
case 14:
$season_name = "Phantom Sight";
break;
case 15:
$season_name = "Ember Rise";
break;
case 16:
$season_name = "Shifting Tides";
break;
case 17:
$season_name = "Void Edge";
break;
case 18:
$season_name = "Steel Wave";
break;
case 19:
$season_name = "Shadow Legacy";
break;
case 20:
$season_name = "Neon Dawn";
break;
case 21:
$season_name = "Crimson Heist";
break;
case 22:
$season_name = "North Star";
break;
case 23:
$season_name = "Crystal Guard";
break;
case 24:
$season_name = "High Calibre";
break;
case 25:
$season_name = "Demon Veil";
break;
case 26:
$season_name = "Vector Glare";
break;
case 27:
$season_name = "Brutal Swarm";
break;
}
return $season_name;
}
foreach($idresponse["players"] as $value) {
$id = $value["profile_id"];
$final[$id] = array_merge(($loadProgression == "true" ? getValue($id, $progression) : array()) , $value, array(
"nickname" => $data[$id]["nickname"],
"user_id" => $data[$id]["user_id"],
"platform" => $platform,
"season_name" => getSeasonName($value["season"]),
"rankInfo" => getRankArray($value["rank"], $config['rank-images-png']),
"maxRankInfo" => getRankArray($value["max_rank"], $config['rank-images-png'])
));
}
header("Content-Type: application/json");
if (array_key_exists("season", $data))
echo $data["season"];
print json_encode(array(
"players" => array_merge($final, $notFound)
));