Add level scores
This commit is contained in:
8 files changed
+242
-39
No files matched your search
+17
-2
@@ -1,11 +1,16 @@
|
||||
import { Elysia } from 'elysia'
|
||||
import { Elysia, t } from 'elysia'
|
||||
import { jsonResponse } from './lib/util'
|
||||
import dotenv from 'dotenv'
|
||||
|
||||
import { handler as gauntletsGetHandler } from './routes/gauntlets/get'
|
||||
|
||||
import { handler as leaderboardsGetHandler } from './routes/leaderboards/get'
|
||||
|
||||
import { handler as mapPacksGetHandler } from './routes/map-packs/get'
|
||||
|
||||
import { handler as leaderboardsGetHandler } from './routes/leaderboards/get'
|
||||
import { handler as scoresLevelGetHandler } from './routes/scores/level/get'
|
||||
|
||||
dotenv.config()
|
||||
|
||||
const app = new Elysia()
|
||||
|
||||
@@ -15,6 +20,16 @@ app.get('/gauntlets', gauntletsGetHandler)
|
||||
app.get('/map-packs', mapPacksGetHandler)
|
||||
app.get('/leaderboards/top', () => leaderboardsGetHandler('top'))
|
||||
app.get('/leaderboards/creators', () => leaderboardsGetHandler('creators'))
|
||||
app.get('/scores/level/top', handler => scoresLevelGetHandler(handler, '1'), {
|
||||
query: t.Object({
|
||||
id: t.String()
|
||||
})
|
||||
})
|
||||
app.get('/scores/level/week', handler => scoresLevelGetHandler(handler, '2'), {
|
||||
query: t.Object({
|
||||
id: t.String()
|
||||
})
|
||||
})
|
||||
app.all('*', () =>
|
||||
jsonResponse(
|
||||
{
|
||||
|
||||
@@ -13,3 +13,11 @@ export const splitGd = (input: string): Record<string, string> => {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export const encodeGJP2 = async (password = '', salt = 'mI29fmAnxgTs') => {
|
||||
const data = new TextEncoder().encode(password + salt)
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-1', data)
|
||||
return Array.from(new Uint8Array(hashBuffer))
|
||||
.map(b => b.toString(16).padStart(2, '0'))
|
||||
.join('')
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import axios from 'axios'
|
||||
import { encodeGJP2, jsonResponse, splitGd } from '../../../lib/util'
|
||||
import { Context } from 'elysia'
|
||||
|
||||
export const handler = async (handler: Context, type: string) => {
|
||||
const id = handler.query.id
|
||||
|
||||
if (!process.env.ACCOUNT_ID || !process.env.ACCOUNT_PASSWORD)
|
||||
return jsonResponse({
|
||||
success: false,
|
||||
message:
|
||||
'Failed to authenticate (are you sure account ID and password are in .env?)',
|
||||
data: null
|
||||
})
|
||||
|
||||
const request = await axios.post(
|
||||
'https://www.boomlings.com/database/getGJLevelScores211.php',
|
||||
new URLSearchParams({
|
||||
gameVersion: '22',
|
||||
binaryVersion: '45',
|
||||
accountID: process.env.ACCOUNT_ID ?? '',
|
||||
gjp2: await encodeGJP2(process.env.ACCOUNT_PASSWORD ?? ''),
|
||||
levelID: id,
|
||||
secret: 'Wmfd2893gb7',
|
||||
type: type
|
||||
}),
|
||||
{
|
||||
headers: {
|
||||
'User-Agent': ' ',
|
||||
Cookie: 'gd=1'
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
if (request.data == '-01')
|
||||
return jsonResponse({
|
||||
success: false,
|
||||
message:
|
||||
'Failed to authenticate (are you sure account ID and password are in .env?)',
|
||||
data: null
|
||||
})
|
||||
|
||||
const responseText = request.data as string
|
||||
const responseSplit = responseText.split('|')
|
||||
|
||||
return jsonResponse({
|
||||
success: true,
|
||||
message: null,
|
||||
data: responseSplit.map(item => {
|
||||
const split = splitGd(item)
|
||||
return {
|
||||
split,
|
||||
rank: +split['6'],
|
||||
username: split['1'],
|
||||
coins: +split['13'],
|
||||
playerId: +split['2'],
|
||||
accountId: +split['16'],
|
||||
date: split['42'] + ' ago',
|
||||
icon: {
|
||||
form: ['icon', 'ship', 'ball', 'ufo', 'wave', 'robot', 'spider'][
|
||||
+split['14']
|
||||
],
|
||||
icon: +split['9'],
|
||||
col1: +split['10'],
|
||||
col2: +split['11'],
|
||||
colG: +split['51'],
|
||||
glow: +split['15'] > 1
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user