Closed Dracbjorn closed 1 year ago
I think this is fine as a 1.4.X release because if the client has the code, but the server is outdated, it will simply never request a sync. So nothing should break.
So, I couldn't get the Jotuun version to work. Not sure why, so I attempted a different method and it works. However, I'm sure the Jotunn method is probably far simpler. I couldn't figure out exactly how to use it and where to use it. This is the alternative method I implemented:
private void SetupWatcher()
{
FileSystemWatcher watcher = new FileSystemWatcher(BepInEx.Paths.ConfigPath, ConfigFileName);
watcher.Changed += ReadConfigValues;
watcher.Created += ReadConfigValues;
watcher.Renamed += ReadConfigValues;
watcher.IncludeSubdirectories = true;
watcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
watcher.EnableRaisingEvents = true;
}
private void ReadConfigValues(object sender, FileSystemEventArgs e)
{
if (!File.Exists(ConfigFileFullPath)) return;
try
{
Jotunn.Logger.LogInfo("Read updated config values");
Config.Reload();
}
catch
{
Jotunn.Logger.LogError($"There was an issue loading your {ConfigFileName}");
Jotunn.Logger.LogError("Please check your config entries for spelling and format!");
}
}
Then I just call SetupWatcher();
at the end of the Awake()
method.
Description
When a config is changed during run-time, it should automatically update on the server without requiring a restart to reload the config.
Is the feature related to a problem?
No.
Solutions
Use the Jotunn SynchronizationManager:
https://valheim-modding.github.io/Jotunn/tutorials/config.html#config-synced-event