0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 09:50:43 -05:00
server/project/src/callbacks/SaveCallbacks.ts

37 lines
1.1 KiB
TypeScript
Raw Normal View History

import { OnLoad } from "@spt/di/OnLoad";
import { OnUpdate } from "@spt/di/OnUpdate";
import { ConfigTypes } from "@spt/models/enums/ConfigTypes";
import { ICoreConfig } from "@spt/models/spt/config/ICoreConfig";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { SaveServer } from "@spt/servers/SaveServer";
import { inject, injectable } from "tsyringe";
2023-03-03 15:23:46 +00:00
@injectable()
export class SaveCallbacks implements OnLoad, OnUpdate {
protected coreConfig: ICoreConfig;
2023-03-03 15:23:46 +00:00
constructor(
@inject("SaveServer") protected saveServer: SaveServer,
2023-11-10 15:19:56 -05:00
@inject("ConfigServer") protected configServer: ConfigServer,
) {
this.coreConfig = this.configServer.getConfig(ConfigTypes.CORE);
2023-03-03 15:23:46 +00:00
}
2023-11-10 15:19:56 -05:00
public async onLoad(): Promise<void> {
2023-03-03 15:23:46 +00:00
this.saveServer.load();
}
public getRoute(): string {
return "spt-save";
2023-03-03 15:23:46 +00:00
}
public async onUpdate(secondsSinceLastRun: number): Promise<boolean> {
2023-03-03 15:23:46 +00:00
// run every 15 seconds
if (secondsSinceLastRun > this.coreConfig.profileSaveIntervalSeconds) {
2023-03-03 15:23:46 +00:00
this.saveServer.save();
return true;
}
return false;
}
2023-11-10 15:19:56 -05:00
}