diff --git a/project/src/callbacks/LauncherCallbacks.ts b/project/src/callbacks/LauncherCallbacks.ts index e60cc5f1..588c2b12 100644 --- a/project/src/callbacks/LauncherCallbacks.ts +++ b/project/src/callbacks/LauncherCallbacks.ts @@ -16,7 +16,7 @@ export class LauncherCallbacks { @inject("LauncherController") protected launcherController: LauncherController, @inject("SaveServer") protected saveServer: SaveServer, @inject("Watermark") protected watermark: Watermark, - ) {} + ) { } public connect(): string { return this.httpResponse.noBody(this.launcherController.connect()); diff --git a/project/src/callbacks/Launcherv2Callbacks.ts b/project/src/callbacks/Launcherv2Callbacks.ts new file mode 100644 index 00000000..4e6a8b31 --- /dev/null +++ b/project/src/callbacks/Launcherv2Callbacks.ts @@ -0,0 +1,98 @@ +import { LauncherV2Controller } from "@spt/controllers/LauncherV2Controller"; +import { ProfileController } from "@spt/controllers/ProfileController"; +import { IChangeRequestData } from "@spt/models/eft/launcher/IChangeRequestData"; +import { ILoginRequestData } from "@spt/models/eft/launcher/ILoginRequestData"; +import { IRegisterData } from "@spt/models/eft/launcher/IRegisterData"; +import { ILauncherV2LoginResponse } from "@spt/models/spt/launcher/ILauncherV2LoginResponse"; +import { ILauncherV2ModsResponse } from "@spt/models/spt/launcher/ILauncherV2ModsResponse"; +import { ILauncherV2PasswordChangeResponse } from "@spt/models/spt/launcher/ILauncherV2PasswordChangeResponse"; +import { ILauncherV2PingResponse } from "@spt/models/spt/launcher/ILauncherV2PingResponse"; +import { ILauncherV2ProfilesResponse } from "@spt/models/spt/launcher/ILauncherV2ProfilesResponse"; +import { ILauncherV2RegisterResponse } from "@spt/models/spt/launcher/ILauncherV2RegisterResponse"; +import { ILauncherV2RemoveResponse } from "@spt/models/spt/launcher/ILauncherV2RemoveResponse"; +import { ILauncherV2TypesResponse } from "@spt/models/spt/launcher/ILauncherV2TypesResponse"; +import { ILauncherV2VersionResponse } from "@spt/models/spt/launcher/ILauncherV2VersionResponse"; +import { SaveServer } from "@spt/servers/SaveServer"; +import { HttpResponseUtil } from "@spt/utils/HttpResponseUtil"; +import { Watermark } from "@spt/utils/Watermark"; +import { inject, injectable } from "tsyringe"; + +@injectable() +export class LauncherV2Callbacks { + + constructor( + @inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil, + @inject("LauncherV2Controller") protected launcherV2Controller: LauncherV2Controller, + @inject("ProfileController") protected profileController: ProfileController, + @inject("SaveServer") protected saveServer: SaveServer, + @inject("Watermark") protected watermark: Watermark, + ) { } + + public ping(): ILauncherV2PingResponse { + return this.httpResponse.noBody({ + response: this.launcherV2Controller.ping(), + }); + } + + public types(): ILauncherV2TypesResponse { + return this.httpResponse.noBody({ + response: this.launcherV2Controller.types(), + }) + } + + public login(info: ILoginRequestData): ILauncherV2LoginResponse { + return this.httpResponse.noBody({ + response: this.launcherV2Controller.login(info), + }) + } + + public register(info: IRegisterData): ILauncherV2RegisterResponse { + return this.httpResponse.noBody({ + response: this.launcherV2Controller.register(info), + profiles: this.profileController.getMiniProfiles(), + }) + } + + public passwordChange(info: IChangeRequestData): ILauncherV2PasswordChangeResponse { + return this.httpResponse.noBody({ + response: this.launcherV2Controller.passwordChange(info), + profiles: this.profileController.getMiniProfiles(), + }) + } + + public remove(info: ILoginRequestData): ILauncherV2RemoveResponse { + return this.httpResponse.noBody({ + response: this.launcherV2Controller.remove(info), + profiles: this.profileController.getMiniProfiles(), + }) + } + + public compatibleVersion(): ILauncherV2VersionResponse { + return this.httpResponse.noBody({ + response: { + sptVersion: this.launcherV2Controller.sptVersion(), + eftVersion: this.launcherV2Controller.eftVersion(), + } + }) + } + + public mods(): ILauncherV2ModsResponse { + return this.httpResponse.noBody({ + response: this.launcherV2Controller.loadedMods(), + }) + } + + public profiles(): ILauncherV2ProfilesResponse { + return this.httpResponse.noBody({ + response: this.profileController.getMiniProfiles(), + }) + } + + public profile(): Error { + throw new Error("Method not implemented."); + } + + public profileMods(): Error { + throw new Error("Method not implemented."); + } +} \ No newline at end of file diff --git a/project/src/controllers/LauncherController.ts b/project/src/controllers/LauncherController.ts index b5045fe9..d86c2d4d 100644 --- a/project/src/controllers/LauncherController.ts +++ b/project/src/controllers/LauncherController.ts @@ -80,7 +80,7 @@ export class LauncherController { public login(info: ILoginRequestData): string { for (const sessionID in this.saveServer.getProfiles()) { const account = this.saveServer.getProfile(sessionID).info; - if (info.username === account.username) { + if (info.username === account.username && info.password === account.password) { return sessionID; } } diff --git a/project/src/controllers/LauncherV2Controller.ts b/project/src/controllers/LauncherV2Controller.ts new file mode 100644 index 00000000..015a4e57 --- /dev/null +++ b/project/src/controllers/LauncherV2Controller.ts @@ -0,0 +1,248 @@ +import { PreSptModLoader } from "@spt/loaders/PreSptModLoader"; +import { IChangeRequestData } from "@spt/models/eft/launcher/IChangeRequestData"; +import { ILoginRequestData } from "@spt/models/eft/launcher/ILoginRequestData"; +import { IRegisterData } from "@spt/models/eft/launcher/IRegisterData"; +import { Info } from "@spt/models/eft/profile/ISptProfile"; +import { ConfigTypes } from "@spt/models/enums/ConfigTypes"; +import { ICoreConfig } from "@spt/models/spt/config/ICoreConfig"; +import { IPackageJsonData } from "@spt/models/spt/mod/IPackageJsonData"; +import { ILogger } from "@spt/models/spt/utils/ILogger"; +import { ConfigServer } from "@spt/servers/ConfigServer"; +import { SaveServer } from "@spt/servers/SaveServer"; +import { DatabaseService } from "@spt/services/DatabaseService"; +import { LocalisationService } from "@spt/services/LocalisationService"; +import { HashUtil } from "@spt/utils/HashUtil"; +import { RandomUtil } from "@spt/utils/RandomUtil"; +import { TimeUtil } from "@spt/utils/TimeUtil"; +import { Watermark } from "@spt/utils/Watermark"; +import { inject, injectable } from "tsyringe"; + +@injectable() +export class LauncherV2Controller { + protected coreConfig: ICoreConfig + + constructor( + @inject("PrimaryLogger") protected logger: ILogger, + @inject("DatabaseService") protected databaseService: DatabaseService, + @inject("ConfigServer") protected configServer: ConfigServer, + @inject("LocalisationService") protected localisationService: LocalisationService, + @inject("SaveServer") protected saveServer: SaveServer, + @inject("HashUtil") protected hashUtil: HashUtil, + @inject("TimeUtil") protected timeUtil: TimeUtil, + @inject("RandomUtil") protected randomUtil: RandomUtil, + @inject("Watermark") protected watermark: Watermark, + @inject("PreSptModLoader") protected preSptModLoader: PreSptModLoader, + ) { + this.coreConfig = this.configServer.getConfig(ConfigTypes.CORE); + } + + /** + * Returns a simple string of pong! + * @returns "pong!" + */ + public ping(): string { + return "pong!"; + } + + /** + * Returns all available profile types and descriptions for creation. + * - This is also localised. + * + * @returns Record of Profile types and Descriptions + */ + public types(): Record { + + const profileRecord: Record = {}; + + // Get all possible profile types, excluding blacklisted ones + const profileKeys = Object.keys(this.databaseService.getProfiles()).filter( + (key) => !this.coreConfig.features.createNewProfileTypesBlacklist.includes(key), + ); + + // Add them to record with description + for (const profileKey in profileKeys) { + profileRecord[profileKey] = this.getProfileDescription(profileKey); + } + + return profileRecord; + } + + /** + * Returns a string that represents the Profile types description. + * - This is also localised. + * + * @param key Profile Type Name: eg "standard" + * @returns Profile Type Description + */ + protected getProfileDescription(key: string): string { + const dbProfiles = this.databaseService.getProfiles(); + const descKey = dbProfiles[key]?.descriptionLocaleKey; + if (!descKey) { + this.logger.warning(this.localisationService.getText("launcher-missing_property", key)); + return ""; + } + + return this.localisationService.getText(key); + } + + /** + * Checks if login details were correct. + * + * @param info ILoginRequestData + * @returns If login was successful or not + */ + public login(info: ILoginRequestData): boolean { + const sessionID = this.getSessionID(info); + + if (!sessionID) { + return false; + } + + return true; + } + + /** + * Register a new profile. + * + * @param info IRegisterData + * @returns If register was successful or not + */ + public register(info: IRegisterData): boolean { + for (const sessionID in this.saveServer.getProfiles()) { + if (info.username === this.saveServer.getProfile(sessionID).info.username) { + return false; + } + } + + this.createAccount(info); + return true; + } + + /** + * Make a password change. + * + * @param info IChangeRequestData + * @returns If change was successful or not + */ + public passwordChange(info: IChangeRequestData): boolean { + const sessionID = this.getSessionID(info); + + if (!sessionID) { + return false; + } + + this.saveServer.getProfile(sessionID).info.password = info.change; + return true; + } + + /** + * Remove profile from server. + * + * @param info ILoginRequestData + * @returns If removal was successful or not + */ + public remove(info: ILoginRequestData): boolean { + const sessionID = this.getSessionID(info); + + if (!sessionID) { + return false; + } + + return this.saveServer.removeProfile(sessionID); + } + + /** + * Gets the Servers SPT Version. + * + * @returns "3.10.0" + */ + public sptVersion(): string { + return this.watermark.getVersionTag(); + } + + /** + * Gets the compatible EFT Version. + * + * @returns "0.14.9.31124" + */ + public eftVersion(): string { + return this.coreConfig.compatibleTarkovVersion; + } + + /** + * Gets the Servers loaded mods. + * + * @returns Record of Mod names to Mod Package Json Details + */ + public loadedMods(): Record { + return this.preSptModLoader.getImportedModDetails(); + } + + /** + * Creates the account from provided details. + * + * @param info IRegisterData + * @returns ProfileID of new account + */ + protected createAccount(info: IRegisterData): string { + const profileId = this.generateProfileId(); + const scavId = this.generateProfileId(); + const newProfileDetails: Info = { + id: profileId, + scavId: scavId, + aid: this.hashUtil.generateAccountId(), + username: info.username, + password: info.password, + wipe: true, + edition: info.edition, + }; + this.saveServer.createProfile(newProfileDetails); + + this.saveServer.loadProfile(profileId); + this.saveServer.saveProfile(profileId); + + return profileId; + } + + /** + * Generates a new ProfileID to use. + * + * @returns ProfileID generated + */ + protected generateProfileId(): string { + const timestamp = this.timeUtil.getTimestamp(); + + return this.formatID(timestamp, timestamp * this.randomUtil.getInt(1, 1000000)); + } + + /** + * Formats ID by lower-casing. + * + * @param timeStamp number + * @param counter number + * @returns Formatted ID + */ + protected formatID(timeStamp: number, counter: number): string { + const timeStampStr = timeStamp.toString(16).padStart(8, "0"); + const counterStr = counter.toString(16).padStart(16, "0"); + + return timeStampStr.toLowerCase() + counterStr.toLowerCase(); + } + + /** + * Gets ProfileID from profile. + * + * @param info ILoginRequestData + * @returns ProfileID if successful otherwise empty string + */ + protected getSessionID(info: ILoginRequestData): string { + for (const sessionID in this.saveServer.getProfiles()) { + const account = this.saveServer.getProfile(sessionID).info; + if (info.username === account.username && info.password === account.password) { + return sessionID; + } + } + + return ""; + } +} \ No newline at end of file diff --git a/project/src/controllers/ProfileController.ts b/project/src/controllers/ProfileController.ts index 5908a255..4bf0bbc6 100644 --- a/project/src/controllers/ProfileController.ts +++ b/project/src/controllers/ProfileController.ts @@ -55,7 +55,7 @@ export class ProfileController { @inject("DialogueHelper") protected dialogueHelper: DialogueHelper, @inject("QuestHelper") protected questHelper: QuestHelper, @inject("ProfileHelper") protected profileHelper: ProfileHelper, - ) {} + ) { } /** * Handle /launcher/profiles @@ -77,38 +77,22 @@ export class ProfileController { const pmc = profile.characters.pmc; const maxlvl = this.profileHelper.getMaxLevel(); - - // Player hasn't completed profile creation process, send defaults - if (!pmc?.Info?.Level) { - return { - username: profile.info?.username ?? "", - nickname: "unknown", - side: "unknown", - currlvl: 0, - currexp: 0, - prevexp: 0, - nextlvl: 0, - maxlvl: maxlvl, - edition: profile.info?.edition ?? "", - profileId: profile.info?.id ?? "", - sptData: this.profileHelper.getDefaultSptDataObject(), - }; - } - - const currlvl = pmc.Info.Level; + const currlvl = pmc?.Info?.Level ?? 0; const nextlvl = this.profileHelper.getExperience(currlvl + 1); + return { - username: profile.info.username, - nickname: pmc.Info.Nickname, - side: pmc.Info.Side, - currlvl: pmc.Info.Level, - currexp: pmc.Info.Experience ?? 0, + username: profile.info?.username ?? "", + nickname: pmc.Info?.Nickname ?? "unknown", + hasPassword: (profile?.info?.password !== ""), + side: pmc?.Info?.Side ?? "unknown", + currlvl: pmc?.Info?.Level ?? 0, + currexp: pmc?.Info?.Experience ?? 0, prevexp: currlvl === 0 ? 0 : this.profileHelper.getExperience(currlvl), nextlvl: nextlvl, maxlvl: maxlvl, - edition: profile.info?.edition ?? "", - profileId: profile.info?.id ?? "", - sptData: profile.spt, + edition: profile?.info?.edition ?? "", + profileId: profile?.info?.id ?? "", + sptData: profile?.spt ?? this.profileHelper.getDefaultSptDataObject(), }; } diff --git a/project/src/di/Container.ts b/project/src/di/Container.ts index 2663a5ce..4c396461 100644 --- a/project/src/di/Container.ts +++ b/project/src/di/Container.ts @@ -16,6 +16,7 @@ import { InsuranceCallbacks } from "@spt/callbacks/InsuranceCallbacks"; import { InventoryCallbacks } from "@spt/callbacks/InventoryCallbacks"; import { ItemEventCallbacks } from "@spt/callbacks/ItemEventCallbacks"; import { LauncherCallbacks } from "@spt/callbacks/LauncherCallbacks"; +import { LauncherV2Callbacks } from "@spt/callbacks/Launcherv2Callbacks"; import { LocationCallbacks } from "@spt/callbacks/LocationCallbacks"; import { MatchCallbacks } from "@spt/callbacks/MatchCallbacks"; import { ModCallbacks } from "@spt/callbacks/ModCallbacks"; @@ -46,6 +47,7 @@ import { InraidController } from "@spt/controllers/InraidController"; import { InsuranceController } from "@spt/controllers/InsuranceController"; import { InventoryController } from "@spt/controllers/InventoryController"; import { LauncherController } from "@spt/controllers/LauncherController"; +import { LauncherV2Controller } from "@spt/controllers/LauncherV2Controller"; import { LocationController } from "@spt/controllers/LocationController"; import { MatchController } from "@spt/controllers/MatchController"; import { NoteController } from "@spt/controllers/NoteController"; @@ -177,6 +179,7 @@ import { InraidStaticRouter } from "@spt/routers/static/InraidStaticRouter"; import { InsuranceStaticRouter } from "@spt/routers/static/InsuranceStaticRouter"; import { ItemEventStaticRouter } from "@spt/routers/static/ItemEventStaticRouter"; import { LauncherStaticRouter } from "@spt/routers/static/LauncherStaticRouter"; +import { LauncherV2StaticRouter } from "@spt/routers/static/LauncherV2StaticRouter"; import { LocationStaticRouter } from "@spt/routers/static/LocationStaticRouter"; import { MatchStaticRouter } from "@spt/routers/static/MatchStaticRouter"; import { NotifierStaticRouter } from "@spt/routers/static/NotifierStaticRouter"; @@ -350,6 +353,7 @@ export class Container { depContainer.registerType("StaticRoutes", "InsuranceStaticRouter"); depContainer.registerType("StaticRoutes", "ItemEventStaticRouter"); depContainer.registerType("StaticRoutes", "LauncherStaticRouter"); + depContainer.registerType("StaticRoutes", "LauncherV2StaticRouter"); depContainer.registerType("StaticRoutes", "LocationStaticRouter"); depContainer.registerType("StaticRoutes", "WeatherStaticRouter"); depContainer.registerType("StaticRoutes", "MatchStaticRouter"); @@ -515,6 +519,7 @@ export class Container { depContainer.register("InsuranceStaticRouter", { useClass: InsuranceStaticRouter }); depContainer.register("ItemEventStaticRouter", { useClass: ItemEventStaticRouter }); depContainer.register("LauncherStaticRouter", { useClass: LauncherStaticRouter }); + depContainer.register("LauncherV2StaticRouter", { useClass: LauncherV2StaticRouter }); depContainer.register("LocationStaticRouter", { useClass: LocationStaticRouter }); depContainer.register("MatchStaticRouter", { useClass: MatchStaticRouter }); depContainer.register("NotifierStaticRouter", { useClass: NotifierStaticRouter }); @@ -666,6 +671,7 @@ export class Container { depContainer.register("InventoryCallbacks", { useClass: InventoryCallbacks }); depContainer.register("ItemEventCallbacks", { useClass: ItemEventCallbacks }); depContainer.register("LauncherCallbacks", { useClass: LauncherCallbacks }); + depContainer.register("LauncherV2Callbacks", { useClass: LauncherV2Callbacks }); depContainer.register("LocationCallbacks", { useClass: LocationCallbacks }); depContainer.register("MatchCallbacks", { useClass: MatchCallbacks }); depContainer.register("ModCallbacks", { useClass: ModCallbacks }); @@ -836,6 +842,7 @@ export class Container { depContainer.register("InsuranceController", { useClass: InsuranceController }); depContainer.register("InventoryController", { useClass: InventoryController }); depContainer.register("LauncherController", { useClass: LauncherController }); + depContainer.register("LauncherV2Controller", { useClass: LauncherV2Controller }); depContainer.register("LocationController", { useClass: LocationController }); depContainer.register("MatchController", MatchController); depContainer.register("NoteController", { useClass: NoteController }); diff --git a/project/src/models/eft/launcher/IMiniProfile.ts b/project/src/models/eft/launcher/IMiniProfile.ts index f9a0a2b6..e192eb8e 100644 --- a/project/src/models/eft/launcher/IMiniProfile.ts +++ b/project/src/models/eft/launcher/IMiniProfile.ts @@ -3,6 +3,7 @@ import { Spt } from "../profile/ISptProfile"; export interface IMiniProfile { username: string; nickname: string; + hasPassword: boolean; side: string; currlvl: number; currexp: number; diff --git a/project/src/models/spt/callbacks/ILauncherV2Callbacks.ts b/project/src/models/spt/callbacks/ILauncherV2Callbacks.ts new file mode 100644 index 00000000..f743fdcf --- /dev/null +++ b/project/src/models/spt/callbacks/ILauncherV2Callbacks.ts @@ -0,0 +1,25 @@ +import { IChangeRequestData } from "@spt/models/eft/launcher/IChangeRequestData"; +import { ILoginRequestData } from "@spt/models/eft/launcher/ILoginRequestData"; +import { IRegisterData } from "@spt/models/eft/launcher/IRegisterData"; +import { ILauncherV2LoginResponse } from "../launcher/ILauncherV2LoginResponse"; +import { ILauncherV2ModsResponse } from "../launcher/ILauncherV2ModsResponse"; +import { ILauncherV2PasswordChangeResponse } from "../launcher/ILauncherV2PasswordChangeResponse"; +import { ILauncherV2PingResponse } from "../launcher/ILauncherV2PingResponse"; +import { ILauncherV2ProfilesResponse } from "../launcher/ILauncherV2ProfilesResponse"; +import { ILauncherV2RegisterResponse } from "../launcher/ILauncherV2RegisterResponse"; +import { ILauncherV2TypesResponse } from "../launcher/ILauncherV2TypesResponse"; +import { ILauncherV2VersionResponse } from "../launcher/ILauncherV2VersionResponse"; + +export interface ILauncherV2Callbacks { + ping(): ILauncherV2PingResponse; + types(): ILauncherV2TypesResponse; + login(info: ILoginRequestData): ILauncherV2LoginResponse; + register(info: IRegisterData): ILauncherV2RegisterResponse; + passwordChange(info: IChangeRequestData): ILauncherV2PasswordChangeResponse; + remove(info: ILoginRequestData): ILauncherV2LoginResponse; + compatibleVersion(): ILauncherV2VersionResponse; + mods(): ILauncherV2ModsResponse; + profiles(): ILauncherV2ProfilesResponse; + profile(): Error + profileMods(): Error +} \ No newline at end of file diff --git a/project/src/models/spt/launcher/ILauncherV2CompatibleVersion.ts b/project/src/models/spt/launcher/ILauncherV2CompatibleVersion.ts new file mode 100644 index 00000000..5bfc7d47 --- /dev/null +++ b/project/src/models/spt/launcher/ILauncherV2CompatibleVersion.ts @@ -0,0 +1,4 @@ +export interface ILauncherV2CompatibleVersion { + sptVersion: string + eftVersion: string +} \ No newline at end of file diff --git a/project/src/models/spt/launcher/ILauncherV2LoginResponse.ts b/project/src/models/spt/launcher/ILauncherV2LoginResponse.ts new file mode 100644 index 00000000..865386e8 --- /dev/null +++ b/project/src/models/spt/launcher/ILauncherV2LoginResponse.ts @@ -0,0 +1,3 @@ +export interface ILauncherV2LoginResponse { + response: boolean +} \ No newline at end of file diff --git a/project/src/models/spt/launcher/ILauncherV2ModsResponse.ts b/project/src/models/spt/launcher/ILauncherV2ModsResponse.ts new file mode 100644 index 00000000..6289e316 --- /dev/null +++ b/project/src/models/spt/launcher/ILauncherV2ModsResponse.ts @@ -0,0 +1,5 @@ +import { IPackageJsonData } from "../mod/IPackageJsonData"; + +export interface ILauncherV2ModsResponse { + response: Record +} \ No newline at end of file diff --git a/project/src/models/spt/launcher/ILauncherV2PasswordChangeResponse.ts b/project/src/models/spt/launcher/ILauncherV2PasswordChangeResponse.ts new file mode 100644 index 00000000..2ba272ed --- /dev/null +++ b/project/src/models/spt/launcher/ILauncherV2PasswordChangeResponse.ts @@ -0,0 +1,6 @@ +import { IMiniProfile } from "@spt/models/eft/launcher/IMiniProfile" + +export interface ILauncherV2PasswordChangeResponse { + response: boolean + profiles: IMiniProfile[] +} \ No newline at end of file diff --git a/project/src/models/spt/launcher/ILauncherV2PingResponse.ts b/project/src/models/spt/launcher/ILauncherV2PingResponse.ts new file mode 100644 index 00000000..07965567 --- /dev/null +++ b/project/src/models/spt/launcher/ILauncherV2PingResponse.ts @@ -0,0 +1,3 @@ +export interface ILauncherV2PingResponse { + response: string +} \ No newline at end of file diff --git a/project/src/models/spt/launcher/ILauncherV2ProfilesResponse.ts b/project/src/models/spt/launcher/ILauncherV2ProfilesResponse.ts new file mode 100644 index 00000000..7d58e06d --- /dev/null +++ b/project/src/models/spt/launcher/ILauncherV2ProfilesResponse.ts @@ -0,0 +1,5 @@ +import { IMiniProfile } from "@spt/models/eft/launcher/IMiniProfile"; + +export interface ILauncherV2ProfilesResponse { + response: IMiniProfile[] +} \ No newline at end of file diff --git a/project/src/models/spt/launcher/ILauncherV2RegisterResponse.ts b/project/src/models/spt/launcher/ILauncherV2RegisterResponse.ts new file mode 100644 index 00000000..04092368 --- /dev/null +++ b/project/src/models/spt/launcher/ILauncherV2RegisterResponse.ts @@ -0,0 +1,6 @@ +import { IMiniProfile } from "@spt/models/eft/launcher/IMiniProfile" + +export interface ILauncherV2RegisterResponse { + response: boolean + profiles: IMiniProfile[] +} \ No newline at end of file diff --git a/project/src/models/spt/launcher/ILauncherV2RemoveResponse.ts b/project/src/models/spt/launcher/ILauncherV2RemoveResponse.ts new file mode 100644 index 00000000..985ba75c --- /dev/null +++ b/project/src/models/spt/launcher/ILauncherV2RemoveResponse.ts @@ -0,0 +1,6 @@ +import { IMiniProfile } from "@spt/models/eft/launcher/IMiniProfile" + +export interface ILauncherV2RemoveResponse { + response: boolean + profiles: IMiniProfile[] +} \ No newline at end of file diff --git a/project/src/models/spt/launcher/ILauncherV2TypesResponse.ts b/project/src/models/spt/launcher/ILauncherV2TypesResponse.ts new file mode 100644 index 00000000..a8becb75 --- /dev/null +++ b/project/src/models/spt/launcher/ILauncherV2TypesResponse.ts @@ -0,0 +1,3 @@ +export interface ILauncherV2TypesResponse { + response: Record +} \ No newline at end of file diff --git a/project/src/models/spt/launcher/ILauncherV2VersionResponse.ts b/project/src/models/spt/launcher/ILauncherV2VersionResponse.ts new file mode 100644 index 00000000..859ea43f --- /dev/null +++ b/project/src/models/spt/launcher/ILauncherV2VersionResponse.ts @@ -0,0 +1,5 @@ +import { ILauncherV2CompatibleVersion } from "@spt/models/spt/launcher/ILauncherV2CompatibleVersion"; + +export interface ILauncherV2VersionResponse { + response: ILauncherV2CompatibleVersion +} \ No newline at end of file diff --git a/project/src/routers/static/LauncherV2StaticRouter.ts b/project/src/routers/static/LauncherV2StaticRouter.ts new file mode 100644 index 00000000..c14c8af6 --- /dev/null +++ b/project/src/routers/static/LauncherV2StaticRouter.ts @@ -0,0 +1,94 @@ +import { LauncherV2Callbacks } from "@spt/callbacks/Launcherv2Callbacks"; +import { ProfileCallbacks } from "@spt/callbacks/ProfileCallbacks"; +import { RouteAction, StaticRouter } from "@spt/di/Router"; +import { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData"; +import { IChangeRequestData } from "@spt/models/eft/launcher/IChangeRequestData"; +import { ILoginRequestData } from "@spt/models/eft/launcher/ILoginRequestData"; +import { IRegisterData } from "@spt/models/eft/launcher/IRegisterData"; +import { ILauncherV2LoginResponse } from "@spt/models/spt/launcher/ILauncherV2LoginResponse"; +import { ILauncherV2ModsResponse } from "@spt/models/spt/launcher/ILauncherV2ModsResponse"; +import { ILauncherV2PasswordChangeResponse } from "@spt/models/spt/launcher/ILauncherV2PasswordChangeResponse"; +import { ILauncherV2PingResponse } from "@spt/models/spt/launcher/ILauncherV2PingResponse"; +import { ILauncherV2ProfilesResponse } from "@spt/models/spt/launcher/ILauncherV2ProfilesResponse"; +import { ILauncherV2RegisterResponse } from "@spt/models/spt/launcher/ILauncherV2RegisterResponse"; +import { ILauncherV2RemoveResponse } from "@spt/models/spt/launcher/ILauncherV2RemoveResponse"; +import { ILauncherV2TypesResponse } from "@spt/models/spt/launcher/ILauncherV2TypesResponse"; +import { ILauncherV2VersionResponse } from "@spt/models/spt/launcher/ILauncherV2VersionResponse"; +import { inject, injectable } from "tsyringe"; + +@injectable() +export class LauncherV2StaticRouter extends StaticRouter { + constructor( + @inject("LauncherV2Callbacks") protected launcherV2Callbacks: LauncherV2Callbacks, + @inject("ProfileCallbacks") protected profileCallbacks: ProfileCallbacks + ) { + super([ + new RouteAction( + "/launcher/v2/ping", + async (url: string, info: IEmptyRequestData, sessionID: string, output: string): Promise => { + return this.launcherV2Callbacks.ping(); + }, + ), + new RouteAction( + "/launcher/v2/types", + async (url: string, info: IEmptyRequestData, sessionID: string, output: string): Promise => { + return this.launcherV2Callbacks.types(); + }, + ), + new RouteAction( + "/launcher/v2/Login", + async (url: string, info: ILoginRequestData, sessionID: string, output: string): Promise => { + return this.launcherV2Callbacks.login(info); + }, + ), + new RouteAction( + "/launcher/v2/Register", + async (url: string, info: IRegisterData, sessionID: string, output: string): Promise => { + return this.launcherV2Callbacks.register(info); + }, + ), + new RouteAction( + "/launcher/v2/passwordChange", + async (url: string, info: IChangeRequestData, sessionID: string, output: string): Promise => { + return this.launcherV2Callbacks.passwordChange(info); + }, + ), + new RouteAction( + "/launcher/v2/Remove", + async (url: string, info: ILoginRequestData, sessionID: string, output: string): Promise => { + return this.launcherV2Callbacks.remove(info); + }, + ), + new RouteAction( + "/launcher/v2/version", + async (url: string, info: IEmptyRequestData, sessionID: string, output: string): Promise => { + return this.launcherV2Callbacks.compatibleVersion(); + }, + ), + new RouteAction( + "/launcher/v2/mods", + async (url: string, info: IEmptyRequestData, sessionID: string, output: string): Promise => { + return this.launcherV2Callbacks.mods(); + }, + ), + new RouteAction( + "/launcher/v2/profiles", + async (url: string, info: IEmptyRequestData, sessionID: string, output: string): Promise => { + return this.launcherV2Callbacks.profiles(); + }, + ), + new RouteAction( + "/launcher/v2/profile", + async (url: string, info: IEmptyRequestData, sessionID: string, output: string): Promise => { + return this.launcherV2Callbacks.profile(); + }, + ), + new RouteAction( + "/launcher/v2/profileMods", + async (url: string, info: IEmptyRequestData, sessionID: string, output: string): Promise => { + return this.launcherV2Callbacks.profileMods(); + }, + ), + ]); + } +}