Files
SPT-Server-Build/Core/Callbacks/SaveCallbacks.cs
T

42 lines
1.0 KiB
C#

using Core.Annotations;
using Core.DI;
using Core.Models.Spt.Config;
using Core.Servers;
using Core.Services;
namespace Core.Callbacks;
[Injectable(InjectableTypeOverride = typeof(OnLoad), TypePriority = OnLoadOrder.SaveCallbacks)]
[Injectable(InjectableTypeOverride = typeof(OnUpdate), TypePriority = OnUpdateOrder.SaveCallbacks)]
public class SaveCallbacks(
SaveServer _saveServer,
ConfigServer _configServer,
BackupService _backupService
)
: OnLoad, OnUpdate
{
private readonly CoreConfig _coreConfig = _configServer.GetConfig<CoreConfig>();
public async Task OnLoad()
{
await _backupService.InitAsync();
_saveServer.Load();
}
public Task<bool> OnUpdate(long SecondsSinceLastRun)
{
if (SecondsSinceLastRun > _coreConfig.ProfileSaveIntervalInSeconds)
{
_saveServer.Save();
return Task.FromResult(true);
}
return Task.FromResult(false);
}
public string GetRoute()
{
return "spt-save";
}
}