accurate leaderboard be back out of its coma

This commit is contained in:
GDColon 2020-11-13 22:32:46 -05:00
parent 8768afa90e
commit b77a6c73d4
6 changed files with 45 additions and 72 deletions

View file

@ -1,14 +1,11 @@
// const request = require('request')
// const {GoogleSpreadsheet} = require('google-spreadsheet');
// const sheet = new GoogleSpreadsheet('1ADIJvAkL0XHGBDhO7PP9aQOuK3mPIKB2cVPbshuBBHc'); // accurate leaderboard spreadsheet
const {GoogleSpreadsheet} = require('google-spreadsheet');
const sheet = new GoogleSpreadsheet('1ADIJvAkL0XHGBDhO7PP9aQOuK3mPIKB2cVPbshuBBHc'); // accurate leaderboard spreadsheet
// let lastIndex = {"stars": 0, "coins": 0, "demons": 0}
// let caches = [{"stars": null, "coins": null, "demons": null}, {"stars": null, "coins": null, "demons": null}] // 0 for JSON, 1 for GD
let lastIndex = {"stars": 0, "coins": 0, "demons": 0}
let caches = [{"stars": null, "coins": null, "demons": null}, {"stars": null, "coins": null, "demons": null}] // 0 for JSON, 1 for GD
module.exports = async (app, req, res, post) => {
return res.send([]) // this really do be a bruh moment
if (app.offline || !app.sheetsKey || app.endpoint != "http://boomlings.com/database/") return res.send([])
let gdMode = post || req.query.hasOwnProperty("gd")
let cache = caches[gdMode ? 1 : 0]
@ -22,49 +19,14 @@ module.exports = async (app, req, res, post) => {
sheet.loadInfo().then(async () => {
let tab = sheet.sheetsById[1555821000]
await tab.loadCells('A2:C2')
let topPlayers = tab.getCell(1, type == "demons" ? 2 : type == "coins" ? 1 : 0).value
let idArray = topPlayers.split(",")
let leaderboard = JSON.parse(tab.getCell(1, type == "demons" ? 2 : type == "coins" ? 1 : 0).value)
let leaderboard = []
let total = idArray.length
let gdFormatting = ""
leaderboard.forEach(x => gdFormatting += `1:${x.username}:2:${x.playerID}:13:${x.coins}:17:${x.usercoins}:6:${x.rank}:9:1:10:10:11:14:14:0:15:0:16:${x.accountID}:3:${x.stars}:8:${x.cp}:46:${x.diamonds}:4:${x.demons}|`)
caches[0][type] = JSON.stringify(leaderboard)
caches[1][type] = gdFormatting
lastIndex[type] = Date.now()
return res.send(gdMode ? gdFormatting : leaderboard)
idArray.forEach((x, y) => {
request.post(app.endpoint + 'getGJUserInfo20.php', req.gdParams({targetAccountID: x}), function (err, resp, body) {
if (err || !body || body == '-1') return res.send([])
let account = app.parseResponse(body)
let accObj = {
rank: "0",
username: account[1],
playerID: account[2],
accountID: account[16],
stars: +account[3],
demons: +account[4],
cp: +account[8],
coins: +account[13],
usercoins: +account[17],
diamonds: +account[46],
icon: [account[21], account[10], account[11], account[28] == "1" ? "2" : "0"]
}
leaderboard.push(accObj)
if (leaderboard.length == total) {
let sortBy = type == "coins" ? "usercoins" : type
leaderboard = leaderboard.filter(x => x.stars).sort(function (a, b) {return parseInt(b[sortBy]) - parseInt(a[sortBy])})
leaderboard.forEach((a, b) => a.rank = b + 1)
let gdFormatting = ""
leaderboard.forEach(x => { gdFormatting += `1:${x.username}:2:${x.playerID}:13:${x.coins}:17:${x.usercoins}:6:${x.rank}:9:${x.icon[0]}:10:${x.icon[1]}:11:${x.icon[2]}:14:0:15:${x.icon[3]}:16:${x.accountID}:3:${x.stars}:8:${x.cp}:46:${x.diamonds}:4:${x.demons}|`; delete x.icon})
caches[0][type] = JSON.stringify(leaderboard)
caches[1][type] = gdFormatting
lastIndex[type] = Date.now()
return res.send(gdMode ? gdFormatting : leaderboard)
}
})
})
})
}

View file

@ -1106,6 +1106,14 @@ input::-webkit-inner-spin-button {
color: #27CEFA;
}
.brightblue {
color: #bbffff
}
.brightred {
color: #ffaaaa;
}
.grayscale {
filter: grayscale(100%) brightness(0.7);
}

View file

@ -337,7 +337,7 @@
</div>
<br>
<p class="reveal" onclick="$('#response-leaderboard').slideToggle(100)"><b>Response (9)</b></p>
<p class="reveal" onclick="$('#response-leaderboard').slideToggle(100)"><b>Response (10)</b></p>
<div class="subdiv" id="response-leaderboard">
<p>The API will return an array of each player with the following information:</p>
<p>rank: Position on the leaderboard</p>
@ -349,7 +349,7 @@
<p>coins: Number of secret coins</p>
<p>usercoins: Number of user coins</p>
<p>diamonds: Number of diamonds</p>
<p>icon: The icon preview showed next to the player's name</p>
<p>icon: The icon preview showed next to the player's name (Not supported by accurate leaderboard)</p>
</div>
<br>
@ -435,7 +435,7 @@
</div>
<br>
<p class="reveal" onclick="$('#response-levelleaderboard').slideToggle(100)"><b>Response (6)</b></p>
<p class="reveal" onclick="$('#response-levelleaderboard').slideToggle(100)"><b>Response (7)</b></p>
<div class="subdiv" id="response-levelleaderboard">
<p>The API will return an array of each player with the following information:</p>
<p>rank: Position on the leaderboard</p>

View file

@ -46,6 +46,7 @@
</tr>
<tr>
<td><a href="./leaderboard"><img class="menubutton" src="../assets/category-scores.png"></a></td>
<!-- <img src="./assets/exclamation.png" style="position: absolute; height: 18%; left: 3.5%; bottom: 23%; pointer-events: none; z-index: 50;"> -->
<td><a href="./search/*?type=hof"><img class="menubutton" src="../assets/category-hof.png"></a></td>
<td><a href="./mappacks"><img class="menubutton" src="../assets/category-packs.png"></a></td>
<td><a href="./search"><img class="menubutton" src="../assets/category-search.png"></a></td>

View file

@ -75,7 +75,7 @@
<script>
let sort = "stars"
let trophies = [1, 3, 5, 10, 25, 50, 100]
let trophies = [1, 3, 10, 25, 50, 75, 100]
let top250Text =
`The <g>Top 250<> leaderboard contains the <g>top 250 players<>, sorted by <y>star<> value. However, due to <o>hackers<> flooding the leaderboard, this leaderboard has been <b>frozen<> for well over 2 years and displays <o>very outdated information<>.`
@ -117,11 +117,11 @@ function leaderboard(val) {
style="cursor: help; height: 19%; transform: translate(-25%, -10%);" title="Stars"></h3>
<h3 class="lessSpaced leaderboardStats">
<span${x.diamonds >= 65535 ? " class='blue'" : ""}>${x.diamonds}</span> <img class="valign" src="../assets/diamond.png" style="cursor: help" title="Diamonds">
<span${x.diamonds >= 65535 ? " class='blue'>~" : ">"}${x.diamonds}</span> <img class="valign" src="../assets/diamond.png" style="cursor: help" title="Diamonds">
<span${x.coins >= 149 ? " class='yellow'" : ""}>${x.coins}</span> <img class="valign" src="../assets/coin.png" style="cursor: help" title="Secret Coins">
${x.usercoins} <img class="valign" src="../assets/silvercoin.png" style="cursor: help" title="User Coins">
${x.demons} <img class="valign" src="../assets/demon.png" style="cursor: help" title="Demons">
${x.cp != 0 ? `${x.cp} <img class="valign" src="../assets/cp.png" style="cursor: help" title="Creator Points">` : ""}
<span${x.usercoins >= 10000 ? " class='brightblue'" : ""}>${x.usercoins}</span> <img class="valign" src="../assets/silvercoin.png" style="cursor: help" title="User Coins">
<span${x.demons >= 1000 ? " class='brightred'" : ""}>${x.demons}</span> <img class="valign" src="../assets/demon.png" style="cursor: help" title="Demons">
${x.cp != 0 ? `<span${x.cp >= 100 ? " class='yellow'" : ""}>${x.cp}</span> <img class="valign" src="../assets/cp.png" style="cursor: help" title="Creator Points">` : ""}
</h3>
<div class="center ranking" style="position:absolute; transform:scale(0.82) translate(-20.7vh, -20vh); height: 10%; width: 12.5%;">
@ -134,13 +134,12 @@ function leaderboard(val) {
</div>`)
})
else if (type == "accurate") {
$('#searchBox').append(`<div style="width: 100%">
<h1 style="margin-top: 14%"class="center">The Accurate Leaderboard<br>is temporarily disabled</h1>
<p class="center" style="padding: 0% 10%">Due to RobTop's new <span style="color: yellow">API enforcements</span>, the Accurate Leaderboard is <span style="color: cyan">no longer able to load reliably</span>. A fix is being worked on and will hopefully be released in <span style="color: lime">a day or two</span>.</p>
</div>`)
}
/* else if (type == "accurate") {
$('#searchBox').append(`<div style="width: 100%">
<h1 style="margin-top: 14%"class="center">The Accurate Leaderboard<br>is temporarily disabled</h1>
<p class="center" style="padding: 0% 10%">Due to RobTop's new <span style="color: yellow">API enforcements</span>, the Accurate Leaderboard is <span style="color: cyan">no longer able to load reliably</span>. A fix is being worked on and will hopefully be released in <span style="color: lime">a day or two</span>.</p>
</div>`)
} */
$('#searchBox').append('<div style="height: 4.5%"></div>')
$('#loading').hide();

View file

@ -86,9 +86,9 @@
<span id="stars">[[STARS]]</span> <img class="valign" src="../assets/star.png" style="cursor: help" title="Stars">
<span id="diamonds">[[DIAMONDS]]</span> <img class="valign" src="../assets/diamond.png" style="cursor: help" title="Diamonds">
<span id="coins">[[COINS]]</span> <img class="valign" src="../assets/coin.png" style="cursor: help" title="Secret Coins">
[[USERCOINS]] <img class="valign"src="../assets/silvercoin.png" style="cursor: help" title="User Coins">
[[DEMONS]] <img class="valign"src="../assets/demon.png" style="cursor: help" title="Demons">
[[CP]] <img class="valign" src="../assets/cp.png" style="cursor: help" title="Creator Points">
<span id="usercoins">[[USERCOINS]]</span> <img class="valign"src="../assets/silvercoin.png" style="cursor: help" title="User Coins">
<span id="demons">[[DEMONS]]</span> <img class="valign"src="../assets/demon.png" style="cursor: help" title="Demons">
<span id="creatorpoints" style="display: none"><span id="cp">[[CP]]</span> <img class="valign" src="../assets/cp.png" style="cursor: help" title="Creator Points"></span>
</h3>
<div class="lightBox center" id="iconsDiv" style="margin: 2% auto; width: 105vh">
@ -159,7 +159,6 @@ let messageText = 'Your <span style="color: yellow">Geometry Dash password</span
$('#message').html(messageText)
$('#likeMessage').html(messageText.replace("profile posts", "liking posts").replace("postProfileComment", "like"))
$('#collectibles').html($('#collectibles').html().split(' 0 <img class="valign" src="../assets/cp')[0])
$('#modBadge[[MODERATOR]]').show()
$('#globalrank[[RANK]]').hide()
@ -181,6 +180,14 @@ $('#followOn').click(function() {
$('#followOn').hide()
})
if ([[DIAMONDS]] >= 65535) $('#diamonds').addClass('blue')
if ([[COINS]] >= 149) $('#coins').addClass('yellow')
if ([[STARS]] >= 100000) $('#stars').addClass('yellow')
if ([[DEMONS]] >= 1000) $('#demons').addClass('brightred')
if ([[USERCOINS]] >= 10000) $('#usercoins').addClass('brightblue')
if ([[CP]] >= 100) $('#cp').addClass('yellow')
if ([[CP]] > 0) $('#creatorpoints').show()
if (`[[YOUTUBE]]` != "null") $('#youtube').show()
if (`[[TWITTER]]` != "null") $('#twitter').show()
if (`[[TWITCH]]` != "null") $('#twitch').show()
@ -269,10 +276,6 @@ $('#content').on('input', function() {
$('#charcount').text(remaining)
})
if ([[DIAMONDS]] >= 65535) $('#diamonds').addClass('blue')
if ([[COINS]] >= 149) $('#coins').addClass('yellow')
if ([[STARS]] >= 100000) $('#stars').addClass('yellow')
$('#submitComment').click(function () {
let comment = $('#content').val()
let username = '[[USERNAME]]'