mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 06:10:44 -05:00
Add safeguard to prevent a call to save the profile from happening if a save is already underway
This commit is contained in:
parent
554159e084
commit
4595c29c15
@ -15,6 +15,7 @@ import { inject, injectAll, injectable } from "tsyringe";
|
|||||||
export class SaveServer {
|
export class SaveServer {
|
||||||
protected profileFilepath = "user/profiles/";
|
protected profileFilepath = "user/profiles/";
|
||||||
protected profiles: Map<string, ISptProfile> = new Map();
|
protected profiles: Map<string, ISptProfile> = new Map();
|
||||||
|
protected profilesBeingSaved: Set<string> = new Set();
|
||||||
protected onBeforeSaveCallbacks: Map<string, (profile: ISptProfile) => Promise<ISptProfile>> = new Map();
|
protected onBeforeSaveCallbacks: Map<string, (profile: ISptProfile) => Promise<ISptProfile>> = new Map();
|
||||||
protected saveSHA1: { [key: string]: string } = {};
|
protected saveSHA1: { [key: string]: string } = {};
|
||||||
|
|
||||||
@ -184,6 +185,12 @@ export class SaveServer {
|
|||||||
throw new Error(`Profile ${sessionID} does not exist! Unable to save this profile!`);
|
throw new Error(`Profile ${sessionID} does not exist! Unable to save this profile!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.profilesBeingSaved.has(sessionID)) {
|
||||||
|
throw new Error(`Profile ${sessionID} is already being saved!`);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.profilesBeingSaved.add(sessionID);
|
||||||
|
|
||||||
const filePath = `${this.profileFilepath}${sessionID}.json`;
|
const filePath = `${this.profileFilepath}${sessionID}.json`;
|
||||||
|
|
||||||
// Run pre-save callbacks before we save into json
|
// Run pre-save callbacks before we save into json
|
||||||
@ -201,12 +208,16 @@ export class SaveServer {
|
|||||||
this.profiles.get(sessionID),
|
this.profiles.get(sessionID),
|
||||||
!this.configServer.getConfig<ICoreConfig>(ConfigTypes.CORE).features.compressProfile,
|
!this.configServer.getConfig<ICoreConfig>(ConfigTypes.CORE).features.compressProfile,
|
||||||
);
|
);
|
||||||
|
|
||||||
const sha1 = await this.hashUtil.generateSha1ForDataAsync(jsonProfile);
|
const sha1 = await this.hashUtil.generateSha1ForDataAsync(jsonProfile);
|
||||||
|
|
||||||
if (typeof this.saveSHA1[sessionID] !== "string" || this.saveSHA1[sessionID] !== sha1) {
|
if (typeof this.saveSHA1[sessionID] !== "string" || this.saveSHA1[sessionID] !== sha1) {
|
||||||
this.saveSHA1[sessionID] = sha1;
|
this.saveSHA1[sessionID] = sha1;
|
||||||
// save profile to disk
|
// save profile to disk
|
||||||
await this.fileSystem.write(filePath, jsonProfile);
|
await this.fileSystem.write(filePath, jsonProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.profilesBeingSaved.delete(sessionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user