Fix multiple server instances overwriting profiles with old data (!291)

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/291
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-04-16 07:15:49 +00:00 committed by chomp
parent ffbeefba6f
commit 521cf51f0e
2 changed files with 17 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import { LocalisationService } from "@spt-aki/services/LocalisationService";
export class HttpServer export class HttpServer
{ {
protected httpConfig: IHttpConfig; protected httpConfig: IHttpConfig;
protected started: boolean;
constructor( constructor(
@inject("WinstonLogger") protected logger: ILogger, @inject("WinstonLogger") protected logger: ILogger,
@ -37,6 +38,8 @@ export class HttpServer
*/ */
public load(): void public load(): void
{ {
this.started = false;
/* create server */ /* create server */
const httpServer: Server = http.createServer(); const httpServer: Server = http.createServer();
@ -48,6 +51,7 @@ export class HttpServer
/* Config server to listen on a port */ /* Config server to listen on a port */
httpServer.listen(this.httpConfig.port, this.httpConfig.ip, () => httpServer.listen(this.httpConfig.port, this.httpConfig.ip, () =>
{ {
this.started = true;
this.logger.success( this.logger.success(
this.localisationService.getText("started_webserver_success", this.httpServerHelper.getBackendUrl()), this.localisationService.getText("started_webserver_success", this.httpServerHelper.getBackendUrl()),
); );
@ -123,4 +127,9 @@ export class HttpServer
return found; return found;
} }
public isStarted(): boolean
{
return this.started;
}
} }

View File

@ -7,6 +7,7 @@ import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
import { ICoreConfig } from "@spt-aki/models/spt/config/ICoreConfig"; import { ICoreConfig } from "@spt-aki/models/spt/config/ICoreConfig";
import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
import { ConfigServer } from "@spt-aki/servers/ConfigServer"; import { ConfigServer } from "@spt-aki/servers/ConfigServer";
import { HttpServer } from "@spt-aki/servers/HttpServer";
import { LocalisationService } from "@spt-aki/services/LocalisationService"; import { LocalisationService } from "@spt-aki/services/LocalisationService";
import { EncodingUtil } from "@spt-aki/utils/EncodingUtil"; import { EncodingUtil } from "@spt-aki/utils/EncodingUtil";
import { TimeUtil } from "@spt-aki/utils/TimeUtil"; import { TimeUtil } from "@spt-aki/utils/TimeUtil";
@ -23,6 +24,7 @@ export class App
@inject("LocalisationService") protected localisationService: LocalisationService, @inject("LocalisationService") protected localisationService: LocalisationService,
@inject("ConfigServer") protected configServer: ConfigServer, @inject("ConfigServer") protected configServer: ConfigServer,
@inject("EncodingUtil") protected encodingUtil: EncodingUtil, @inject("EncodingUtil") protected encodingUtil: EncodingUtil,
@inject("HttpServer") protected httpServer: HttpServer,
@injectAll("OnLoad") protected onLoadComponents: OnLoad[], @injectAll("OnLoad") protected onLoadComponents: OnLoad[],
@injectAll("OnUpdate") protected onUpdateComponents: OnUpdate[], @injectAll("OnUpdate") protected onUpdateComponents: OnUpdate[],
) )
@ -64,6 +66,12 @@ export class App
protected async update(onUpdateComponents: OnUpdate[]): Promise<void> protected async update(onUpdateComponents: OnUpdate[]): Promise<void>
{ {
// If the server has failed to start, skip any update calls
if (!this.httpServer.isStarted())
{
return;
}
for (const updateable of onUpdateComponents) for (const updateable of onUpdateComponents)
{ {
let success = false; let success = false;