Fixed broken lists and more GDPS stuff
This commit is contained in:
parent
a2bb6f0b7a
commit
46e03b1932
5 changed files with 50 additions and 28 deletions
24
api/icon.js
24
api/icon.js
|
@ -1,3 +1,7 @@
|
|||
// this file is a potential candidate for worst code on github
|
||||
// i advise you to turn back now
|
||||
// seriously, it's not too late
|
||||
|
||||
const request = require('request')
|
||||
const Jimp = require('jimp');
|
||||
const fs = require('fs');
|
||||
|
@ -274,7 +278,9 @@ module.exports = async (app, req, res) => {
|
|||
ic.composite(robotLeg1, 100 + (iconSize[0] / 2) - (robotOffset1[2]) + robotOffset1[0] + 7, (iconSize[1] / 2) - (robotOffset1[3]) - robotOffset1[1] + 70)
|
||||
}
|
||||
|
||||
if (useExtra) ic.composite(extra, imgOff + (iconSize[0] / 2) - (size2[0] / 2) + offset2[0], (iconSize[1] / 2) - (size2[1] / 2) - offset2[1] + (form == "bird" && !req.query.topless ? 300 - iconSize[1] : 0))
|
||||
// every now and then jimp does a fucky wucky uwu and this line errors. seems to be an issue with the lib itself :v
|
||||
try { if (useExtra) ic.composite(extra, imgOff + (iconSize[0] / 2) - (size2[0] / 2) + offset2[0], (iconSize[1] / 2) - (size2[1] / 2) - offset2[1] + (form == "bird" && !req.query.topless ? 300 - iconSize[1] : 0)) }
|
||||
catch(e) {}
|
||||
|
||||
let finalSize = [ic.bitmap.width, ic.bitmap.height]
|
||||
|
||||
|
@ -352,29 +358,31 @@ module.exports = async (app, req, res) => {
|
|||
|
||||
let username = req.params.text
|
||||
let userCode;
|
||||
|
||||
res.contentType('image/png');
|
||||
|
||||
if (app.offline || req.query.hasOwnProperty("noUser") || req.query.hasOwnProperty("nouser") || username == "icon") return buildIcon()
|
||||
|
||||
else if (app.config.cachePlayerIcons && !Object.keys(req.query).length || Object.keys(req.query).length == 1 && req.query.form) {
|
||||
userCode = `u-${username.toLowerCase()}-${forms[req.query.form] ? req.query.form : 'cube'}`
|
||||
else if (app.config.cachePlayerIcons && !Object.keys(req.query).filter(x => !["form", "forceGD"].includes(x)).length) {
|
||||
userCode = `${app.GDPSName}u-${username.toLowerCase()}-${forms[req.query.form] ? req.query.form : 'cube'}`
|
||||
if (cache[userCode]) return res.end(cache[userCode].value)
|
||||
}
|
||||
|
||||
let accountMode = !req.query.hasOwnProperty("player") && Number(req.params.id)
|
||||
let foundID = app.accountCache[username.toLowerCase()]
|
||||
let foundID = app.accountCache[app.GDPSName + username.toLowerCase()]
|
||||
let skipRequest = accountMode || foundID
|
||||
let forceGD = req.query.hasOwnProperty("forceGD") // forces request to be made on boomlings.com
|
||||
let endpoint = forceGD ? "http://boomlings.com/database/" : app.endpoint
|
||||
|
||||
// skip request by causing fake error lmao
|
||||
request.post(skipRequest ? "" : app.endpoint + 'getGJUsers20.php', skipRequest ? {} : req.gdParams({ str: username }), function (err1, res1, body1) {
|
||||
request.post(skipRequest ? "" : endpoint + 'getGJUsers20.php', skipRequest ? {} : req.gdParams({ str: username }, !forceGD), function (err1, res1, body1) {
|
||||
|
||||
let result = foundID ? foundID[0] : (accountMode || err1 || !body1 || body1 == "-1" || body1.startsWith("<!")) ? username : app.parseResponse(body1)[16];
|
||||
|
||||
request.post(app.endpoint + 'getGJUserInfo20.php', req.gdParams({ targetAccountID: result }), function (err2, res2, body2) {
|
||||
request.post(endpoint + 'getGJUserInfo20.php', req.gdParams({ targetAccountID: result }, !forceGD), function (err2, res2, body2) {
|
||||
|
||||
if (err2 || !body2 || body2 == '-1' || body2.startsWith("<!")) return buildIcon();
|
||||
let iconData = app.parseResponse(body2)
|
||||
if (!foundID && app.config.cacheAccountIDs) app.accountCache[username.toLowerCase()] = [iconData[16], iconData[2]]
|
||||
if (!foundID && !forceGD && app.config.cacheAccountIDs) app.accountCache[app.GDPSName + username.toLowerCase()] = [iconData[16], iconData[2]]
|
||||
return buildIcon(iconData, userCode);
|
||||
|
||||
})
|
||||
|
|
|
@ -6,12 +6,21 @@ module.exports = async (app, req, res, api, getLevels) => {
|
|||
if (app.offline) return res.send("-1")
|
||||
let username = getLevels || req.params.id
|
||||
let accountMode = !req.query.hasOwnProperty("player") && Number(req.params.id)
|
||||
let foundID = app.accountCache[username.toLowerCase()]
|
||||
let foundID = app.accountCache[app.GDPSName + username.toLowerCase()]
|
||||
let skipRequest = accountMode || foundID
|
||||
let searchResult;
|
||||
|
||||
// if you're searching by account id, an intentional error is caused to skip the first request to the gd servers. see i pulled a sneaky on ya. (fuck callbacks man)
|
||||
request.post(skipRequest ? "" : app.endpoint + 'getGJUsers20.php', skipRequest ? {} : req.gdParams({ str: username, page: 0 }), function (err1, res1, b1) {
|
||||
let searchResult = foundID ? foundID[0] : (accountMode || err1 || b1 == '-1' || b1.startsWith("<!") || !b1) ? req.params.id : app.parseResponse(b1.split("|")[0])[16]
|
||||
|
||||
if (foundID) searchResult = foundID[0]
|
||||
else if (accountMode || err1 || b1 == '-1' || b1.startsWith("<!") || !b1) searchResult = req.params.id
|
||||
else if (!app.isGDPS) searchResult = app.parseResponse(b1.split("|")[0])[16]
|
||||
else { // GDPS's return multiple users, GD no longer does this
|
||||
let userResults = b1.split("|").map(x => app.parseResponse(x))
|
||||
searchResult = userResults.find(x => x[1].toLowerCase() == username.toLowerCase() || x[2] == username) || ""
|
||||
if (searchResult) searchResult = searchResult[16]
|
||||
}
|
||||
|
||||
if (getLevels) {
|
||||
req.params.text = foundID ? foundID[1] : app.parseResponse(b1)[2]
|
||||
|
@ -19,14 +28,16 @@ module.exports = async (app, req, res, api, getLevels) => {
|
|||
}
|
||||
|
||||
request.post(app.endpoint + 'getGJUserInfo20.php', req.gdParams({ targetAccountID: searchResult }), function (err2, res2, body) {
|
||||
if (err2 || body == '-1' || !body) {
|
||||
|
||||
let account = app.parseResponse(body || "")
|
||||
let dumbGDPSError = app.isGDPS && !account[16] || account[1].toLowerCase() == "undefined"
|
||||
|
||||
if (err2 || body == '-1' || !body || dumbGDPSError) {
|
||||
if (!api) return res.redirect('/search/' + req.params.id)
|
||||
else return res.send("-1")
|
||||
}
|
||||
|
||||
let account = app.parseResponse(body)
|
||||
|
||||
if (!foundID && app.config.cacheAccountIDs) app.accountCache[username.toLowerCase()] = [account[16], account[2]]
|
||||
if (!foundID && app.config.cacheAccountIDs) app.accountCache[app.GDPSName + username.toLowerCase()] = [account[16], account[2]]
|
||||
|
||||
let userData = {
|
||||
username: account[1] || "[MISSINGNO.]",
|
||||
|
@ -58,10 +69,6 @@ module.exports = async (app, req, res, api, getLevels) => {
|
|||
deathEffect: +account[48] || 1,
|
||||
glow: account[28] == "1",
|
||||
}
|
||||
|
||||
if (app.isGDPS) {
|
||||
if (userData.icon == 0 && !userData.accountID && userData.username.toLowerCase() == "undefined") userData.username = "[MISSINGNO.]"
|
||||
}
|
||||
|
||||
if (api) return res.send(userData)
|
||||
|
||||
|
|
|
@ -11,10 +11,13 @@ module.exports = async (app, req, res) => {
|
|||
if (demonMode) {
|
||||
if (app.isGDPS) return res.send('-1')
|
||||
if (!demonList.list.length || demonList.lastUpdated + 600000 < Date.now()) { // 10 minute cache
|
||||
return request.get('http://www.pointercrate.com/api/v2/demons/listed/?limit=100', function (err, resp, list) {
|
||||
if (err) return res.send("-1")
|
||||
demonList = {list: JSON.parse(list).map(x => x.level_id), lastUpdated: Date.now()}
|
||||
return app.run.search(app, req, res)
|
||||
return request.get('http://www.pointercrate.com/api/v2/demons/listed/?limit=100', function (err1, resp1, list1) {
|
||||
if (err1) return res.send("-1")
|
||||
else return request.get('http://www.pointercrate.com/api/v2/demons/listed/?limit=100&after=100', function (err2, resp2, list2) {
|
||||
if (err2) return res.send("-1")
|
||||
demonList = {list: JSON.parse(list1).concat(JSON.parse(list2)).map(x => x.level_id), lastUpdated: Date.now()}
|
||||
return app.run.search(app, req, res)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +74,7 @@ module.exports = async (app, req, res) => {
|
|||
}
|
||||
|
||||
if (req.query.hasOwnProperty("user")) {
|
||||
let accountCheck = app.accountCache[filters.str.toLowerCase()]
|
||||
let accountCheck = app.accountCache[app.GDPSName + filters.str.toLowerCase()]
|
||||
filters.type = 5
|
||||
if (accountCheck) filters.str = accountCheck[1]
|
||||
else if (!filters.str.match(/^[0-9]*$/)) return app.run.profile(app, req, res, null, req.params.text)
|
||||
|
@ -88,7 +91,7 @@ module.exports = async (app, req, res) => {
|
|||
filters.page = 0
|
||||
}
|
||||
|
||||
if (req.params.text == "*") delete filters.str
|
||||
if (filters.str == "*") delete filters.str
|
||||
|
||||
request.post(app.endpoint + 'getGJLevels21.php', req.gdParams(filters), async function(err, resp, body) {
|
||||
|
||||
|
|
10
index.js
10
index.js
|
@ -50,12 +50,15 @@ app.use(timeout('20s'));
|
|||
app.set('json spaces', 2)
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
req.gdParams = function(obj={}) {
|
||||
req.gdParams = function(obj={}, substitute=true) {
|
||||
Object.keys(app.config.params).forEach(x => { if (!obj[x]) obj[x] = app.config.params[x] })
|
||||
let ip = req.headers['x-real-ip'] || req.headers['x-forwarded-for']
|
||||
let params = {form: obj, headers: app.config.ipForwarding && ip ? {'x-forwarded-for': ip, 'x-real-ip': ip} : {}}
|
||||
for (let sub in app.config.substitutions) {
|
||||
if (params.form[sub]) { params.form[app.config.substitutions[sub]] = params.form[sub]; delete params.form[sub] }
|
||||
|
||||
if (substitute) { // GDPS substitutions in settings.js
|
||||
for (let sub in app.config.substitutions) {
|
||||
if (params.form[sub]) { params.form[app.config.substitutions[sub]] = params.form[sub]; delete params.form[sub] }
|
||||
}
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
@ -79,6 +82,7 @@ app.timeSince = function(time=app.lastSuccess) {
|
|||
}
|
||||
|
||||
app.isGDPS = app.endpoint != "http://boomlings.com/database/"
|
||||
app.GDPSName = (app.isGDPS ? app.endpoint.split("/")[2] : "")
|
||||
|
||||
app.run = {}
|
||||
directories.forEach(d => {
|
||||
|
|
|
@ -19,9 +19,9 @@ module.exports = {
|
|||
ipForwarding: true, // Forwards 'x-real-ip' to the servers. (requested by robtop)
|
||||
|
||||
// GDPS Related (feel free to drop a PR if you're able to make gdbrowser work better with gdps'es <3)
|
||||
timestampSuffix: " ago", // Suffix to add after timestamps, if any.
|
||||
base64descriptions: true, // Are level descriptions encoded in Base64?
|
||||
xorPasswords: true, // Are level passwords XOR encrypted?
|
||||
timestampSuffix: " ago", // Suffix to add after timestamps, if any.
|
||||
substitutions: { // Any parameters that are renamed on the GDPS should be listed here, e.g. { levelID: "abcde" }
|
||||
// levelID: "oiuyhxp4w9I"
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue