Skip to content

Commit

Permalink
Merge pull request #1 from Soraclee/dev
Browse files Browse the repository at this point in the history
1.0
  • Loading branch information
Soraclee authored May 13, 2023
2 parents 14e89de + 07fabd5 commit 5f4544c
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 146 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});
11 changes: 6 additions & 5 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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% {
Expand All @@ -121,7 +122,7 @@ hr {

@-webkit-keyframes slide-out {
0% {
-webkit-transform: translateX(0%);
-webkit-transform: translateX(4%);
}

100% {
Expand Down
22 changes: 22 additions & 0 deletions public/js/checkPlayerData.js
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 0 additions & 1 deletion public/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ setInterval(function () {
overlay[0].classList.remove("slide-out");
overlay[0].classList.add("slide-in");
}
console.log(overlay[0].classList);
}, 180000);
157 changes: 27 additions & 130 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
8 changes: 7 additions & 1 deletion settings.json
Original file line number Diff line number Diff line change
@@ -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
}
}
59 changes: 52 additions & 7 deletions views/index.pug
Original file line number Diff line number Diff line change
@@ -1,19 +1,64 @@
extends layout

block content
#{console.log(dataPlayer)}
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="" alt="Radiant")
img(class="rank-user")
div(class="right-overlay")
div(class="rank-name")
span Radiant
span
hr
div(class="stats")
p 1.2 KDA
p 175 Wins
p 1910 Elo

p
p
p
3 changes: 2 additions & 1 deletion views/layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5f4544c

Please sign in to comment.