Server/project/src/services/ProfileSnapshotService.ts
TheSparta 418d9f2a8f Import path alias on the whole project (!157)
- Ability to use @spt-aki path alias on the whole project.
- Swapped all imports from relative paths, for imports using the path alias.

Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/157
Co-authored-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com>
Co-committed-by: TheSparta <thesparta@noreply.dev.sp-tarkov.com>
2023-10-19 17:21:17 +00:00

64 lines
1.6 KiB
TypeScript

import { inject, injectable } from "tsyringe";
import { IAkiProfile } from "@spt-aki/models/eft/profile/IAkiProfile";
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
@injectable()
export class ProfileSnapshotService
{
protected storedProfileSnapshots: Record<string, IAkiProfile> = {};
constructor(
@inject("JsonUtil") protected jsonUtil: JsonUtil
)
{}
/**
* Store a profile into an in-memory object
* @param sessionID session id - acts as the key
* @param profile - profile to save
*/
public storeProfileSnapshot(sessionID: string, profile: IAkiProfile): void
{
this.storedProfileSnapshots[sessionID] = this.jsonUtil.clone(profile);
}
/**
* Retreve a stored profile
* @param sessionID key
* @returns A player profile object
*/
public getProfileSnapshot(sessionID: string): IAkiProfile
{
if (this.storedProfileSnapshots[sessionID])
{
return this.storedProfileSnapshots[sessionID];
}
return null;
}
/**
* Does a profile exists against the provided key
* @param sessionID key
* @returns true if exists
*/
public hasProfileSnapshot(sessionID: string): boolean
{
if (this.storedProfileSnapshots[sessionID])
{
return true;
}
return false;
}
/**
* Remove a stored profile by key
* @param sessionID key
*/
public clearProfileSnapshot(sessionID: string): void
{
delete this.storedProfileSnapshots[sessionID];
}
}