Merge pull request #38 from CWXDEV/main

Add temp logging, Move Http to be last in the order as its currently blocking, a few exceptions blocked out onLoad methods
This commit is contained in:
clodanSPT
2025-01-12 11:04:54 +00:00
committed by GitHub
13 changed files with 162 additions and 31 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ public class ModCallbacks : OnLoad
// if (ProgramStatics.MODS) {
// await this.postSptModLoader.load();
// } TODO: needs to be implemented
throw new NotImplementedException();
return;
}
public string GetRoute()
+1 -3
View File
@@ -26,12 +26,10 @@ public class SaveCallbacks : OnLoad, OnUpdate
_backupService = backupService;
}
public Task OnLoad()
public async Task OnLoad()
{
_backupService.InitAsync();
_saveServer.Load();
return Task.CompletedTask;
}
public async Task<bool> OnUpdate(long SecondsSinceLastRun)
+1 -1
View File
@@ -187,6 +187,6 @@ public class GameController
public void Load()
{
throw new NotImplementedException();
return; // TODO: actually implement
}
}
+1 -1
View File
@@ -10,6 +10,6 @@ public class PresetController
/// </summary>
public void Initialize()
{
throw new NotImplementedException();
return; // TODO: actually implement
}
}
+1 -1
View File
@@ -14,7 +14,7 @@ public class TraderController
/// </summary>
public void Load()
{
throw new NotImplementedException();
return; // TODO: actually implement
}
/// <summary>
+8 -8
View File
@@ -5,12 +5,12 @@ public static class OnLoadOrder
public const int Database = 0;
public const int PostDBModLoader = 1;
public const int HandbookCallbacks = 2;
public const int HttpCallbacks = 3;
public const int PresetCallbacks = 4;
public const int SaveCallbacks = 5;
public const int TraderCallbacks = 6;
public const int RagfairPriceService = 7;
public const int RagfairCallbacks = 8;
public const int ModCallbacks = 9;
public const int GameCallbacks = 10;
public const int PresetCallbacks = 3;
public const int SaveCallbacks = 4;
public const int TraderCallbacks = 5;
public const int RagfairPriceService = 6;
public const int RagfairCallbacks = 7;
public const int ModCallbacks = 8;
public const int GameCallbacks = 9;
public const int HttpCallbacks = 10;
}
@@ -0,0 +1,47 @@
using Core.Annotations;
using Core.DI;
using Core.Models.Eft.Profile;
namespace Core.Routers.SaveLoad;
[Injectable(InjectableTypeOverride = typeof(SaveLoadRouter))]
public class HealthSaveLoadRouter : SaveLoadRouter
{
protected override List<HandledRoute> GetHandledRoutes()
{
return new List<HandledRoute>() { new HandledRoute("spt-health", false) };
}
public override SptProfile HandleLoad(SptProfile profile)
{
if (profile?.VitalityData == null)
profile.VitalityData = new() { Health = null, Effects = null };
profile.VitalityData.Health = new()
{
Hydration = 0,
Energy = 0,
Temperature = 0,
Head = 0,
Chest = 0,
Stomach = 0,
LeftArm = 0,
RightArm = 0,
LeftLeg = 0,
RightLeg = 0
};
profile.VitalityData.Effects = new()
{
Head = new(),
Chest = new(),
Stomach = new(),
LeftArm = new(),
RightArm = new(),
LeftLeg = new(),
RightLeg = new()
};
return profile;
}
}
@@ -0,0 +1,22 @@
using Core.Annotations;
using Core.DI;
using Core.Models.Eft.Profile;
namespace Core.Routers.SaveLoad;
[Injectable(InjectableTypeOverride = typeof(SaveLoadRouter))]
public class InraidSaveLoadRouter : SaveLoadRouter
{
protected override List<HandledRoute> GetHandledRoutes()
{
return new List<HandledRoute>() { new HandledRoute("spt-inraid", false) };
}
public override SptProfile HandleLoad(SptProfile profile)
{
if (profile.InraidData == null)
profile.InraidData = new Inraid { Location = "none", Character = "none" };
return profile;
}
}
@@ -0,0 +1,22 @@
using Core.Annotations;
using Core.DI;
using Core.Models.Eft.Profile;
namespace Core.Routers.SaveLoad;
[Injectable(InjectableTypeOverride = typeof(SaveLoadRouter))]
public class InsuranceSaveLoadRouter : SaveLoadRouter
{
protected override List<HandledRoute> GetHandledRoutes()
{
return new List<HandledRoute>() { new HandledRoute("spt-insurance", false) };
}
public override SptProfile HandleLoad(SptProfile profile)
{
if (profile.InsuranceList == null)
profile.InsuranceList = new List<Insurance>();
return profile;
}
}
@@ -0,0 +1,22 @@
using Core.Annotations;
using Core.DI;
using Core.Models.Eft.Profile;
namespace Core.Routers.SaveLoad;
[Injectable(InjectableTypeOverride = typeof(SaveLoadRouter))]
public class ProfileSaveLoadRouter : SaveLoadRouter
{
protected override List<HandledRoute> GetHandledRoutes()
{
return new List<HandledRoute>() { new HandledRoute("spt-profile", false) };
}
public override SptProfile HandleLoad(SptProfile profile)
{
if (profile.CharacterData == null)
profile.CharacterData = new Characters { PmcData = new(), ScavData = new() };
return profile;
}
}
+18 -12
View File
@@ -85,9 +85,11 @@ public class SaveServer
// load profiles
var stopwatch = Stopwatch.StartNew();
foreach (var file in files) {
foreach (var file in files)
{
LoadProfile(_vfs.StripExtension(file));
}
stopwatch.Stop();
_logger.Debug($"{files.Count()} Profiles took: {stopwatch.ElapsedMilliseconds}ms to load.");
}
@@ -99,7 +101,8 @@ public class SaveServer
{
// Save every profile
var totalTime = 0L;
foreach ( var sessionID in profiles) {
foreach (var sessionID in profiles)
{
totalTime += SaveProfile(sessionID.Key);
}
@@ -139,7 +142,7 @@ public class SaveServer
* @returns Dictionary of ISptProfile
*/
public Dictionary<string, SptProfile> GetProfiles() => profiles;
/**
* Delete a profile by id
* @param sessionID Id of profile to remove
@@ -171,7 +174,7 @@ public class SaveServer
new SptProfile()
{
ProfileInfo = profileInfo,
CharacterData = new Characters() { PmcData = new PmcData(), ScavData = new PmcData() }
CharacterData = new Characters() { PmcData = new(), ScavData = new() }
});
}
@@ -191,8 +194,8 @@ public class SaveServer
*/
public void LoadProfile(string sessionID)
{
var filename = $"{sessionID}.json";
var filePath = $"{profileFilepath}{filename}";
var filename = $"{sessionID}.json";
var filePath = $"{profileFilepath}{filename}";
if (_vfs.FileExists(filePath))
{
// File found, store in profiles[]
@@ -200,7 +203,8 @@ public class SaveServer
}
// Run callbacks
foreach (var callback in _saveLoadRouters) {
foreach (var callback in _saveLoadRouters) // HealthSaveLoadRouter, InraidSaveLoadRouter, InsuranceSaveLoadRouter, ProfileSaveLoadRouter. THESE SHOULD EXIST IN HERE
{
profiles[sessionID] = callback.HandleLoad(GetProfile(sessionID));
}
}
@@ -216,9 +220,9 @@ public class SaveServer
var filePath = $"{profileFilepath}{sessionID}.json";
// Run pre-save callbacks before we save into json
foreach ( var callback in onBeforeSaveCallbacks)
foreach (var callback in onBeforeSaveCallbacks)
{
var previous = profiles[sessionID];
var previous = profiles[sessionID];
try
{
profiles[sessionID] = onBeforeSaveCallbacks[callback.Key](profiles[sessionID]);
@@ -231,9 +235,10 @@ public class SaveServer
}
var start = Stopwatch.StartNew();
var jsonProfile = _jsonUtil.Serialize(profiles[sessionID], !_configServer.GetConfig<CoreConfig>(ConfigTypes.CORE).Features.CompressProfile);
var fmd5 = _hashUtil.GenerateMd5ForData(jsonProfile);
if (!saveMd5.TryGetValue(sessionID, out var currentMd5) || currentMd5 != fmd5) {
var jsonProfile = _jsonUtil.Serialize(profiles[sessionID], !_configServer.GetConfig<CoreConfig>(ConfigTypes.CORE).Features.CompressProfile);
var fmd5 = _hashUtil.GenerateMd5ForData(jsonProfile);
if (!saveMd5.TryGetValue(sessionID, out var currentMd5) || currentMd5 != fmd5)
{
saveMd5[sessionID] = fmd5;
// save profile to disk
_vfs.WriteFile(filePath, jsonProfile);
@@ -256,6 +261,7 @@ public class SaveServer
profiles.Remove(sessionID);
_vfs.DeleteFile(file);
}
return !_vfs.FileExists(file);
}
}
+17 -3
View File
@@ -79,9 +79,23 @@ public class App
_logger.Debug("Commit: ${ProgramStatics.COMMIT}");
}
*/
foreach (var onLoad in _onLoad) await onLoad.OnLoad();
foreach (var onLoad in _onLoad)
{
Console.WriteLine($"Start Onload: {onLoad.GetRoute()}");
await onLoad.OnLoad();
Console.WriteLine($"finish Onload: {onLoad.GetRoute()}");
}
var timer = new Timer(_ => { update(_onUpdate); }, null, TimeSpan.Zero, TimeSpan.FromMilliseconds(5000));
var timer = new Timer(_ =>
{
Console.WriteLine($"Start OnUpdate");
update(_onUpdate);
Console.WriteLine($"Finish OnUpdate");
},
null,
TimeSpan.Zero,
TimeSpan.FromMilliseconds(5000));
}
protected async Task update(IEnumerable<OnUpdate> onUpdateComponents)
@@ -124,4 +138,4 @@ public class App
_logger.Error(_localisationService.GetText("scheduled_event_failed_to_run", updateable.GetRoute()));
_logger.Error(err.ToString());
}
}
}
+1 -1
View File
@@ -110,7 +110,7 @@ public class Watermark {
var versionTag = /*ProgramStatics.DEBUG&*/ $"{sptVersion} - {_localisationService.GetText("bleeding_edge_build")}";
if (withEftVersion) {
var tarkovVersion = sptConfig.CompatibleTarkovVersion.Split(".").First();
var tarkovVersion = sptConfig.CompatibleTarkovVersion.Split(".").Last();
return $"{versionTag} ({tarkovVersion})";
}