@@ -15,13 +15,30 @@ public class SyncedConfig<T>(string guid) : SyncedInstance<T>, ISynchronizable w
1515 static void LogErr ( string str ) => Plugin . Logger . LogError ( str ) ;
1616 static void LogDebug ( string str ) => Plugin . Logger . LogDebug ( str ) ;
1717
18+ /// <summary>
19+ /// Invoked on the host when a client requests to sync.
20+ /// </summary>
21+ [ field: NonSerialized ] public event EventHandler SyncRequested ;
22+ internal void OnSyncRequested ( ) => SyncRequested ? . Invoke ( this , EventArgs . Empty ) ;
23+
24+ /// <summary>
25+ /// Invoked on the client when they receive the host config.
26+ /// </summary>
27+ [ field: NonSerialized ] public event EventHandler SyncReceived ;
28+ internal void OnSyncReceived ( ) => SyncReceived ? . Invoke ( this , EventArgs . Empty ) ;
29+
1830 /// <summary>
1931 /// The mod name or abbreviation. After being given to the constructor, it cannot be changed.
2032 /// </summary>
2133 public readonly string GUID = guid ;
2234
2335 internal SyncedEntry < bool > SYNC_TO_CLIENTS { get ; private set ; } = null ;
2436
37+ /// <summary>
38+ /// Allow the host to control whether clients can use their own config.
39+ /// This MUST be called after binding the entry parameter.
40+ /// </summary>
41+ /// <param name="hostSyncControlOption">The entry for the host to use in your config file.</param>
2542 protected void EnableHostSyncControl ( SyncedEntry < bool > hostSyncControlOption ) {
2643 SYNC_TO_CLIENTS = hostSyncControlOption ;
2744
@@ -51,8 +68,8 @@ void RequestSync() {
5168 }
5269
5370 internal void OnRequestSync ( ulong clientId , FastBufferReader _ ) {
54- // Only run if we are host/server.
5571 if ( ! IsHost ) return ;
72+ OnSyncRequested ( ) ;
5673
5774 if ( SYNC_TO_CLIENTS != null && SYNC_TO_CLIENTS == false ) {
5875 using FastBufferWriter s = new ( IntSize , Allocator . Temp ) ;
@@ -80,6 +97,8 @@ internal void OnRequestSync(ulong clientId, FastBufferReader _) {
8097 }
8198
8299 internal void OnReceiveSync ( ulong _ , FastBufferReader reader ) {
100+ OnSyncReceived ( ) ;
101+
83102 if ( ! reader . TryBeginRead ( IntSize ) ) {
84103 LogErr ( $ "{ GUID } - Config sync error: Could not begin reading buffer.") ;
85104 return ;
0 commit comments