diff --git a/Core/Callbacks/SaveCallbacks.cs b/Core/Callbacks/SaveCallbacks.cs index 176ed83b..28d881b0 100644 --- a/Core/Callbacks/SaveCallbacks.cs +++ b/Core/Callbacks/SaveCallbacks.cs @@ -1,28 +1,51 @@ -using Core.DI; +using Core.Annotations; +using Core.DI; +using Core.Models.Enums; using Core.Models.Spt.Config; +using Core.Servers; +using Core.Services; namespace Core.Callbacks; +[Injectable] public class SaveCallbacks : OnLoad, OnUpdate { - private CoreConfig _coreConfig; + protected SaveServer _saveServer; + protected CoreConfig _coreConfig; + protected BackupService _backupService; - public SaveCallbacks() + public SaveCallbacks( + SaveServer saveServer, + ConfigServer configServer, + BackupService backupService + ) { + _saveServer = saveServer; + _coreConfig = configServer.GetConfig(ConfigTypes.CORE); + _backupService = backupService; } - public async Task OnLoad() + public Task OnLoad() { - throw new NotImplementedException(); + _backupService.InitAsync(); + _saveServer.Load(); + + return Task.CompletedTask; } public async Task OnUpdate(long SecondsSinceLastRun) { - throw new NotImplementedException(); + if (SecondsSinceLastRun > _coreConfig.ProfileSaveIntervalInSeconds) + { + _saveServer.Save(); + return true; + } + + return false; } public string GetRoute() { - throw new NotImplementedException(); + return "spt-save"; } -} \ No newline at end of file +} diff --git a/Core/Controllers/LauncherController.cs b/Core/Controllers/LauncherController.cs index a3d874cf..2c44cc39 100644 --- a/Core/Controllers/LauncherController.cs +++ b/Core/Controllers/LauncherController.cs @@ -102,7 +102,7 @@ public class LauncherController return _saveServer.GetProfiles().TryGetValue(sessionId, out var profile) ? profile.ProfileInfo : null; } - public string Login(LoginRequestData info) + public string? Login(LoginRequestData info) { foreach (var sessionID in _saveServer.GetProfiles()) { var account = _saveServer.GetProfile(sessionID.Key).ProfileInfo; @@ -111,7 +111,7 @@ public class LauncherController } } - return ""; + return null; } public string Register(RegisterData info)