Showing
3 changed files
with
86 additions
and
2 deletions
This diff is collapsed. Click to expand it.
| ... | @@ -12,6 +12,8 @@ | ... | @@ -12,6 +12,8 @@ |
| 12 | "axios": "^0.19.2", | 12 | "axios": "^0.19.2", |
| 13 | "express": "^4.17.1", | 13 | "express": "^4.17.1", |
| 14 | "http": "0.0.1-security", | 14 | "http": "0.0.1-security", |
| 15 | + "jquery": "^3.5.1", | ||
| 16 | + "jsdom": "^16.2.2", | ||
| 15 | "nodemon": "^2.0.4" | 17 | "nodemon": "^2.0.4" |
| 16 | } | 18 | } |
| 17 | } | 19 | } | ... | ... |
| ... | @@ -17,6 +17,83 @@ const crwalCharacterCode = async function(nickname) { | ... | @@ -17,6 +17,83 @@ const crwalCharacterCode = async function(nickname) { |
| 17 | } | 17 | } |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | +const getCharacterInfo = async function(nickname, characterCode) { | ||
| 21 | + try { | ||
| 22 | + const resp = await axios.get("https://maplestory.nexon.com/Common/Character/Detail/" + encodeURI(nickname) + "?p=" + characterCode); | ||
| 23 | + | ||
| 24 | + if (resp.data.indexOf("공개하지 않은 정보입니다.") > 0) { | ||
| 25 | + throw new Error("private_character"); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + const character = { | ||
| 29 | + 'nickname': nickname, | ||
| 30 | + 'characterCode': characterCode | ||
| 31 | + }; | ||
| 32 | + const stats = {}; | ||
| 33 | + | ||
| 34 | + const { JSDOM } = require('jsdom'); | ||
| 35 | + const dom = new JSDOM(resp.data); | ||
| 36 | + const $ = (require('jquery'))(dom.window); | ||
| 37 | + | ||
| 38 | + const jobModel = require('../model/job'); | ||
| 39 | + const statModel = require('../model/stat'); | ||
| 40 | + | ||
| 41 | + character.job = $(".tab01_con_wrap .table_style01:eq(0) tbody tr:eq(0) td:eq(1) span").text(); | ||
| 42 | + character.level = parseInt($(".char_info dl:eq(0) dd").text().substring(3)); | ||
| 43 | + | ||
| 44 | + const $statInfo = $(".tab01_con_wrap .table_style01:eq(1)"); | ||
| 45 | + $("tbody tr", $statInfo).each(function() { | ||
| 46 | + if ($("th", this).length == 1) { | ||
| 47 | + if ($("th span", this).text() == "하이퍼스탯") { | ||
| 48 | + const values = $("td span", this).html().split("<br>"); | ||
| 49 | + const regex = new RegExp(`${statModel[jobModel[character.job].major].korean} (\\d+) 증가`); | ||
| 50 | + for (let i = 0; i < values.length; i++) { | ||
| 51 | + const regexResult = regex.exec(values[i]); | ||
| 52 | + | ||
| 53 | + if (!regexResult) | ||
| 54 | + continue; | ||
| 55 | + | ||
| 56 | + stats['majorHyper'] = parseInt(regexResult[1]); | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + } else { | ||
| 60 | + for (let i = 0; i < 2; i++) { | ||
| 61 | + const statName = $(`th:eq(${i}) span`, this).text(); | ||
| 62 | + const value = $(`td:eq(${i}) span`, this).text().replace(/\,/g, ""); | ||
| 63 | + | ||
| 64 | + switch (statName) { | ||
| 65 | + case jobModel[character.job].major: | ||
| 66 | + stats['major'] = parseInt(value); | ||
| 67 | + break; | ||
| 68 | + case jobModel[character.job].minor: | ||
| 69 | + stats['minor'] = parseInt(value); | ||
| 70 | + break; | ||
| 71 | + case "크리티컬 데미지": | ||
| 72 | + stats['criticalDamage'] = parseInt(value); | ||
| 73 | + break; | ||
| 74 | + case "보스공격력": | ||
| 75 | + stats['bossAttackDamage'] = parseInt(value); | ||
| 76 | + break; | ||
| 77 | + case "방어율무시": | ||
| 78 | + stats['ignoreGuard'] = parseInt(value); | ||
| 79 | + break; | ||
| 80 | + case "스탯공격력": | ||
| 81 | + stats['statAttackPower'] = parseInt(value.split(' ~ ')[1]); | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + }); | ||
| 86 | + | ||
| 87 | + return { | ||
| 88 | + character: character, | ||
| 89 | + stats: stats | ||
| 90 | + }; | ||
| 91 | + } catch (error) { | ||
| 92 | + console.log(error); | ||
| 93 | + return false; | ||
| 94 | + } | ||
| 95 | +} | ||
| 96 | + | ||
| 20 | module.exports = { | 97 | module.exports = { |
| 21 | getCharacter: async function(req, res) { | 98 | getCharacter: async function(req, res) { |
| 22 | if (!req.query.nickname) { | 99 | if (!req.query.nickname) { |
| ... | @@ -32,7 +109,12 @@ module.exports = { | ... | @@ -32,7 +109,12 @@ module.exports = { |
| 32 | return; | 109 | return; |
| 33 | } | 110 | } |
| 34 | 111 | ||
| 35 | - console.log(characterCode); | 112 | + const characterInfo = await getCharacterInfo(nickname, characterCode); |
| 36 | - res.send({ text: characterCode }); | 113 | + if (!characterInfo) { |
| 114 | + res.status(403).send(); | ||
| 115 | + return; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + res.send(characterInfo); | ||
| 37 | } | 119 | } |
| 38 | }; | 120 | }; |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment