From 91ec0144ed2cf34e39c1d639eed85c4c17070093 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 10 Aug 2023 14:29:09 +0100 Subject: [PATCH] Esxpose two endpoints for launcher to get mod-related data --- project/src/callbacks/LauncherCallbacks.ts | 11 +++++++++++ project/src/controllers/LauncherController.ts | 18 +++++++++++++++++- project/src/helpers/InRaidHelper.ts | 2 +- .../src/routers/static/LauncherStaticRouter.ts | 16 ++++++++++++++++ project/src/utils/HttpResponseUtil.ts | 5 +++++ 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/project/src/callbacks/LauncherCallbacks.ts b/project/src/callbacks/LauncherCallbacks.ts index 359f843e..2400f8d0 100644 --- a/project/src/callbacks/LauncherCallbacks.ts +++ b/project/src/callbacks/LauncherCallbacks.ts @@ -88,6 +88,17 @@ class LauncherCallbacks { return this.httpResponse.noBody(this.launcherController.getCompatibleTarkovVersion()); } + + public getLoadedServerMods(): string + { + return this.httpResponse.noBody(this.launcherController.getLoadedServerMods()); + } + + public getServerModsProfileUsed(url: string, info: IEmptyRequestData, sessionId: string): string + { + return this.httpResponse.noBody(this.launcherController.getServerModsProfileUsed(sessionId)); + } } export { LauncherCallbacks }; + diff --git a/project/src/controllers/LauncherController.ts b/project/src/controllers/LauncherController.ts index f9b660d1..34c46840 100644 --- a/project/src/controllers/LauncherController.ts +++ b/project/src/controllers/LauncherController.ts @@ -1,13 +1,16 @@ import { inject, injectable } from "tsyringe"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; +import { ProfileHelper } from "../helpers/ProfileHelper"; +import { PreAkiModLoader } from "../loaders/PreAkiModLoader"; import { IChangeRequestData } from "../models/eft/launcher/IChangeRequestData"; import { ILoginRequestData } from "../models/eft/launcher/ILoginRequestData"; import { IRegisterData } from "../models/eft/launcher/IRegisterData"; -import { Info } from "../models/eft/profile/IAkiProfile"; +import { Info, ModDetails } from "../models/eft/profile/IAkiProfile"; import { IConnectResponse } from "../models/eft/profile/IConnectResponse"; import { ConfigTypes } from "../models/enums/ConfigTypes"; import { ICoreConfig } from "../models/spt/config/ICoreConfig"; +import { IPackageJsonData } from "../models/spt/mod/IPackageJsonData"; import { ConfigServer } from "../servers/ConfigServer"; import { DatabaseServer } from "../servers/DatabaseServer"; import { SaveServer } from "../servers/SaveServer"; @@ -23,8 +26,10 @@ export class LauncherController @inject("HashUtil") protected hashUtil: HashUtil, @inject("SaveServer") protected saveServer: SaveServer, @inject("HttpServerHelper") protected httpServerHelper: HttpServerHelper, + @inject("ProfileHelper") protected profileHelper: ProfileHelper, @inject("DatabaseServer") protected databaseServer: DatabaseServer, @inject("LocalisationService") protected localisationService: LocalisationService, + @inject("PreAkiModLoader") protected preAkiModLoader: PreAkiModLoader, @inject("ConfigServer") protected configServer: ConfigServer ) { @@ -160,4 +165,15 @@ export class LauncherController { return this.coreConfig.compatibleTarkovVersion; } + + public getLoadedServerMods(): Record + { + return this.preAkiModLoader.getImportedModDetails(); + } + + public getServerModsProfileUsed(sessionId: string): ModDetails[] + { + const profile = this.profileHelper.getFullProfile(sessionId); + return profile?.aki?.mods; + } } diff --git a/project/src/helpers/InRaidHelper.ts b/project/src/helpers/InRaidHelper.ts index 49029be1..d602483c 100644 --- a/project/src/helpers/InRaidHelper.ts +++ b/project/src/helpers/InRaidHelper.ts @@ -52,7 +52,7 @@ export class InRaidHelper } /** - * Check an array of items and add an upd object to money items with a stack count of 1 + * Check items array and add an upd object to money with a stack count of 1 * Single stack money items have no upd object and thus no StackObjectsCount, causing issues * @param items Items array to check */ diff --git a/project/src/routers/static/LauncherStaticRouter.ts b/project/src/routers/static/LauncherStaticRouter.ts index 86d4381a..9423f667 100644 --- a/project/src/routers/static/LauncherStaticRouter.ts +++ b/project/src/routers/static/LauncherStaticRouter.ts @@ -99,6 +99,22 @@ export class LauncherStaticRouter extends StaticRouter { return this.launcherCallbacks.getServerVersion(); } + ), + new RouteAction( + "/launcher/server/loadedServerMods", + // eslint-disable-next-line @typescript-eslint/no-unused-vars + (url: string, info: any, sessionID: string, output: string): any => + { + return this.launcherCallbacks.getLoadedServerMods(); + } + ), + new RouteAction( + "/launcher/server/serverModsUsedByProfile", + // eslint-disable-next-line @typescript-eslint/no-unused-vars + (url: string, info: any, sessionID: string, output: string): any => + { + return this.launcherCallbacks.getServerModsProfileUsed(url, info, sessionID); + } ) ] ); diff --git a/project/src/utils/HttpResponseUtil.ts b/project/src/utils/HttpResponseUtil.ts index c02f7d37..71279de2 100644 --- a/project/src/utils/HttpResponseUtil.ts +++ b/project/src/utils/HttpResponseUtil.ts @@ -27,6 +27,11 @@ export class HttpResponseUtil .replace(/[\\]/g, ""); } + /** + * Return passed in data as JSON string + * @param data + * @returns + */ public noBody(data: any): any { return this.clearString(this.jsonUtil.serialize(data));