XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
UTF-8
import crypto from "node:crypto";
import { args } from "../helpers/commandLineArguments.ts";
import type { ITunables } from "../types/bootstrapperTypes.ts";
import { config } from "./configService.ts";

let secret;
if (args.secret) {
    secret = args.secret; // Maintain same secret across hot reloads in dev mode
} else {
    secret = "";
    for (let i = 0; i != 10; ++i) {
        secret += String.fromCharCode(Math.floor(Math.random() * 26) + 0x41);
    }
}

export const getTokenForClient = (clientAddress: string): string => {
    return crypto.createHmac("sha256", secret).update(clientAddress).digest("hex");
};

export const getTunablesForClient = (clientAddress: string, reflexiveAddress: string): ITunables => {
    const tunables: ITunables = {
        // To successfully update the NRS address for pre-U15.14 clients, this needs to be set before login.
        nrs: ((config.nrsAddresses ?? [])[0] || "%THIS_MACHINE%").replaceAll("%THIS_MACHINE%", reflexiveAddress),

        // if (version_compare(buildLabel, gameToBuildVersion["16.5.5"]) < 0) {
        irc: (config.ircAddress || "%THIS_MACHINE%").replaceAll("%THIS_MACHINE%", reflexiveAddress)
    };
    if (config.tunables?.useLoginToken) {
        tunables.token = getTokenForClient(clientAddress);
    }
    if (config.tunables?.prohibitSkipMissionStartTimer) {
        tunables.prohibit_skip_mission_start_timer = true;
    }
    if (config.tunables?.prohibitDisableProfanityFilter) {
        tunables.prohibit_disable_profanity_filter = true;
    }
    if (config.tunables?.prohibitFovOverride) {
        tunables.prohibit_fov_override = true;
    }
    if (config.tunables?.prohibitFreecam) {
        tunables.prohibit_freecam = true;
    }
    if (config.tunables?.prohibitTeleport) {
        tunables.prohibit_teleport = true;
    }
    if (config.tunables?.prohibitScripts) {
        tunables.prohibit_scripts = true;
    }
    if (config.tunables?.motd) {
        tunables.motd = config.tunables.motd;
    }
    if (config.tunables?.udpProxyUpstream) {
        tunables.udp_proxy_upstream = config.tunables.udpProxyUpstream.replaceAll("%THIS_MACHINE%", reflexiveAddress);
    }
    return tunables;
};