mytest.js
12.3 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
module.exports = function (app) {
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;
var match;
app.get('/', 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.render('main', {
title: 'LOL INFO',
c_rotation: rotation_pic,
c_rotation_newbie: rotation_pic_newbie
});
});
});
});
app.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"];
console.log(info_summoner_json);
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.render('userinfo', {
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
});
}
});
});
});
});
app.get('/search/:username/spectator', function (req, res, next) {
if (true) {
console.log(id);
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);
console.log(spectator_json);
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
};
}
console.log(flag);
console.log(spectator);
res.render('main', {
flag: flag,
spectator: spectator
});
});
}
else {
res.send();
}
});
app.get('/search/:username/match', function (req, res, next) {
// 게임정보 불러오기
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++;
}
match = new Array();
for (var i = 0; i < 5; i++) {
// teamId: 100 = Blue , teamId:200 = Red
var match1Url = "https://kr.api.riotgames.com/lol/match/v4/matches/" + match_gameId[i] + "?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");
}
}
}
var match_temp = {
"summonerName": match1_summonerName,
"selectedChamp_image": match1_selectedChamp_image,
"bannedChamp_image": match1_bannedChamp_image,
"spell_image": match1_spell_image,
"kda": match1_kda
};
match.push(match_temp);
});
}
console.log(match);
res.render('match', {
match: match
});
});
});
}