From 415823a980f3bf1de2ba81e9e49a1a981189c18c Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Sat, 8 Nov 2025 19:29:11 -0700 Subject: [PATCH] `/can-load-client` endpoint --- src/index.ts | 2 ++ src/info/general.ts | 5 +++++ src/lib/util.ts | 23 +++++++++++++++++++++++ src/routes/can-load-client.ts | 24 ++++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 src/info/general.ts create mode 100644 src/routes/can-load-client.ts diff --git a/src/index.ts b/src/index.ts index ba5f661..c555f1d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ import { cors } from '@elysiajs/cors' import { jsonResponse } from './lib/util' import dotenv from 'dotenv' +import { handler as canLoadClientHandler } from './routes/can-load-client' import { handler as launcherVersionsHandler } from './routes/launcher/versions' import { handler as launcherLatestHandler } from './routes/launcher/latest' import { handler as launcherLoaderLatestHandler } from './routes/launcher/loader/latest' @@ -17,6 +18,7 @@ const app = new Elysia().use( }) ) +app.get('/can-load-client', context => canLoadClientHandler(context)) app.get('/launcher/versions', context => launcherVersionsHandler(context)) app.get('/launcher/latest', launcherLatestHandler) app.get('/launcher/loader/latest', launcherLoaderLatestHandler) diff --git a/src/info/general.ts b/src/info/general.ts new file mode 100644 index 0000000..ce41dc5 --- /dev/null +++ b/src/info/general.ts @@ -0,0 +1,5 @@ +export const latestVersion = '1.8.3' +export const latestBetaVersion = latestVersion +export const latestLauncherLoaderVersion = '1.0.1' +export const allowedVersions = [latestVersion, latestBetaVersion] +export const allowedDatabaseVersions = [latestVersion, latestBetaVersion] diff --git a/src/lib/util.ts b/src/lib/util.ts index d7fafdc..a785410 100644 --- a/src/lib/util.ts +++ b/src/lib/util.ts @@ -1,5 +1,11 @@ import mysql from 'mysql2' import { drizzle } from 'drizzle-orm/mysql2' +import { + allowedDatabaseVersions, + allowedVersions, + latestBetaVersion, + latestVersion +} from '../info/general' export function jsonResponse (data: any, status = 200) { return new Response(JSON.stringify(data, null, 2), { @@ -20,3 +26,20 @@ export function getDatabaseConnection () { return { connection, db } } + +export const isLatestVersion = (version: string) => version === latestVersion + +export const isBetaVersion = (version: string) => version === latestBetaVersion + +export const isAllowedVersion = (version: string) => + allowedVersions.includes(version) + +export const isAllowedDatabaseVersion = (version: string) => + allowedDatabaseVersions.includes(version) + +export const checkClientDatabaseVersion = (request: Request) => { + const requester = request.headers.get('http_requester') ?? '' + const clientVersion = request.headers.get('http_clientversion') ?? '' + if (requester !== 'BerryDashClient') return '-998' + if (!allowedDatabaseVersions.includes(clientVersion)) return '-998' +} diff --git a/src/routes/can-load-client.ts b/src/routes/can-load-client.ts new file mode 100644 index 0000000..75db5a9 --- /dev/null +++ b/src/routes/can-load-client.ts @@ -0,0 +1,24 @@ +import { Context } from 'elysia' +import { + isAllowedDatabaseVersion, + isAllowedVersion, + isBetaVersion, + isLatestVersion +} from '../lib/util' + +export async function handler ({ request, set }: Context) { + set.headers['Content-Type'] = 'text/plain' + const requester = request.headers.get('Requester') ?? '0' + const clientVersion = request.headers.get('ClientVersion') ?? '0' + + if (requester === 'BerryDashGodotClient') return 'all;1.0.0' + else if (isLatestVersion(clientVersion)) return '1' + else if (isBetaVersion(clientVersion)) return '4' + else if ( + isAllowedVersion(clientVersion) && + isAllowedDatabaseVersion(clientVersion) + ) + return '2' + else if (isAllowedVersion(clientVersion)) return '3' + return '-1' +}