Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

A lot of refactoring, and etc #232

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
0b3ad3f
Refactoring, formatting, etc...
Rudxain May 27, 2022
5886f33
Fixed some whitespaces
Rudxain May 29, 2022
32d0dee
Replaced `if` by `||=`
Rudxain May 29, 2022
2cd72fa
Update index.js
Rudxain May 29, 2022
b7eb348
Forgot parentheses lol
Rudxain May 29, 2022
f7c5e12
Using `Object.hasOwn` instead of checking `undefined`
Rudxain May 29, 2022
419bf02
Merge branch 'master' into patch-1
Rudxain Jun 13, 2022
6eb5acc
patch-1
Rudxain Jun 14, 2022
cf7313c
patch-1
Rudxain Jun 14, 2022
e9f84b6
patch-1
Rudxain Jun 14, 2022
e2f7bcb
p
Rudxain Jun 14, 2022
0c6c1a1
Added radian converters
Rudxain Jun 14, 2022
e3e1342
Replaced `perigon` by `scale`
Rudxain Jun 14, 2022
3d68f0e
icon.js and global.js
Rudxain Jun 14, 2022
6f70050
Finished `global.js` (I guess)
Rudxain Jun 14, 2022
51e676f
dragscroll.js
Rudxain Jun 14, 2022
5b3da23
I added too much indent, fixed now
Rudxain Jun 14, 2022
bc15522
Added `randRange`
Rudxain Jun 15, 2022
6d50bbe
etc
Rudxain Jun 15, 2022
2dd7c2b
Replaced `for of` by `forEach`
Rudxain Jun 15, 2022
12ea39a
Replaced `pop` by `at`
Rudxain Jun 15, 2022
14c7359
Add files via upload
Rudxain Jun 17, 2022
69254a0
Add files via upload
Rudxain Jun 17, 2022
fc365ca
Add files via upload
Rudxain Jun 17, 2022
16c7e0d
Add files via upload
Rudxain Jun 17, 2022
3815933
Add files via upload
Rudxain Jun 17, 2022
d1ee9f5
Add files via upload
Rudxain Jun 17, 2022
efb41fb
Add files via upload
Rudxain Jun 17, 2022
f3574bf
Add files via upload
Rudxain Jun 17, 2022
fe472b7
Add files via upload
Rudxain Jun 17, 2022
17f6278
Add files via upload
Rudxain Jun 17, 2022
ae3c59f
Add files via upload
Rudxain Jun 17, 2022
2eb29e6
Add files via upload
Rudxain Jun 17, 2022
b06944c
Add files via upload
Rudxain Jun 17, 2022
4f6a80e
Add files via upload
Rudxain Jun 17, 2022
e52edd6
Shorter inc
Rudxain Jun 17, 2022
1facc93
Fixed `replaceFirst` behavior into `replaceAll`
Rudxain Jun 17, 2022
e59a143
Merge branch 'GDColon:master' into patch-1
Rudxain Jul 3, 2022
a1f4b41
Add files via upload
Rudxain Jul 3, 2022
60673ee
Add files via upload
Rudxain Jul 3, 2022
7ab773f
Add files via upload
Rudxain Jul 3, 2022
d736c4f
Add files via upload
Rudxain Jul 3, 2022
db592b9
Add files via upload
Rudxain Jul 3, 2022
da54ecc
Add files via upload
Rudxain Jul 3, 2022
e45c5b3
Add files via upload
Rudxain Jul 3, 2022
746ab12
Add files via upload
Rudxain Jul 3, 2022
611a6ea
Add files via upload
Rudxain Jul 3, 2022
5213fc1
Add files via upload
Rudxain Jul 3, 2022
767fbec
Add files via upload
Rudxain Jul 3, 2022
07d312f
Add files via upload
Rudxain Jul 3, 2022
6f9ec9d
Add files via upload
Rudxain Jul 3, 2022
f6a0c7e
Fixed possible URL bug @ boomlings.css
Rudxain Jul 3, 2022
76e8531
Reverted URL change @ browser.css
Rudxain Jul 3, 2022
210ef3c
Reverted URL @ iconkit.css
Rudxain Jul 3, 2022
9e0309a
Better formatting? I guess
Rudxain Jul 3, 2022
5eabd88
Add files via upload
Rudxain Jul 3, 2022
72d90d4
Update analyze.html
Rudxain Jul 3, 2022
7a65f9a
Reverted my bad MB conversion
Rudxain Jul 3, 2022
99e04c7
Add back a line
Rudxain Sep 1, 2022
0446668
Update analyze.js
Rudxain Sep 1, 2022
6e06305
Update analyze.js
Rudxain Oct 5, 2022
5e86a88
Update analyze.js
Rudxain Oct 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
318 changes: 175 additions & 143 deletions api/analyze.js

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions api/comments.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
const Player = require('../classes/Player.js')

module.exports = async (app, req, res) => {
Expand All @@ -8,8 +9,8 @@ module.exports = async (app, req, res) => {
if (count > 1000) count = 1000

let params = {
userID : req.params.id,
accountID : req.params.id,
userID : req.params.id,
accountID : req.params.id,
levelID: req.params.id,
page: +req.query.page || 0,
count,
Expand All @@ -20,7 +21,7 @@ module.exports = async (app, req, res) => {
if (req.query.type == "commentHistory") { path = "getGJCommentHistory"; delete params.levelID }
else if (req.query.type == "profile") path = "getGJAccountComments20"

req.gdRequest(path, req.gdParams(params), function(err, resp, body) {
req.gdRequest(path, req.gdParams(params), function(err, resp, body) {

if (err) return res.sendError()

Expand All @@ -32,7 +33,7 @@ module.exports = async (app, req, res) => {
if (!comments.length) return res.status(204).send([])

let pages = body.split('#')[1].split(":")
let lastPage = +Math.ceil(+pages[0] / +pages[2]);
let lastPage = +Math.ceil(+pages[0] / +pages[2])

let commentArray = []

Expand All @@ -41,7 +42,7 @@ module.exports = async (app, req, res) => {
var x = c[0] //comment info
var y = c[1] //account info

if (!x[2]) return;
if (!x[2]) return

let comment = {}
comment.content = Buffer.from(x[2], 'base64').toString();
Expand All @@ -50,9 +51,9 @@ module.exports = async (app, req, res) => {
comment.date = (x[9] || "?") + req.timestampSuffix
if (comment.content.endsWith("⍟") || comment.content.endsWith("☆")) {
comment.content = comment.content.slice(0, -1)
comment.browserColor = true
comment.browserColor = true
}

if (req.query.type != "profile") {
let commentUser = new Player(y)
Object.keys(commentUser).forEach(k => {
Expand All @@ -74,7 +75,7 @@ module.exports = async (app, req, res) => {

commentArray.push(comment)

})
})

return res.send(commentArray)

Expand Down
31 changes: 16 additions & 15 deletions api/download.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
"use strict";
const request = require('request')
const fs = require('fs')
const Level = require('../classes/Level.js')

module.exports = async (app, req, res, api, ID, analyze) => {

function rejectLevel() {
if (!api) return res.redirect('search/' + req.params.id)
else return res.sendError()
return !api ? res.redirect('search/' + req.params.id) : res.sendError()
}

if (req.offline) {
if (!api && levelID < 0) return res.redirect('/')
return rejectLevel()
return !api && levelID < 0 ? res.redirect('/') : rejectLevel()
}

let levelID = ID || req.params.id
if (levelID == "daily") levelID = -1
else if (levelID == "weekly") levelID = -2
else levelID = levelID.replace(/[^0-9]/g, "")
levelID = (
levelID == "daily" ? -1 :
levelID == "weekly" ? -2 :
levelID.replace(/\D/g, "")
)

req.gdRequest('downloadGJLevel22', { levelID }, function (err, resp, body) {

if (err) {
if (analyze && api && req.server.downloadsDisabled) return res.status(403).send("-3")
else if (!api && levelID < 0) return res.redirect(`/?daily=${levelID * -1}`)
else return rejectLevel()
}
if (err) return (
analyze && api && req.server.downloadsDisabled ? res.status(403).send("-3")
: !api && levelID < 0 ? res.redirect(`/?daily=${levelID * -1}`)
: rejectLevel()
)

let authorData = body.split("#")[3] // daily/weekly only, most likely

Expand All @@ -43,7 +44,7 @@ module.exports = async (app, req, res, api, ID, analyze) => {
if (err2 && (foundID || authorData)) {
let authorInfo = foundID || authorData.split(":")
level.author = authorInfo[1] || "-"
level.accountID = authorInfo[0] && authorInfo[0].includes(",") ? "0" : authorInfo[0]
level.accountID = authorInfo[0]?.includes(",") ? "0" : authorInfo[0]
}

else if (!err && b2 != '-1') {
Expand Down Expand Up @@ -72,7 +73,7 @@ module.exports = async (app, req, res, api, ID, analyze) => {
if (api) return res.send(level)

else return fs.readFile('./html/level.html', 'utf8', function (err, data) {
let html = data;
let html = data
let variables = Object.keys(level)
variables.forEach(x => {
let regex = new RegExp(`\\[\\[${x.toUpperCase()}\\]\\]`, "g")
Expand All @@ -89,7 +90,7 @@ module.exports = async (app, req, res, api, ID, analyze) => {
level.nextDaily = +dailyTime
level.nextDailyTimestamp = Math.round((Date.now() + (+dailyTime * 1000)) / 100000) * 100000
return sendLevel()
})
})
}

else if (req.server.demonList && level.difficulty == "Extreme Demon") {
Expand Down
11 changes: 7 additions & 4 deletions api/gauntlets.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
let cache = {}
let gauntletNames = ["Fire", "Ice", "Poison", "Shadow", "Lava", "Bonus", "Chaos", "Demon", "Time", "Crystal", "Magic", "Spike", "Monster", "Doom", "Death"]

Expand All @@ -6,17 +7,19 @@ module.exports = async (app, req, res) => {
if (req.offline) return res.sendError()

let cached = cache[req.id]
if (app.config.cacheGauntlets && cached && cached.data && cached.indexed + 2000000 > Date.now()) return res.send(cached.data) // half hour cache
if (app.config.cacheGauntlets && cached && cached.data && cached.indexed + 2000000 > Date.now())
return res.send(cached.data) // half hour cache

req.gdRequest('getGJGauntlets21', {}, function (err, resp, body) {

if (err) return res.sendError()
let gauntlets = body.split('#')[0].split('|').map(x => app.parseResponse(x)).filter(x => x[3])
let gauntlets = body.split('#', 1)[0].split('|').map(x => app.parseResponse(x)).filter(x => x[3])
let gauntletList = gauntlets.map(x => ({ id: +x[1], name: gauntletNames[+x[1] - 1] || "Unknown", levels: x[3].split(",") }))

if (app.config.cacheGauntlets) cache[req.id] = {data: gauntletList, indexed: Date.now()}
if (app.config.cacheGauntlets)
cache[req.id] = {data: gauntletList, indexed: Date.now()}
res.send(gauntletList)

})

}
75 changes: 39 additions & 36 deletions api/leaderboards/accurate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const {GoogleSpreadsheet} = require('google-spreadsheet');
const sheet = new GoogleSpreadsheet('1ADIJvAkL0XHGBDhO7PP9aQOuK3mPIKB2cVPbshuBBHc'); // accurate leaderboard spreadsheet
"use strict";
const {GoogleSpreadsheet} = require('google-spreadsheet')
const sheet = new GoogleSpreadsheet('1ADIJvAkL0XHGBDhO7PP9aQOuK3mPIKB2cVPbshuBBHc') // accurate leaderboard spreadsheet

let indexes = ["stars", "coins", "demons", "diamonds"]

Expand All @@ -9,39 +10,41 @@ let caches = [{"stars": null, "coins": null, "demons": null, "diamonds": null},

module.exports = async (app, req, res, post) => {

// Accurate leaderboard returns 418 because private servers do not use.
if (req.isGDPS) return res.status(418).send("-2")
if (!app.sheetsKey) return res.status(500).send([])
let gdMode = post || req.query.hasOwnProperty("gd")
let modMode = !gdMode && req.query.hasOwnProperty("mod")
let cache = caches[gdMode ? 2 : modMode ? 1 : 0]

let type = req.query.type ? req.query.type.toLowerCase() : 'stars'
if (type == "usercoins") type = "coins"
if (!indexes.includes(type)) type = "stars"
if (lastIndex[modMode ? 1 : 0][type] + 600000 > Date.now() && cache[type]) return res.send(gdMode ? cache[type] : JSON.parse(cache[type])) // 10 min cache

sheet.useApiKey(app.sheetsKey)
sheet.loadInfo().then(async () => {
let tab = sheet.sheetsById[1555821000]
await tab.loadCells('A2:H2')

let cellIndex = indexes.findIndex(x => type == x)
if (modMode) cellIndex += indexes.length

let cell = tab.getCell(1, cellIndex).value
if (!cell || typeof cell != "string" || cell.startsWith("GoogleSpreadsheetFormulaError")) { console.log("Spreadsheet Error:"); console.log(cell); return res.sendError() }
let leaderboard = JSON.parse(cell.replace(/~( |$)/g, ""))

let gdFormatting = ""
leaderboard.forEach(x => {
app.userCache(req.id, x.accountID, x.playerID, x.username)
gdFormatting += `1:${x.username}:2:${x.playerID}:13:${x.coins}:17:${x.usercoins}:6:${x.rank}:9:${x.icon.icon}:10:${x.icon.col1}:11:${x.icon.col2}:14:${forms.indexOf(x.icon.form)}:15:${x.icon.glow ? 2 : 0}:16:${x.accountID}:3:${x.stars}:8:${x.cp}:46:${x.diamonds}:4:${x.demons}|`
})
caches[modMode ? 1 : 0][type] = JSON.stringify(leaderboard)
caches[2][type] = gdFormatting
lastIndex[modMode ? 1 : 0][type] = Date.now()
return res.send(gdMode ? gdFormatting : leaderboard)

// Accurate leaderboard returns 418 because private servers do not use.
if (req.isGDPS) return res.status(418).send("-2")
if (!app.sheetsKey) return res.status(500).send([])
const gdMode = post || req.query.hasOwnProperty("gd")
const modMode = !gdMode && req.query.hasOwnProperty("mod")
let cache = caches[gdMode ? 2 : modMode ? 1 : 0]

let type = req.query.type ? req.query.type.toLowerCase() : 'stars'
if (type == "usercoins") type = "coins"
if (!indexes.includes(type)) type = "stars"
if (lastIndex[modMode ? 1 : 0][type] + 600000 > Date.now() && cache[type])
return res.send(gdMode ? cache[type] : JSON.parse(cache[type])) // 10 min cache

sheet.useApiKey(app.sheetsKey)
sheet.loadInfo().then(async () => {
let tab = sheet.sheetsById[1555821000]
await tab.loadCells('A2:H2')

let cellIndex = indexes.indexOf(type)
if (modMode) cellIndex += indexes.length

let cell = tab.getCell(1, cellIndex).value
if (!cell || typeof cell != "string" || cell.startsWith("GoogleSpreadsheetFormulaError")) {
console.log("Spreadsheet Error:"); console.log(cell); return res.sendError()
}
let leaderboard = JSON.parse(cell.replace(/~( |$)/g, ""))

let gdFormatting = ""
leaderboard.forEach(x => {
app.userCache(req.id, x.accountID, x.playerID, x.username)
gdFormatting += `1:${x.username}:2:${x.playerID}:13:${x.coins}:17:${x.usercoins}:6:${x.rank}:9:${x.icon.icon}:10:${x.icon.col1}:11:${x.icon.col2}:14:${forms.indexOf(x.icon.form)}:15:${x.icon.glow ? 2 : 0}:16:${x.accountID}:3:${x.stars}:8:${x.cp}:46:${x.diamonds}:4:${x.demons}|`
})
caches[modMode ? 1 : 0][type] = JSON.stringify(leaderboard)
caches[2][type] = gdFormatting
lastIndex[modMode ? 1 : 0][type] = Date.now()
return res.send(gdMode ? gdFormatting : leaderboard)
})
}
19 changes: 11 additions & 8 deletions api/leaderboards/boomlings.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"use strict";
const request = require('request')

module.exports = async (app, req, res) => {

// Accurate leaderboard returns 418 because Private servers do not use.
if (req.isGDPS) return res.status(418).send("0")
// Accurate leaderboard returns 418 because Private servers do not use.
if (req.isGDPS) return res.status(418).send("0")

request.post('http://robtopgames.com/Boomlings/get_scores.php', {
form : { secret: app.config.params.secret || "Wmfd2893gb7", name: "Player" } }, function(err, resp, body) {
request.post(
'http://robtopgames.com/Boomlings/get_scores.php',
{ form : { secret: app.config.params.secret || "Wmfd2893gb7", name: "Player" } },
function(err, resp, body) {

if (err || !body || body == 0) return res.status(500).send("0")

Expand All @@ -24,7 +27,7 @@ module.exports = async (app, req, res) => {
score: +scores.slice(3, 10),
boomling: +visuals.slice(5, 7),
boomlingLevel: +visuals.slice(2, 4),
powerups: [+visuals.slice(7, 9), +visuals.slice(9, 11), +visuals.slice(11, 13)].map(x => (x > 8 || x < 1) ? 0 : x),
powerups: [+visuals.slice(7, 9), +visuals.slice(9, 11), +visuals.slice(11, 13)].map(x => (x > 8 || x < 1) ? 0 : x),

unknownVisual: +visuals.slice(0, 2),
unknownScore: +scores.slice(0, 1),
Expand All @@ -34,10 +37,10 @@ module.exports = async (app, req, res) => {
if (!user.boomling || user.boomling > 66 || user.boomling < 0) user.boomling = 0
if (!user.boomlingLevel || user.boomlingLevel > 25 || user.boomlingLevel < 1) user.boomlingLevel = 25

users.push(user)
users.push(user)
})

return res.send(users)
})
}
)
}
91 changes: 44 additions & 47 deletions api/leaderboards/leaderboardLevel.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,50 @@
const colors = require('../../iconkit/sacredtexts/colors.json');
"use strict";
const colors = require('../../iconkit/sacredtexts/colors.json')

module.exports = async (app, req, res) => {

if (req.offline) return res.sendError()

let amount = 100;
let count = req.query.count ? parseInt(req.query.count) : null
if (count && count > 0) {
if (count > 200) amount = 200
else amount = count;
}

let params = {
levelID: req.params.id,
accountID: app.id,
gjp: app.gjp,
type: req.query.hasOwnProperty("week") ? "2" : "1",
}

req.gdRequest('getGJLevelScores211', params, function(err, resp, body) {

if (err) return res.status(500).send({error: true, lastWorked: app.timeSince(req.id)})
scores = body.split('|').map(x => app.parseResponse(x)).filter(x => x[1])
if (!scores.length) return res.status(500).send([])
else app.trackSuccess(req.id)

scores.forEach(x => {
let keys = Object.keys(x)
x.rank = x[6]
x.username = x[1]
x.percent = +x[3]
x.coins = +x[13]
x.playerID = x[2]
x.accountID = x[16]
x.date = x[42] + req.timestampSuffix
x.icon = {
form: ['icon', 'ship', 'ball', 'ufo', 'wave', 'robot', 'spider'][+x[14]],
icon: +x[9],
col1: +x[10],
col2: +x[11],
glow: +x[15] > 1,
col1RGB: colors[x[10]] || colors["0"],
col2RGB: colors[x[11]] || colors["3"]
}
keys.forEach(k => delete x[k])
app.userCache(req.id, x.accountID, x.playerID, x.username)
})

return res.send(scores.slice(0, amount))

})
let amount = 100
let count = req.query.count ? parseInt(req.query.count) : null
if (count && count > 0) amount = Math.min(count, 200)

let params = {
levelID: req.params.id,
accountID: app.id,
gjp: app.gjp,
type: req.query.hasOwnProperty("week") ? "2" : "1",
}

req.gdRequest('getGJLevelScores211', params, function(err, resp, body) {

if (err) return res.status(500).send({error: true, lastWorked: app.timeSince(req.id)})
scores = body.split('|').map(x => app.parseResponse(x)).filter(x => x[1])
if (!scores.length) return res.status(500).send([])
app.trackSuccess(req.id)

scores.forEach(x => {
let keys = Object.keys(x)
x.rank = x[6]
x.username = x[1]
x.percent = +x[3]
x.coins = +x[13]
x.playerID = x[2]
x.accountID = x[16]
x.date = x[42] + req.timestampSuffix
x.icon = {
form: ['icon', 'ship', 'ball', 'ufo', 'wave', 'robot', 'spider'][+x[14]],
icon: +x[9],
col1: +x[10],
col2: +x[11],
glow: +x[15] > 1,
col1RGB: colors[x[10]] || colors["0"],
col2RGB: colors[x[11]] || colors["3"]
}
keys.forEach(k => delete x[k])
app.userCache(req.id, x.accountID, x.playerID, x.username)
})

return res.send(scores.slice(0, amount))
})
}
Loading