From d824b83cf9e078013573098f0f9977253946f575 Mon Sep 17 00:00:00 2001 From: Sainan Date: Fri, 20 Dec 2024 03:11:09 +0100 Subject: [PATCH] feat: respect client-supplied version information (#585) --- src/controllers/api/loginController.ts | 9 +++++++-- src/controllers/dynamic/worldStateController.ts | 7 +++++-- src/routes/cache.ts | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/controllers/api/loginController.ts b/src/controllers/api/loginController.ts index 9338b3c7..40d5d5d1 100644 --- a/src/controllers/api/loginController.ts +++ b/src/controllers/api/loginController.ts @@ -20,6 +20,11 @@ const loginController: RequestHandler = async (request, response) => { const account = await Account.findOne({ email: loginRequest.email }); //{ _id: 0, __v: 0 } const nonce = Math.round(Math.random() * Number.MAX_SAFE_INTEGER); + const buildLabel: string = + typeof request.query.buildLabel == "string" + ? request.query.buildLabel.split(" ").join("+") + : buildConfig.buildLabel; + if (!account && config.autoCreateAccount && loginRequest.ClientType != "webui") { try { const newAccount = await createAccount({ @@ -45,7 +50,7 @@ const loginController: RequestHandler = async (request, response) => { DTLS: DTLS, IRC: config.myIrcAddresses ?? [config.myAddress], HUB: HUB, - BuildLabel: buildConfig.buildLabel, + BuildLabel: buildLabel, MatchmakingBuildId: buildConfig.matchmakingBuildId }; @@ -81,7 +86,7 @@ const loginController: RequestHandler = async (request, response) => { DTLS: DTLS, IRC: config.myIrcAddresses ?? [config.myAddress], HUB: HUB, - BuildLabel: buildConfig.buildLabel, + BuildLabel: buildLabel, MatchmakingBuildId: buildConfig.matchmakingBuildId }; diff --git a/src/controllers/dynamic/worldStateController.ts b/src/controllers/dynamic/worldStateController.ts index 32cfdfa0..92351233 100644 --- a/src/controllers/dynamic/worldStateController.ts +++ b/src/controllers/dynamic/worldStateController.ts @@ -2,10 +2,13 @@ import { RequestHandler } from "express"; import worldState from "@/static/fixed_responses/worldState.json"; import buildConfig from "@/static/data/buildConfig.json"; -const worldStateController: RequestHandler = (_req, res) => { +const worldStateController: RequestHandler = (req, res) => { + const buildLabel: string = + typeof req.query.buildLabel == "string" ? req.query.buildLabel.split(" ").join("+") : buildConfig.buildLabel; + res.json({ ...worldState, - BuildLabel: buildConfig.buildLabel, + BuildLabel: buildLabel, Time: Math.round(Date.now() / 1000) }); }; diff --git a/src/routes/cache.ts b/src/routes/cache.ts index 34764f22..37275394 100644 --- a/src/routes/cache.ts +++ b/src/routes/cache.ts @@ -4,8 +4,12 @@ import fs from "fs/promises"; const cacheRouter = express.Router(); -cacheRouter.get(/^\/origin\/[a-zA-Z0-9]+\/[0-9]+\/H\.Cache\.bin.*$/, (_req, res) => { - res.sendFile(`static/data/H.Cache_${buildConfig.version}.bin`, { root: "./" }); +cacheRouter.get(/^\/origin\/[a-zA-Z0-9]+\/[0-9]+\/H\.Cache\.bin.*$/, (req, res) => { + if (typeof req.query.version == "string" && req.query.version.match(/^\d\d\d\d\.\d\d\.\d\d\.\d\d\.\d\d$/)) { + res.sendFile(`static/data/H.Cache_${req.query.version}.bin`, { root: "./" }); + } else { + res.sendFile(`static/data/H.Cache_${buildConfig.version}.bin`, { root: "./" }); + } }); // eslint-disable-next-line @typescript-eslint/no-misused-promises