From a207e5778e236cbf5c906aacfa53a26366f35056 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 23 Mar 2023 14:48:10 +0000 Subject: [PATCH] Feature: Save profile changes on game exit --- project/src/callbacks/GameCallbacks.ts | 5 +++++ project/src/context/ApplicationContext.ts | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/project/src/callbacks/GameCallbacks.ts b/project/src/callbacks/GameCallbacks.ts index 839243b8..6df3c3c6 100644 --- a/project/src/callbacks/GameCallbacks.ts +++ b/project/src/callbacks/GameCallbacks.ts @@ -13,6 +13,7 @@ import { IServerDetails } from "../models/eft/game/IServerDetails"; import { IVersionValidateRequestData } from "../models/eft/game/IVersionValidateRequestData"; import { IGetBodyResponseData } from "../models/eft/httpResponse/IGetBodyResponseData"; import { INullResponseData } from "../models/eft/httpResponse/INullResponseData"; +import { SaveServer } from "../servers/SaveServer"; import { HttpResponseUtil } from "../utils/HttpResponseUtil"; import { Watermark } from "../utils/Watermark"; @@ -22,6 +23,7 @@ class GameCallbacks constructor( @inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil, @inject("Watermark") protected watermark: Watermark, + @inject("SaveServer") protected saveServer: SaveServer, @inject("GameController") protected gameController: GameController ) {} @@ -53,11 +55,13 @@ class GameCallbacks /** * Handle client/game/logout + * Save profiles on game close * @returns IGameLogoutResponseData */ // eslint-disable-next-line @typescript-eslint/no-unused-vars public gameLogout(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData { + this.saveServer.save(); return this.httpResponse.getBody({ status: "ok" }); @@ -123,3 +127,4 @@ class GameCallbacks } export { GameCallbacks }; + diff --git a/project/src/context/ApplicationContext.ts b/project/src/context/ApplicationContext.ts index bf3948e4..951b2ed2 100644 --- a/project/src/context/ApplicationContext.ts +++ b/project/src/context/ApplicationContext.ts @@ -26,6 +26,7 @@ export class ApplicationContext { return this.variables.get(type)?.getTail()?.getValue(); } + return undefined; } @@ -35,6 +36,7 @@ export class ApplicationContext { return this.variables.get(type).toList(); } + return undefined; } @@ -45,8 +47,10 @@ export class ApplicationContext list = this.variables.get(type); else list = new LinkedList(); + if (list.getSize() >= ApplicationContext.holderMaxSize) list.removeFirst(); + list.add(new ContextVariable(value, type)); this.variables.set(type, list); }