From d29f560039d0ca1d456b76d13c0c080bd1b5ffb7 Mon Sep 17 00:00:00 2001 From: Soracle <69369114+Soraclee@users.noreply.github.com> Date: Fri, 12 May 2023 10:15:16 +0200 Subject: [PATCH 1/3] Initial commit --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e1c746a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Soracle + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 963e389443f1f6d702c366c3ac340a5601285e8b Mon Sep 17 00:00:00 2001 From: Soracle Date: Fri, 12 May 2023 11:18:46 +0200 Subject: [PATCH 2/3] Add data player in view --- views/index.pug | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/views/index.pug b/views/index.pug index 2b6ee53..aa1e23c 100644 --- a/views/index.pug +++ b/views/index.pug @@ -1,19 +1,19 @@ extends layout block content - #{console.log(dataPlayer)} + - let last_season = dataPlayer.by_season[Object.keys(dataPlayer.by_season)[Object.keys(dataPlayer.by_season).length - 1]] div(id="overlay" class="global-overlay slide-out") div(class="overlay-background") div(class="overlay") div(class="head-overlay") div(class="left-overlay") - img(class="rank-user" src="" alt="Radiant") + img(class="rank-user" src=`${dataPlayer.current_data.images.small}` alt="Radiant") div(class="right-overlay") div(class="rank-name") - span Radiant + span #{dataPlayer.current_data.currenttierpatched} hr div(class="stats") p 1.2 KDA - p 175 Wins - p 1910 Elo + p #{last_season.wins} Wins + p #{dataPlayer.current_data.elo} Elo From 07fabd534151dcc41e020d7234496249d9779e45 Mon Sep 17 00:00:00 2001 From: Soracle Date: Sat, 13 May 2023 10:50:04 +0200 Subject: [PATCH 3/3] Finish 1.0 --- app.js | 2 +- public/css/style.css | 11 +-- public/js/checkPlayerData.js | 22 +++++ public/js/script.js | 1 - routes/index.js | 157 ++++++----------------------------- settings.json | 8 +- views/index.pug | 59 +++++++++++-- views/layout.pug | 3 +- 8 files changed, 117 insertions(+), 146 deletions(-) create mode 100644 public/js/checkPlayerData.js diff --git a/app.js b/app.js index 34ad0a3..6301cf2 100644 --- a/app.js +++ b/app.js @@ -13,5 +13,5 @@ app.set("view engine", "pug"); app.use("/", indexRouter); app.listen(port, () => { - console.log(`Example app listening on port ${port}`); + console.log(`Listening on port ${port}`); }); diff --git a/public/css/style.css b/public/css/style.css index 436de6e..dc02524 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -10,16 +10,17 @@ body { background-color: transparent; font-family: euclid circular a; + overflow: hidden; } .global-overlay { position: absolute; float: right; right: -138px; + top: 15px; } .overlay-background { - background-image: url("https://media.valorant-api.com/playercards/b5314b3f-4532-9e41-bc1f-13954a4c6829/wideart.png"); background-repeat: round; opacity: 0.1; float: right; @@ -99,19 +100,19 @@ hr { } 100% { - transform: translateX(0%); + transform: translateX(4%); } } @-webkit-keyframes slide-in { 100% { - -webkit-transform: translateX(0%); + -webkit-transform: translateX(4%); } } @keyframes slide-out { 0% { - transform: translateX(0%); + transform: translateX(4%); } 100% { @@ -121,7 +122,7 @@ hr { @-webkit-keyframes slide-out { 0% { - -webkit-transform: translateX(0%); + -webkit-transform: translateX(4%); } 100% { diff --git a/public/js/checkPlayerData.js b/public/js/checkPlayerData.js new file mode 100644 index 0000000..0d710a4 --- /dev/null +++ b/public/js/checkPlayerData.js @@ -0,0 +1,22 @@ +async function searchPlayerbySubject(subject) { + let mmr = await fetch( + `https://api.henrikdev.xyz/valorant/v2/by-puuid/mmr/eu/${subject}` + ); + + let mmrJson = mmr.status == 200 ? await mmr.json() : "N.A"; + + return mmrJson; +} + +async function infosPlayer(pseudo) { + let pseudoValid = pseudo.toString().replace("#", "/"); + + let infosPlayer = await fetch( + `https://api.henrikdev.xyz/valorant/v1/account/${pseudoValid}` + ); + + let infosPlayerJson = + infosPlayer.status == 200 ? await infosPlayer.json() : "N.A"; + + return infosPlayerJson; +} diff --git a/public/js/script.js b/public/js/script.js index 5838f0f..ce5f726 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -8,5 +8,4 @@ setInterval(function () { overlay[0].classList.remove("slide-out"); overlay[0].classList.add("slide-in"); } - console.log(overlay[0].classList); }, 180000); diff --git a/routes/index.js b/routes/index.js index ea0f9ff..6e563cb 100644 --- a/routes/index.js +++ b/routes/index.js @@ -92,7 +92,7 @@ async function websocketConnect() { }); if (presence instanceof Error) { - console.log("Une requête à Valorant a généré une erreur."); + console.log("Valorant is not launched"); ws.close(); return; } @@ -191,146 +191,43 @@ function sleep(ms) { }); } -async function getNamebySubject(tokens) { - var playerid = await axios - .put( - `https://pd.${settings.region}.a.pvp.net/name-service/v2/players`, - [tokens.data.subject], - { - headers: { - Authorization: "Bearer " + tokens.data.accessToken, - "X-Riot-Entitlements-JWT": tokens.data.token, - "X-Riot-ClientVersion": "release-03.00-shipping-22-574489", - "X-Riot-ClientPlatform": - "ew0KCSJwbGF0Zm9ybVR5cGUiOiAiUEMiLA0KCSJwbGF0Zm9ybU9TIjogIldpbmRvd3MiLA0KCSJwbGF0Zm9ybU9TVmVyc2lvbiI6ICIxMC4wLjE5MDQyLjEuMjU2LjY0Yml0IiwNCgkicGxhdGZvcm1DaGlwc2V0IjogIlVua25vd24iDQp9", - }, - } - ) - .catch((error) => { - return error; - }); - - if (playerid.response && playerid.response.status == 400) { - tokens = await data(); - playerid = await axios - .put( - `https://pd.${settings.region}.a.pvp.net/name-service/v2/players`, - [tokens.data.subject], - { - headers: { - Authorization: "Bearer " + tokens.data.accessToken, - "X-Riot-Entitlements-JWT": tokens.data.token, - "X-Riot-ClientVersion": "release-03.00-shipping-22-574489", - "X-Riot-ClientPlatform": - "ew0KCSJwbGF0Zm9ybVR5cGUiOiAiUEMiLA0KCSJwbGF0Zm9ybU9TIjogIldpbmRvd3MiLA0KCSJwbGF0Zm9ybU9TVmVyc2lvbiI6ICIxMC4wLjE5MDQyLjEuMjU2LjY0Yml0IiwNCgkicGxhdGZvcm1DaGlwc2V0IjogIlVua25vd24iDQp9", - }, - } - ) - .catch((error) => { - return error; - }); - } - - if (playerid.response) return errorhandler(playerid.response.status, res); - - return playerid.data; -} - -async function getMMRbySubject( - subject = "dc5abcce-65e3-5841-8cd1-c7a11d3fb205" -) { - let mmrInfo = await axios - .get( - `https://api.henrikdev.xyz/valorant/v2/by-puuid/mmr/${settings.region}/${subject}` - ) - .catch((error) => { - return error; - }); - - return mmrInfo; -} - var tokens; var cstate; +var subjectPlayer; /* GET home page. */ router.get("/", async function (req, res, next) { tokens = tokens == undefined ? await data() : tokens; - dataPlayerMMR = await getMMRbySubject(); - dataPlayerJson = await JSON.parse(JSON.stringify(dataPlayerMMR.data.data)); + if (tokens != undefined) { + subjectPlayer = tokens.data.subject; + } else { + subjectPlayer = settings.subjectDefault; + } + + setInterval(async function () { + console.log("Refresh..."); + try { + tokens = await data(); + subjectPlayer = tokens.data.subject; + console.log("Token found"); + } catch { + subjectPlayer = settings.subjectDefault; + console.log("Token not found"); + } + }, 10000); + res.render("index", { title: "Valomy", - dataPlayer: dataPlayerJson, + subjectPlayer: subjectPlayer, }); }); -io.on("connection", async (socket) => { - console.log("Connected"); - socket.on("disconnect", () => { - console.log("Disconnected"); - }); - if (wsdata == null) { - console.log( - "Une requête à Valorant a généré une erreur. Raison: wsdata = null" - ); - io.emit("initialize", { state: "Menu" }); - console.log("State: Close"); - return; - } - var presence = await axios - .get(`https://127.0.0.1:${wsdata.port}/chat/v4/presences`, { - headers: { - Authorization: `Basic ${Buffer.from( - `riot:${wsdata.pw}`, - "utf8" - ).toString("base64")}`, - "user-agent": "ShooterGame/21 Windows/10.0.19042.1.768.64bit", - "X-Riot-ClientVersion": "release-02.03-shipping-8-521855", - "Content-Type": "application/json", - "rchat-blocking": "true", - }, - httpsAgent: new https.Agent({ - rejectUnauthorized: false, - }), - }) - .catch((error) => { - return error; - }); - if (presence instanceof Error) { - console.log( - "Une requête à Valorant a généré une erreur. Raison: Presence Error" - ); - io.emit("initialize", { state: "Menu" }); - console.log("State: Close"); - return; - } - try { - var f = presence.data.presences.filter( - (item) => item.puuid == tokens.data.subject - ); - var d = JSON.parse( - Buffer.from( - Buffer.from(f[0].private, "base64").toString("utf-8") - ).toString("utf-8") - ); - if (d.sessionLoopState == "MENUS") { - io.emit("initialize", { state: "Menu", data: d }); - console.log("State: MENUS"); - } - if (d.sessionLoopState == "PREGAME") { - io.emit("initialize", { state: "PreGame", data: d }); - console.log("State: PREGAME"); - } - if (d.sessionLoopState == "INGAME") { - io.emit("initialize", { state: "Ingame", data: d }); - console.log("State: INGAME"); - } - } catch (e) { - console.log("Une requête à Valorant a généré une erreur."); - io.emit("update", { state: "Menu" }); - console.log("State: Close"); - return; - } +router.get("/getSubjectPlayer", (req, res) => { + res.json({ subjectPlayer }); +}); + +router.get("/settings.json", (req, res) => { + res.json(settings); }); module.exports = router; diff --git a/settings.json b/settings.json index 4f37350..3c3e777 100644 --- a/settings.json +++ b/settings.json @@ -1,3 +1,9 @@ { - "region": "eu" + "region": "eu", + "subjectDefault": "dc5abcce-65e3-5841-8cd1-c7a11d3fb205", + "overlayOut": { + "_comment": "Display only the rank from how many ms", + "available": true, + "time": 180000 + } } \ No newline at end of file diff --git a/views/index.pug b/views/index.pug index aa1e23c..3338874 100644 --- a/views/index.pug +++ b/views/index.pug @@ -1,19 +1,64 @@ extends layout block content - - let last_season = dataPlayer.by_season[Object.keys(dataPlayer.by_season)[Object.keys(dataPlayer.by_season).length - 1]] + script(src='/js/checkPlayerData.js' defer) + script. + let subject = !{JSON.stringify(subjectPlayer)}; + let dataPlayer; + let infosPlayerData; + + async function updateSubjectPlayer() { + try { + const resultSubject = await fetch('/getSubjectPlayer'); + const newSubject = await resultSubject.json(); + subject = newSubject + } catch (error) { + console.error(error); + } + } + + setInterval(updateSubjectPlayer, 10000) + + async function updateDisplay() { + try { + let resultDataPlayer = await searchPlayerbySubject(subject.subjectPlayer || subject) + dataPlayer = resultDataPlayer.data + + let nametagPlayer = dataPlayer.name + "#" + dataPlayer.tag + + let resultInfosPlayer = await infosPlayer(nametagPlayer) + infosPlayerData = resultInfosPlayer.data + + // Update Display + + let last_season = dataPlayer.by_season[Object.keys(dataPlayer.by_season)[Object.keys(dataPlayer.by_season).length - 1]] + + document.querySelector('.overlay-background').style.backgroundImage = `url(${infosPlayerData.card.wide})` + document.querySelector('.rank-user').src = dataPlayer.current_data.images.small + document.querySelector('.rank-user').alt = dataPlayer.current_data.currenttierpatched + document.querySelector('.rank-name span').textContent = dataPlayer.current_data.currenttierpatched + document.querySelector('.stats p:nth-of-type(1)').textContent = `${infosPlayerData.account_level} Lvl` + document.querySelector('.stats p:nth-of-type(2)').textContent = `${dataPlayer.current_data.elo} Elo` + document.querySelector('.stats p:nth-of-type(3)').textContent = `${last_season.wins} Wins` + } catch (error) { + console.error(error) + } + } + updateDisplay(); + setInterval(function() { + updateDisplay(); + }, 10000) div(id="overlay" class="global-overlay slide-out") div(class="overlay-background") div(class="overlay") div(class="head-overlay") div(class="left-overlay") - img(class="rank-user" src=`${dataPlayer.current_data.images.small}` alt="Radiant") + img(class="rank-user") div(class="right-overlay") div(class="rank-name") - span #{dataPlayer.current_data.currenttierpatched} + span hr div(class="stats") - p 1.2 KDA - p #{last_season.wins} Wins - p #{dataPlayer.current_data.elo} Elo - + p + p + p diff --git a/views/layout.pug b/views/layout.pug index 6b452ef..847a56b 100644 --- a/views/layout.pug +++ b/views/layout.pug @@ -6,5 +6,6 @@ html style include ../public/css/style.css script(src='/js/script.js' defer) - body(style={background: 'transparent'}) + script(src='/js/checkPlayerData.js') + body block content