forked from OpenWF/SpaceNinjaServer
		
	feat: respect client-supplied version information (#585)
This commit is contained in:
		
							parent
							
								
									259bfa1362
								
							
						
					
					
						commit
						d824b83cf9
					
				@ -20,6 +20,11 @@ const loginController: RequestHandler = async (request, response) => {
 | 
				
			|||||||
    const account = await Account.findOne({ email: loginRequest.email }); //{ _id: 0, __v: 0 }
 | 
					    const account = await Account.findOne({ email: loginRequest.email }); //{ _id: 0, __v: 0 }
 | 
				
			||||||
    const nonce = Math.round(Math.random() * Number.MAX_SAFE_INTEGER);
 | 
					    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") {
 | 
					    if (!account && config.autoCreateAccount && loginRequest.ClientType != "webui") {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            const newAccount = await createAccount({
 | 
					            const newAccount = await createAccount({
 | 
				
			||||||
@ -45,7 +50,7 @@ const loginController: RequestHandler = async (request, response) => {
 | 
				
			|||||||
                DTLS: DTLS,
 | 
					                DTLS: DTLS,
 | 
				
			||||||
                IRC: config.myIrcAddresses ?? [config.myAddress],
 | 
					                IRC: config.myIrcAddresses ?? [config.myAddress],
 | 
				
			||||||
                HUB: HUB,
 | 
					                HUB: HUB,
 | 
				
			||||||
                BuildLabel: buildConfig.buildLabel,
 | 
					                BuildLabel: buildLabel,
 | 
				
			||||||
                MatchmakingBuildId: buildConfig.matchmakingBuildId
 | 
					                MatchmakingBuildId: buildConfig.matchmakingBuildId
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -81,7 +86,7 @@ const loginController: RequestHandler = async (request, response) => {
 | 
				
			|||||||
        DTLS: DTLS,
 | 
					        DTLS: DTLS,
 | 
				
			||||||
        IRC: config.myIrcAddresses ?? [config.myAddress],
 | 
					        IRC: config.myIrcAddresses ?? [config.myAddress],
 | 
				
			||||||
        HUB: HUB,
 | 
					        HUB: HUB,
 | 
				
			||||||
        BuildLabel: buildConfig.buildLabel,
 | 
					        BuildLabel: buildLabel,
 | 
				
			||||||
        MatchmakingBuildId: buildConfig.matchmakingBuildId
 | 
					        MatchmakingBuildId: buildConfig.matchmakingBuildId
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -2,10 +2,13 @@ import { RequestHandler } from "express";
 | 
				
			|||||||
import worldState from "@/static/fixed_responses/worldState.json";
 | 
					import worldState from "@/static/fixed_responses/worldState.json";
 | 
				
			||||||
import buildConfig from "@/static/data/buildConfig.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({
 | 
					    res.json({
 | 
				
			||||||
        ...worldState,
 | 
					        ...worldState,
 | 
				
			||||||
        BuildLabel: buildConfig.buildLabel,
 | 
					        BuildLabel: buildLabel,
 | 
				
			||||||
        Time: Math.round(Date.now() / 1000)
 | 
					        Time: Math.round(Date.now() / 1000)
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -4,8 +4,12 @@ import fs from "fs/promises";
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const cacheRouter = express.Router();
 | 
					const cacheRouter = express.Router();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cacheRouter.get(/^\/origin\/[a-zA-Z0-9]+\/[0-9]+\/H\.Cache\.bin.*$/, (_req, res) => {
 | 
					cacheRouter.get(/^\/origin\/[a-zA-Z0-9]+\/[0-9]+\/H\.Cache\.bin.*$/, (req, res) => {
 | 
				
			||||||
    res.sendFile(`static/data/H.Cache_${buildConfig.version}.bin`, { root: "./" });
 | 
					    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
 | 
					// eslint-disable-next-line @typescript-eslint/no-misused-promises
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user