-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
240 lines (200 loc) · 9.78 KB
/
Copy pathtest.php
File metadata and controls
240 lines (200 loc) · 9.78 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
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
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET');
header('Access-Control-Allow-Headers: Access-Control-Allow-Headers, Content-Type, Access-Control-Allow-Methods, Authorization, X-Requested-With');
$NALOL = "https://na1.api.riotgames.com/lol/";
$americaLOL = "https://americas.api.riotgames.com/lol/";
$apiKey = "api_key=~~insert key here~~";
//get ID's for given summoner
if(isset($_GET['summoner'])) {
$summonerInput = rawurlencode($_GET['summoner']);
$getPlayerIDS = $NALOL . "summoner/v4/summoners/by-name/" . $summonerInput . "?" . $apiKey;
$encodedPlayerIDS = file_get_contents($getPlayerIDS);
if(is_null($encodedPlayerIDS)) {
return http_response_code(404);
}
//echo "player ID's: ";
//var_dump($encodedPlayerIDS);
$playerIDS = json_decode($encodedPlayerIDS);
//Get Rank
if($playerIDS->id != null) {
$summonerName = $playerIDS->name;
$encryptedSummonerID = $playerIDS->id;
$summonerIcon = $playerIDS->profileIconId;
//echo "encrypted ID: " . $encryptedSummonerID . "\n";
$getPlayerRank = $NALOL . "league/v4/entries/by-summoner/" . $encryptedSummonerID . "?" . $apiKey;
$encodedPlayerRank = file_get_contents($getPlayerRank);
if(is_null($encodedPlayerRank)) {
return http_response_code(404);
}
//echo "player ranks: ";
//var_dump($encodedPlayerRank);
$playerRank = json_decode($encodedPlayerRank);
if($playerRank != null) {
foreach($playerRank as $rank) {
if($rank->queueType == "RANKED_SOLO_5x5") {
$soloTier = ucwords(strtolower($rank->tier));
$soloDivision = $rank->rank;
$soloRank = $soloTier . " " . $soloDivision;
$soloLP = $rank->leaguePoints;
$soloWins = $rank->wins;
$soloLosses = $rank->losses;
$soloWinRate = round($soloWins * 100 / ($soloWins + $soloLosses), 1) . "%";
if(isset($rank->miniSeries)) {
$soloPrint = $soloPrint . "\n-> Promotion: " . $rank->miniSeries->wins . " Wins " . $rank->miniSeries->losses . " Losses";
}
}
else if($rank->queueType == "RANKED_FLEX_SR") {
$flexTier = ucwords(strtolower($rank->tier));
$flexDivision = $rank->rank;
$flexRank = $flexTier . " " . $flexDivision;
$flexLP = $rank->leaguePoints;
$flexWins = $rank->wins;
$flexLosses = $rank->losses;
$flexWinRate = round($flexWins * 100 / ($flexWins + $flexLosses), 1) . "%";
if(isset($rank->miniSeries)) {
$flexPrint = $flexPrint . "\n-> Promotion: " . $rank->miniSeries->wins . " Wins " . $rank->miniSeries->losses . " Losses";
}
}
}
}
if($soloTier == null) {
$soloTier = "Unranked";
$soloDivision = "Unranked";
$soloRank = "Unranked";
$soloLP = "Unranked";
$soloWins = "Unranked";
$soloLosses = "Unranked";
$soloWinRate = "Unranked";
}
if($flexTier == null) {
$flexTier = "Unranked";
$flexDivision = "Unranked";
$flexRank = "Unranked";
$flexLP = "Unranked";
$flexWins = "Unranked";
$flexLosses = "Unranked";
$flexWinRate = "Unranked";
}
} else {
return http_response_code(404);
}
//Get queues into a php variable
$encodedQueueTypes = file_get_contents("./queues.json");
if(is_null($encodedQueueTypes)) {
return http_response_code(404);
}
$queueTypes = json_decode($encodedQueueTypes);
//Get summoners into a php variable
$encodedSummoners = file_get_contents("./summoner.json");
if(is_null($encodedSummoners)) {
return http_response_code(404);
}
$summoners = json_decode($encodedSummoners);
//Get Match History
if($playerIDS->accountId != null) {
$encryptedSummonerPUUID = $playerIDS->puuid;
$startMatchIndex = 0;
$endMatchIndex = 20;
$getPlayerMatchHistory = $americaLOL . "match/v5/matches/by-puuid/" . $encryptedSummonerPUUID . "/ids?start=" . $startMatchIndex . "&count=" . $endMatchIndex ."&" . $apiKey;
$encodedPlayerMatchHistory = file_get_contents($getPlayerMatchHistory);
if(is_null($encodedPlayerMatchHistory)) {
return http_response_code(404);
}
$playerMatchHistory = json_decode($encodedPlayerMatchHistory);
if($playerMatchHistory != null) {
$matchHistory = array();
foreach($playerMatchHistory as $match) {
$getPlayerSingleMatch = $americaLOL . "match/v5/matches/" . $match . "?" . $apiKey;
$encodedPlayerSingleMatch = file_get_contents($getPlayerSingleMatch);
if(is_null($encodedPlayerSingleMatch)) {
return http_response_code(404);
}
$playerSingleMatch = json_decode($encodedPlayerSingleMatch);
//Get individual player information for a match
$playerList = array();
foreach($playerSingleMatch->info->participants as $participant) {
foreach($summoners->data as $summoner) {
if($summoner->key == $participant->summoner1Id) {
$summonerD = $summoner->name;
}
if($summoner->key == $participant->summoner2Id) {
$summonerF = $summoner->name;
}
}
$player = array(
'summonerName' => $participant->summonerName,
'championId' => $participant->championId,
'championName' => $participant->championName,
'kills' => $participant->kills,
'deaths' => $participant->deaths,
'assists' => $participant->assists,
'position' => $participant->individualPosition,
'champLevel' => $participant->champLevel,
'summonerD' => $summonerD,
'summonerF' => $summonerF,
'cs' => $participant->totalMinionsKilled,
'teamId' => $participant->teamId
);
if($participant->summonerName == $summonerName) {
$gameResult = $participant->win;
}
array_push($playerList, $player);
}
//find queue type
foreach($queueTypes as $queueType) {
if($queueType->queueId == $playerSingleMatch->info->queueId) {
$gameMap = $queueType->map;
$gameMode = $queueType->description;
}
}
//Get total kills for each side
foreach($playerSingleMatch->info->teams as $teamStats) {
if($teamStats->teamId == "100") {
$team100TotalKills = $teamStats->objectives->champion->kills;
}
if($teamStats->teamId == "200") {
$team200TotalKills = $teamStats->objectives->champion->kills;
}
}
//Set data for a single match
$returnMatch = array (
'matchId' => $playerSingleMatch->metadata->matchId,
'gameMap' => $gameMap,
'gameMode' => $gameMode,
'gameVersion' => $playerSingleMatch->info->gameVersion,
'mapId' => $playerSingleMatch->info->mapId,
'gameDuration' => $playerSingleMatch->info->gameDuration,
'gameResult' => $gameResult,
'team100TotalKills' => $team100TotalKills,
'team200TotalKills' => $team200TotalKills,
'playerList' => $playerList
);
array_push($matchHistory, $returnMatch);
}
}
}
} else {
return http_response_code(404);
}
//JSON data
$file = array(
'summonerName' => $summonerName,
'summonerIcon' => $summonerIcon,
'summonerID' => $encryptedSummonerID,
'summonerPUUID' => $encryptedSummonerPUUID,
'soloLP' => $soloLP,
'soloTier' => $soloTier,
'soloDivision' => $soloDivision,
'soloWins' => $soloWins,
'soloLosses' => $soloLosses,
'soloWinRate' => $soloWinRate,
'flexTier' => $flexTier,
'flexDivision' => $flexDivision,
'flexLP' => $flexLP,
'flexWins' => $flexWins,
'flexLosses' => $flexLosses,
'flexWinRate' => $flexWinRate,
'matches' => $matchHistory
);
echo json_encode($file);