GDBrowser/api/leaderboard.js
GDColon 252e3f3b05 GDPS Compatibility (kinda)
I've started work on making GDBrowser compatible with GD private servers :D
Currently a few things (comments, leaderboards, etc) are broken but other than that I'm kind of getting there.

This commit mostly just makes life easier for people who want to fork GDBrowser for their private server
- The endpoint (e.g. boomlings.com) is now set in index.js
- Added gdpsConfig.js, where you can tweak small settings in case your GDPS does stuff weirdly
- Small tweaks to the code so the weird GDPS responses can be correctly interpreted
- secretStuff.json is no longer mandatory

If you're able to help me out with this project, PRs are appreciated :D

- Removed Herobrine
2019-12-21 22:16:18 -05:00

41 lines
No EOL
1.2 KiB
JavaScript

const request = require('request')
module.exports = async (app, req, res) => {
let amount = 100;
let count = req.query.count ? parseInt(req.query.count) : null
if (count && count > 0) {
if (count > 5000) amount = 5000
else amount = count;
}
let params = {
count: amount,
secret: app.secret,
type: (req.query.hasOwnProperty("creator") || req.query.hasOwnProperty("creators")) ? "creators" : "top",
}
request.post(app.endpoint + 'getGJScores20.php', {
form : params}, async function(err, resp, body) {
if (err || body == '-1' || !body) return res.send("-1")
scores = body.split('|').map(x => app.parseResponse(x)).filter(x => x[1])
if (!scores.length) return res.send("-1")
scores.forEach(x => {
let keys = Object.keys(x)
x.rank = x[6]
x.username = x[1]
x.playerID = x[2]
x.accountID = x[16]
x.stars = x[3]
x.demons = x[4]
x.cp = x[8]
x.coins = x[13]
x.usercoins = x[17]
x.diamonds = x[46] == '65535' ? '65535+' : x[46],
keys.forEach(k => delete x[k])
})
return res.send(scores)
})
}