Server/project/src/callbacks/SaveCallbacks.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-03-03 15:23:46 +00:00
import { inject, injectable } from "tsyringe";
import { OnLoad } from "@spt-aki/di/OnLoad";
import { OnUpdate } from "@spt-aki/di/OnUpdate";
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
import { ICoreConfig } from "@spt-aki/models/spt/config/ICoreConfig";
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
import { SaveServer } from "@spt-aki/servers/SaveServer";
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,
2023-03-03 15:23:46 +00:00
)
{
this.coreConfig = this.configServer.getConfig(ConfigTypes.CORE);
2023-03-03 15:23:46 +00:00
}
2023-11-10 15:19:56 -05:00
2023-03-03 15:23:46 +00:00
public async onLoad(): Promise<void>
{
this.saveServer.load();
}
2023-11-10 15:19:56 -05:00
public getRoute(): string
2023-03-03 15:23:46 +00:00
{
return "aki-save";
}
public async onUpdate(secondsSinceLastRun: number): Promise<boolean>
{
// 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
}