lolinfo.js
23.7 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
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
var express = require('express');
var router = express.Router();
/* GET users listing. */
var request = require("request");
var urlenconde = require('urlencode');
var apikey = "RGAPI-b69c36b5-e5c6-4698-af93-4be17fc8a7e4"//api
var profileIconId; //아이콘 번호
var revisionDate; //수정날짜
var id; //소환사ID
var accountId; //계정Id
var name; //소환사 이름
var summonerLevel; //소환사
var rotation_champ = new Array();
var rotation_champ_newbie = new Array();
var champion;
var champ_count = 0;
var spell;
router.get('/main', function (req, res) {
var rotation_name = new Array();
var rotation_name_newbie = new Array();
var rotation_pic = new Array();
var rotation_pic_newbie = new Array();
var rotationUrl = "https://kr.api.riotgames.com/lol/platform/v3/champion-rotations?api_key=" + apikey;
request(rotationUrl, function (error, response, body) {
var info_rotation = JSON.parse(body);
var keys = Object.keys(info_rotation);
for (var k = 0; k < info_rotation[keys[0]].length; k++)
rotation_champ[k] = info_rotation[keys[0]][k];
for (var k = 0; k < info_rotation[keys[1]].length; k++)
rotation_champ_newbie[k] = info_rotation[keys[1]][k];
var staticUrl = "http://ddragon.leagueoflegends.com/cdn/10.11.1/data/en_US/champion.json";
request(staticUrl, function (error, response, body) {
var info_static_champ_json = JSON.parse(body);
champion = info_static_champ_json["data"];
for (var name in champion) {
if (champion.hasOwnProperty(name)) {
champ_count++;
}
}
for (var i = 0; i < champ_count; i++) {
for (js in champion) {
for (j in champion[js]) {
if (champion[js]["key"] == rotation_champ[i]) {
rotation_name[i] = champion[js]["id"];
rotation_pic[i] = "http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + rotation_name[i] + ".png";
}
if (champion[js]["key"] == rotation_champ_newbie[i]) {
rotation_name_newbie[i] = champion[js]["id"]
rotation_pic_newbie[i] = "http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + rotation_name_newbie[i] + ".png";
}
}
}
}
res.send({
title: 'LOL INFO',
c_rotation: rotation_pic,
c_rotation_newbie: rotation_pic_newbie
});
});
});
});
router.get('/search/:username/', function (req, res, next) {
//롤 api url
name = req.params.username;
var nameUrl = "https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + urlenconde(name) + "?api_key=" + apikey;
request(nameUrl, function (error, response, body) {
// 요청에 대한 응답이 성공적으로 왔는지 검사.
// status code가 200이 아니면 오류가 있었던 것으로 간주하고 함수 종료.
console.log('response code ', response.statusCode);
if (response.statusCode != 200) {
console.log('Error with response code22 ', response.statusCode);
res.end();
return;
}
var info_summoner_json = JSON.parse(body);
accountId = info_summoner_json["accountId"];
id = info_summoner_json["id"];
summoner = info_summoner_json["name"];
profileIconId = info_summoner_json["profileIconId"];
summonerLevel = info_summoner_json["summonerLevel"];
revisionDate = info_summoner_json["revisionDate"];
var spellUrl = "http://ddragon.leagueoflegends.com/cdn/10.12.1/data/en_US/summoner.json";
request(spellUrl, function (error, response, body) {
spell = (JSON.parse(body)).data;
var userLeagueUrl = "https://kr.api.riotgames.com/lol/league/v4/entries/by-summoner/" + urlenconde(id) + "?api_key=" + apikey;
request(userLeagueUrl, function (error, response, body) {
var info_user_league_json = JSON.parse(body);
if (info_user_league_json[0] != null) {
var wins = info_user_league_json[0]["wins"];
var losses = info_user_league_json[0]["losses"];
var tier = info_user_league_json[0]["tier"];
var rank = info_user_league_json[0]["rank"];
var leaguePoints = info_user_league_json[0]["leaguePoints"];
var img_tier;
if (tier == "MASTER") {
img_tier = "/ranked-emblems/Emblem_Master.png";
} else if (tier == "CHALLENGER") {
img_tier = "/ranked-emblems/Emblem_Challenger.png";
} else if (tier == "DIAMOND") {
img_tier = "/ranked-emblems/Emblem_Diamond.png"
} else if (tier == "PLATINUM") {
img_tier = "/ranked-emblems/Emblem_Platinum.png"
} else if (tier == "GRANDMASTER") {
img_tier = "/ranked-emblems/Emblem_Grandmaster.png"
} else if (tier == "GOLD") {
img_tier = "/ranked-emblems/Emblem_Gold.png"
} else if (tier == "SILVER") {
img_tier = "/ranked-emblems/Emblem_Silver.png"
} else if (tier == "BRONZE") {
img_tier = "/ranked-emblems/Emblem_Bronze.png"
} else {
img_tier = "/ranked-emblems/Emblem_Iron.png"
}
res.send({
title: req.params.username,
c_summoner: summoner,
c_wins: wins,
c_losses: losses,
c_tier: tier,
c_imgtier: img_tier,
c_rank: rank,
c_leaguePoint: leaguePoints
});
}
});
});
});
});
router.get('/search/:username/spectator', function (req, res, next) {
if (true) {
var spectatorUrl = "https://kr.api.riotgames.com/lol/spectator/v4/active-games/by-summoner/" + urlenconde(id) + "?api_key=" + apikey;
request(spectatorUrl, function (error, response, body) {
var flag = true; // 실시간 경기 여부
if (response.statusCode != 200)
flag = false;
var spectator;
if (flag) { // 실시간 경기 진행중이면
var spectator_json = JSON.parse(body);
var spec_bannedChamp = spectator_json.bannedChampions;
var spec_gameId = spectator_json.gameId;
var spec_gameLength = spectator_json.gameLength;
var spec_gameMode = spectator_json.gameMode;
var spec_QueueId = spectator_json.gameQueueConfigId;
var spec_mapId = spectator_json.mapId;
var spec_participants = spectator_json.participants;
var spec_bannedChamp_image = new Array();
var spec_selectedChamp_image = new Array();
var spec_summonerName = new Array();
var spec_spellId = new Array();
var spec_spell_image = new Array();
for (var i = 0; i < 10; i++) {
spec_summonerName.push(spec_participants[i].summonerName);
spec_spellId.push(spec_participants[i].spell1Id);
spec_spellId.push(spec_participants[i].spell2Id);
}
for (var i = 0; i < 10; i++) {
for (key in champion) {
if (champion.hasOwnProperty(key) && champion[key].key == spec_bannedChamp[i].championId) {
spec_bannedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
}
if (champion.hasOwnProperty(key) && champion[key].key == spec_participants[i].championId) {
spec_selectedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
}
}
}
for (var i = 0; i < 20; i++) {
for (key in spell) {
if (spell.hasOwnProperty(key) && spell[key].key == spec_spellId[i]) {
spec_spell_image.push("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/spell/" + spell[key].id + ".png");
}
}
}
spectator = {
"summonerName": spec_summonerName,
"selectedChamp_image": spec_selectedChamp_image,
"bannedChamp_image": spec_bannedChamp_image,
"spell_image": spec_spell_image
};
}
res.send({
flag: flag,
spectator: spectator
});
});
}
else {
res.send();
}
});
router.get('/search/:username/match', function (req, res, next) {
// 게임정보 불러오기
var match = new Array();
var matchUrl = "https://kr.api.riotgames.com/lol/match/v4/matchlists/by-account/" + accountId + "?api_key=" + apikey;
request(matchUrl, function (error, response, body) {
var match_json = JSON.parse(body).matches;
var match_gameId = new Array();
var match_mychamp = new Array();
var count = 0, idx = 0;
while (count < 5) {
// 420 : 5x5 솔로랭크, 440 : 5x5 자유랭크
if (match_json[idx].queue == 420 || match_json[idx].queue == 440) {
match_gameId.push(match_json[idx].gameId);
match_mychamp.push(match_json[idx].champion);
count++;
}
idx++;
}
// teamId: 100 = Blue , teamId:200 = Red
var match1Url = "https://kr.api.riotgames.com/lol/match/v4/matches/" + match_gameId[0] + "?api_key=" + apikey;
request(match1Url, function (error, response, body) {
var match1_json = JSON.parse(body);
var match1_gameLength = match_json.gameDuration;
var match1_teams = match1_json.teams;
var match1_participants = match1_json.participants;
var match1_participantIdentities = match1_json.participantIdentities;
var match1_bannedChamp = new Array();
var match1_selectedChamp = new Array();
var match1_spellId = new Array();
var match1_summonerName = new Array();
var match1_kda = new Array();
var match1_bannedChamp_image = new Array();
var match1_selectedChamp_image = new Array();
var match1_spell_image = new Array();
for (var i = 0; i < 2; i++) {
var temp = match1_teams[i].bans;
for (var j = 0; j < 5; j++) {
match1_bannedChamp.push(temp[j].championId);
}
}
for (var i = 0; i < 10; i++) {
match1_selectedChamp.push(match1_participants[i].championId);
match1_spellId.push(match1_participants[i].spell1Id);
match1_spellId.push(match1_participants[i].spell2Id);
match1_summonerName.push((match1_participantIdentities[i].player).summonerName);
var obj = {
'k': (match1_participants[i].stats).kills,
'd': (match1_participants[i].stats).deaths,
'a': (match1_participants[i].stats).assists
};
match1_kda.push(obj);
}
for (var i = 0; i < 10; i++) {
for (key in champion) {
if (champion.hasOwnProperty(key) && champion[key].key == match1_bannedChamp[i]) {
match1_bannedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
}
if (champion.hasOwnProperty(key) && champion[key].key == match1_selectedChamp[i]) {
match1_selectedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
}
}
}
for (var i = 0; i < 20; i++) {
for (key in spell) {
if (spell.hasOwnProperty(key) && spell[key].key == match1_spellId[i]) {
match1_spell_image.push("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/spell/" + spell[key].id + ".png");
}
}
}
match.push({
"summonerName": match1_summonerName,
"selectedChamp_image": match1_selectedChamp_image,
"bannedChamp_image": match1_bannedChamp_image,
"spell_image": match1_spell_image,
"kda": match1_kda
});
var match2Url = "https://kr.api.riotgames.com/lol/match/v4/matches/" + match_gameId[1] + "?api_key=" + apikey;
request(match2Url, function (error, response, body) {
var match2_json = JSON.parse(body);
var match2_gameLength = match_json.gameDuration;
var match2_teams = match2_json.teams;
var match2_participants = match2_json.participants;
var match2_participantIdentities = match2_json.participantIdentities;
var match2_bannedChamp = new Array();
var match2_selectedChamp = new Array();
var match2_spellId = new Array();
var match2_summonerName = new Array();
var match2_kda = new Array();
var match2_bannedChamp_image = new Array();
var match2_selectedChamp_image = new Array();
var match2_spell_image = new Array();
for (var i = 0; i < 2; i++) {
var temp = match2_teams[i].bans;
for (var j = 0; j < 5; j++) {
match2_bannedChamp.push(temp[j].championId);
}
}
for (var i = 0; i < 10; i++) {
match2_selectedChamp.push(match2_participants[i].championId);
match2_spellId.push(match2_participants[i].spell1Id);
match2_spellId.push(match2_participants[i].spell2Id);
match2_summonerName.push((match2_participantIdentities[i].player).summonerName);
var obj = {
'k': (match2_participants[i].stats).kills,
'd': (match2_participants[i].stats).deaths,
'a': (match2_participants[i].stats).assists
};
match2_kda.push(obj);
}
for (var i = 0; i < 10; i++) {
for (key in champion) {
if (champion.hasOwnProperty(key) && champion[key].key == match2_bannedChamp[i]) {
match2_bannedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
}
if (champion.hasOwnProperty(key) && champion[key].key == match2_selectedChamp[i]) {
match2_selectedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
}
}
}
for (var i = 0; i < 20; i++) {
for (key in spell) {
if (spell.hasOwnProperty(key) && spell[key].key == match2_spellId[i]) {
match2_spell_image.push("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/spell/" + spell[key].id + ".png");
}
}
}
match.push({
"summonerName": match2_summonerName,
"selectedChamp_image": match2_selectedChamp_image,
"bannedChamp_image": match2_bannedChamp_image,
"spell_image": match2_spell_image,
"kda": match2_kda
});
var match3Url = "https://kr.api.riotgames.com/lol/match/v4/matches/" + match_gameId[1] + "?api_key=" + apikey;
request(match3Url, function (error, response, body) {
var match3_json = JSON.parse(body);
var match3_gameLength = match_json.gameDuration;
var match3_teams = match3_json.teams;
var match3_participants = match3_json.participants;
var match3_participantIdentities = match3_json.participantIdentities;
var match3_bannedChamp = new Array();
var match3_selectedChamp = new Array();
var match3_spellId = new Array();
var match3_summonerName = new Array();
var match3_kda = new Array();
var match3_bannedChamp_image = new Array();
var match3_selectedChamp_image = new Array();
var match3_spell_image = new Array();
for (var i = 0; i < 2; i++) {
var temp = match3_teams[i].bans;
for (var j = 0; j < 5; j++) {
match3_bannedChamp.push(temp[j].championId);
}
}
for (var i = 0; i < 10; i++) {
match3_selectedChamp.push(match3_participants[i].championId);
match3_spellId.push(match3_participants[i].spell1Id);
match3_spellId.push(match3_participants[i].spell2Id);
match3_summonerName.push((match3_participantIdentities[i].player).summonerName);
var obj = {
'k': (match3_participants[i].stats).kills,
'd': (match3_participants[i].stats).deaths,
'a': (match3_participants[i].stats).assists
};
match3_kda.push(obj);
}
for (var i = 0; i < 10; i++) {
for (key in champion) {
if (champion.hasOwnProperty(key) && champion[key].key == match3_bannedChamp[i]) {
match3_bannedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
}
if (champion.hasOwnProperty(key) && champion[key].key == match3_selectedChamp[i]) {
match3_selectedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
}
}
}
for (var i = 0; i < 20; i++) {
for (key in spell) {
if (spell.hasOwnProperty(key) && spell[key].key == match3_spellId[i]) {
match3_spell_image.push("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/spell/" + spell[key].id + ".png");
}
}
}
match.push({
"summonerName": match3_summonerName,
"selectedChamp_image": match3_selectedChamp_image,
"bannedChamp_image": match3_bannedChamp_image,
"spell_image": match3_spell_image,
"kda": match3_kda
});
var match4Url = "https://kr.api.riotgames.com/lol/match/v4/matches/" + match_gameId[1] + "?api_key=" + apikey;
request(match4Url, function (error, response, body) {
var match4_json = JSON.parse(body);
var match4_gameLength = match_json.gameDuration;
var match4_teams = match4_json.teams;
var match4_participants = match4_json.participants;
var match4_participantIdentities = match4_json.participantIdentities;
var match4_bannedChamp = new Array();
var match4_selectedChamp = new Array();
var match4_spellId = new Array();
var match4_summonerName = new Array();
var match4_kda = new Array();
var match4_bannedChamp_image = new Array();
var match4_selectedChamp_image = new Array();
var match4_spell_image = new Array();
for (var i = 0; i < 2; i++) {
var temp = match4_teams[i].bans;
for (var j = 0; j < 5; j++) {
match4_bannedChamp.push(temp[j].championId);
}
}
for (var i = 0; i < 10; i++) {
match4_selectedChamp.push(match4_participants[i].championId);
match4_spellId.push(match4_participants[i].spell1Id);
match4_spellId.push(match4_participants[i].spell2Id);
match4_summonerName.push((match4_participantIdentities[i].player).summonerName);
var obj = {
'k': (match4_participants[i].stats).kills,
'd': (match4_participants[i].stats).deaths,
'a': (match4_participants[i].stats).assists
};
match4_kda.push(obj);
}
for (var i = 0; i < 10; i++) {
for (key in champion) {
if (champion.hasOwnProperty(key) && champion[key].key == match4_bannedChamp[i]) {
match4_bannedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
}
if (champion.hasOwnProperty(key) && champion[key].key == match4_selectedChamp[i]) {
match4_selectedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
}
}
}
for (var i = 0; i < 20; i++) {
for (key in spell) {
if (spell.hasOwnProperty(key) && spell[key].key == match4_spellId[i]) {
match4_spell_image.push("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/spell/" + spell[key].id + ".png");
}
}
}
match.push({
"summonerName": match4_summonerName,
"selectedChamp_image": match4_selectedChamp_image,
"bannedChamp_image": match4_bannedChamp_image,
"spell_image": match4_spell_image,
"kda": match4_kda
});
var match5Url = "https://kr.api.riotgames.com/lol/match/v4/matches/" + match_gameId[1] + "?api_key=" + apikey;
request(match5Url, function (error, response, body) {
var match5_json = JSON.parse(body);
var match5_gameLength = match_json.gameDuration;
var match5_teams = match5_json.teams;
var match5_participants = match5_json.participants;
var match5_participantIdentities = match5_json.participantIdentities;
var match5_bannedChamp = new Array();
var match5_selectedChamp = new Array();
var match5_spellId = new Array();
var match5_summonerName = new Array();
var match5_kda = new Array();
var match5_bannedChamp_image = new Array();
var match5_selectedChamp_image = new Array();
var match5_spell_image = new Array();
for (var i = 0; i < 2; i++) {
var temp = match5_teams[i].bans;
for (var j = 0; j < 5; j++) {
match5_bannedChamp.push(temp[j].championId);
}
}
for (var i = 0; i < 10; i++) {
match5_selectedChamp.push(match5_participants[i].championId);
match5_spellId.push(match5_participants[i].spell1Id);
match5_spellId.push(match5_participants[i].spell2Id);
match5_summonerName.push((match5_participantIdentities[i].player).summonerName);
var obj = {
'k': (match5_participants[i].stats).kills,
'd': (match5_participants[i].stats).deaths,
'a': (match5_participants[i].stats).assists
};
match5_kda.push(obj);
}
for (var i = 0; i < 10; i++) {
for (key in champion) {
if (champion.hasOwnProperty(key) && champion[key].key == match5_bannedChamp[i]) {
match5_bannedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
}
if (champion.hasOwnProperty(key) && champion[key].key == match5_selectedChamp[i]) {
match5_selectedChamp_image.push("http://ddragon.leagueoflegends.com/cdn/10.11.1/img/champion/" + champion[key].id + ".png");
}
}
}
for (var i = 0; i < 20; i++) {
for (key in spell) {
if (spell.hasOwnProperty(key) && spell[key].key == match5_spellId[i]) {
match5_spell_image.push("http://ddragon.leagueoflegends.com/cdn/10.12.1/img/spell/" + spell[key].id + ".png");
}
}
}
match.push({
"summonerName": match5_summonerName,
"selectedChamp_image": match5_selectedChamp_image,
"bannedChamp_image": match5_bannedChamp_image,
"spell_image": match5_spell_image,
"kda": match5_kda
});
console.log(match);
res.send({
match: match
});
});
});
});
});
});
});
});
module.exports = router;