diff --git a/CSync/Lib/SyncedConfig.cs b/CSync/Lib/SyncedConfig.cs index 76c8cea..b8eac1c 100644 --- a/CSync/Lib/SyncedConfig.cs +++ b/CSync/Lib/SyncedConfig.cs @@ -15,6 +15,18 @@ public class SyncedConfig(string guid) : SyncedInstance, ISynchronizable w static void LogErr(string str) => Plugin.Logger.LogError(str); static void LogDebug(string str) => Plugin.Logger.LogDebug(str); + /// + /// Invoked on the host when a client requests to sync. + /// + [field:NonSerialized] public event EventHandler SyncRequested; + internal void OnSyncRequested() => SyncRequested?.Invoke(this, EventArgs.Empty); + + /// + /// Invoked on the client when they receive the host config. + /// + [field:NonSerialized] public event EventHandler SyncReceived; + internal void OnSyncReceived() => SyncReceived?.Invoke(this, EventArgs.Empty); + /// /// The mod name or abbreviation. After being given to the constructor, it cannot be changed. /// @@ -22,6 +34,11 @@ public class SyncedConfig(string guid) : SyncedInstance, ISynchronizable w internal SyncedEntry SYNC_TO_CLIENTS { get; private set; } = null; + /// + /// Allow the host to control whether clients can use their own config. + /// This MUST be called after binding the entry parameter. + /// + /// The entry for the host to use in your config file. protected void EnableHostSyncControl(SyncedEntry hostSyncControlOption) { SYNC_TO_CLIENTS = hostSyncControlOption; @@ -51,8 +68,8 @@ void RequestSync() { } internal void OnRequestSync(ulong clientId, FastBufferReader _) { - // Only run if we are host/server. if (!IsHost) return; + OnSyncRequested(); if (SYNC_TO_CLIENTS != null && SYNC_TO_CLIENTS == false) { using FastBufferWriter s = new(IntSize, Allocator.Temp); @@ -80,6 +97,8 @@ internal void OnRequestSync(ulong clientId, FastBufferReader _) { } internal void OnReceiveSync(ulong _, FastBufferReader reader) { + OnSyncReceived(); + if (!reader.TryBeginRead(IntSize)) { LogErr($"{GUID} - Config sync error: Could not begin reading buffer."); return;