From ba171523589f399f7de8112ad545b9e7a3473bf3 Mon Sep 17 00:00:00 2001 From: Archangel Date: Mon, 29 Jul 2024 13:00:43 +0200 Subject: [PATCH 1/2] Refactor: Set dedicated client level on raid start request --- src/controllers/FikaRaidController.ts | 12 +++ src/di/Container.ts | 3 - src/overrides/controllers/BotController.ts | 95 ---------------------- 3 files changed, 12 insertions(+), 98 deletions(-) delete mode 100644 src/overrides/controllers/BotController.ts diff --git a/src/controllers/FikaRaidController.ts b/src/controllers/FikaRaidController.ts index 3d2ca9a6..c2818a49 100644 --- a/src/controllers/FikaRaidController.ts +++ b/src/controllers/FikaRaidController.ts @@ -19,6 +19,8 @@ import { IStatusDedicatedRequest } from "../models/fika/routes/raid/dedicated/IS import { IStatusDedicatedResponse } from "../models/fika/routes/raid/dedicated/IStatusDedicatedResponse"; import { IGetStatusDedicatedResponse } from "../models/fika/routes/raid/dedicated/IGetStatusDedicatedResponse"; import { FikaDedicatedRaidWebSocket } from "../websockets/FikaDedicatedRaidWebSocket"; +import { IPmcData } from "@spt/models/eft/common/IPmcData"; +import { ProfileHelper } from "@spt/helpers/ProfileHelper"; @injectable() export class FikaRaidController { @@ -26,6 +28,7 @@ export class FikaRaidController { @inject("FikaMatchService") protected fikaMatchService: FikaMatchService, @inject("FikaDedicatedRaidService") protected fikaDedicatedRaidService: FikaDedicatedRaidService, @inject("FikaDedicatedRaidWebSocket") protected fikaDedicatedRaidWebSocket: FikaDedicatedRaidWebSocket, + @inject("ProfileHelper") protected profileHelper: ProfileHelper, @inject("WinstonLogger") protected logger: ILogger, ) { // empty @@ -148,6 +151,15 @@ export class FikaRaidController { }; } + const pmcDedicatedClientProfile: IPmcData = this.profileHelper.getPmcProfile(dedicatedClient); + const requesterProfile: IPmcData = this.profileHelper.getPmcProfile(sessionID); + + this.logger.debug(`Dedicated: ${pmcDedicatedClientProfile.Info.Nickname} ${pmcDedicatedClientProfile.Info.Level} - Requester: ${requesterProfile.Info.Nickname} ${requesterProfile.Info.Level}`) + + //Set level of the dedicated profile to the person that has requested the raid to be started. + pmcDedicatedClientProfile.Info.Level = requesterProfile.Info.Level; + pmcDedicatedClientProfile.Info.Experience = requesterProfile.Info.Experience; + this.fikaDedicatedRaidService.requestedSessions[dedicatedClient] = sessionID; dedicatedClientWs.send( diff --git a/src/di/Container.ts b/src/di/Container.ts index 3f86d175..e2431bb8 100644 --- a/src/di/Container.ts +++ b/src/di/Container.ts @@ -49,7 +49,6 @@ import { IWebSocketConnectionHandler } from "@spt/servers/ws/IWebSocketConnectio import { Fika } from "../Fika"; import { FikaServerTools } from "../utils/FikaServerTools"; import { FikaDedicatedProfileService } from "../services/dedicated/FikaDedicatedProfileService"; -import { BotControllerOverride } from "../overrides/controllers/BotController"; export class Container { @@ -85,7 +84,6 @@ export class Container { container.registerType("Overrides", "LocalesOverride"); container.registerType("Overrides", "AchievementControllerOverride"); container.registerType("Overrides", "DatabaseServiceOverride"); - container.registerType("Overrides", "BotControllerOverride"); container.registerType("StaticRoutes", "FikaClientStaticRouter"); container.registerType("StaticRoutes", "FikaLocationStaticRouter"); @@ -110,7 +108,6 @@ export class Container { container.register("HttpRouterOverride", HttpRouterOverride, { lifecycle: Lifecycle.Singleton }); container.register("LauncherBackgroundOverride", LauncherBackgroundOverride, { lifecycle: Lifecycle.Singleton }); container.register("LocalesOverride", LocalesOverride, { lifecycle: Lifecycle.Singleton }); - container.register("BotControllerOverride", BotControllerOverride, { lifecycle: Lifecycle.Singleton }); container.register("Overrider", Overrider, { lifecycle: Lifecycle.Singleton }); container.register("AchievementControllerOverride", AchievementControllerOverride, { lifecycle: Lifecycle.Singleton }); container.register("DatabaseServiceOverride", DatabaseServiceOverride, { lifecycle: Lifecycle.Singleton }); diff --git a/src/overrides/controllers/BotController.ts b/src/overrides/controllers/BotController.ts deleted file mode 100644 index 235984b4..00000000 --- a/src/overrides/controllers/BotController.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { injectable, inject, DependencyContainer } from "tsyringe"; -import { FikaDialogueController } from "../../controllers/FikaDialogueController"; -import { Override } from "../../di/Override"; -import { IBotBase } from "@spt/models/eft/common/tables/IBotBase"; -import { BotController } from "@spt/controllers/BotController"; -import { ProfileHelper } from "@spt/helpers/ProfileHelper"; -import { IGenerateBotsRequestData } from "@spt/models/eft/bot/IGenerateBotsRequestData"; -import { FikaDedicatedRaidService } from "../../services/dedicated/FikaDedicatedRaidService"; -import { ILogger } from "@spt/models/spt/utils/ILogger"; -import { IPmcData } from "@spt/models/eft/common/IPmcData"; -import { FikaMatchService } from "../../services/FikaMatchService"; -import { SaveServer } from "@spt/servers/SaveServer"; - -@injectable() -export class BotControllerOverride extends Override { - constructor( - @inject("ProfileHelper") protected profileHelper: ProfileHelper, - @inject("BotController") protected botController: BotController, - @inject("FikaDedicatedRaidService") protected fikaDedicatedRaidService: FikaDedicatedRaidService, - @inject("WinstonLogger") protected logger: ILogger, - @inject("FikaMatchService") protected fikaMatchService: FikaMatchService, - @inject("SaveServer") protected saveServer: SaveServer, - ) { - super(); - } - - public execute(container: DependencyContainer): void { - container.afterResolution( - "BotController", - (_t, result: BotController) => { - // Override the bot generate function to determine which profile to use whether we're - // generating bots for a dedicated client or a normal host. - result.generate = (sessionId: string, info: IGenerateBotsRequestData): Promise => { - let pmcProfile: IPmcData; - const dedicatedSessions = this.fikaDedicatedRaidService.requestedSessions; - const isDedicated = dedicatedSessions.hasOwnProperty(sessionId); - - if (isDedicated) { - // Use the dedicated client requester's PMC profile - const dedicatedRequesterSessionId = dedicatedSessions[sessionId]; - pmcProfile = this.profileHelper.getPmcProfile(dedicatedRequesterSessionId); - } else { - // Use the host PMC profile - pmcProfile = this.profileHelper.getPmcProfile(sessionId); - } - - // Get the matchId and then match - const matchId = this.fikaMatchService.getMatchIdByProfile(sessionId); - const match = this.fikaMatchService.getMatch(matchId); - - if(!match) - { - this.logger.warning("FIKA Match is null! Running default SPT bot generation"); - - return this.botController.generate(sessionId, info); - } - - const players = match.players.keys(); - - // Loop through all the players and get their profiles - let level = 1; - for (const playerId of players) { - const player = this.saveServer.getProfile(playerId); - if (player.info.password === "fika-dedicated") - continue; - - if (player.characters.pmc.Info.Level > level) - level = player.characters.pmc.Info.Level; - } - - const originalLevel = pmcProfile.Info.Level; - pmcProfile.Info.Level = level; - - // If there's more than 1 condition, this is the first time client has requested bots - // Client sends every bot type it will need in raid - // Use this opportunity to create and cache bots for later retrieval - const isFirstGen = info.conditions.length > 1; - let botGenerationResult: Promise; - if (isFirstGen) { - // Temporary cast to remove the error caused by protected method. - botGenerationResult = (this.botController as any).generateBotsFirstTime(info, pmcProfile, sessionId); - } - // Temporary cast to remove the error caused by protected method. - botGenerationResult = (this.botController as any).returnSingleBotFromCache(sessionId, info); - - // Set back the original level - //pmcProfile.Info.Level = originalLevel; - pmcProfile.Info.Level = originalLevel; - return botGenerationResult; - }; - }, - { frequency: "Always" }, - ); - } -} From b43170338b12bf7742f00db28099164164d7d7cd Mon Sep 17 00:00:00 2001 From: Archangel Date: Mon, 29 Jul 2024 13:25:38 +0200 Subject: [PATCH 2/2] Update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 14d73a58..37816495 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "server", - "version": "2.2.4", + "version": "2.2.5", "sptVersion": "~3.9", "main": "src/mod.js", "scripts": {