@@ -1998,18 +1998,26 @@ private void OnClientLoadedScene(uint sceneEventId, Scene scene)
19981998 /// <param name="clientId">newly joined client identifier</param>
19991999 internal void SynchronizeNetworkObjects ( ulong clientId , bool synchronizingService = false )
20002000 {
2001- // If this is a newly connecting client, add it to the connecting client queue
2002- if ( ! synchronizingService && ! ClientConnectionQueue . Contains ( clientId ) )
2001+ // If we are connected to a live service hosted session and we are not doing the initial synchronization for the service...
2002+ if ( NetworkManager . CMBServiceConnection && ! synchronizingService )
20032003 {
2004- ClientConnectionQueue . Add ( clientId ) ;
2005- // If we are already synchronizing a client, then add this client to the queue and exit.
2006- if ( ClientConnectionQueue . Count > 1 )
2004+ // then as long as this is a newly connecting client add it to the connecting client queue.
2005+ // Otherwise, if this is not a newly connecting client (i.e. it is already in the queue), then go ahead and synchronize
2006+ // that client.
2007+ if ( ! ClientConnectionQueue . Contains ( clientId ) )
20072008 {
2008- Debug . Log ( $ "Deferring Client-{ clientId } synchrnization.") ;
2009- return ;
2009+ ClientConnectionQueue . Add ( clientId ) ;
2010+ // If we are already synchronizing one or more clients, then add this client to the queue and exit.
2011+ if ( ClientConnectionQueue . Count > 1 )
2012+ {
2013+ if ( NetworkManager . LogLevel <= LogLevel . Developer )
2014+ {
2015+ Debug . Log ( $ "Deferring Client-{ clientId } synchrnization.") ;
2016+ }
2017+ return ;
2018+ }
20102019 }
20112020 }
2012-
20132021
20142022 // Update the clients
20152023 NetworkManager . SpawnManager . UpdateObservedNetworkObjects ( clientId ) ;
@@ -2638,12 +2646,43 @@ private void HandleSessionOwnerEvent(uint sceneEventId, ulong clientId)
26382646 // DANGO-EXP TODO: Remove this once service distributes objects
26392647 NetworkManager . SpawnManager . DistributeNetworkObjects ( clientId ) ;
26402648 EndSceneEvent ( sceneEventId ) ;
2641- ClientConnectionQueue . Remove ( clientId ) ;
2642- Debug . Log ( $ "Client-{ clientId } synchronized.") ;
2643- if ( ClientConnectionQueue . Count > 0 )
2649+
2650+ // Exit early if not a distributed authority session or this is a DAHost
2651+ // (DAHost has a unique connection per client, so no need to queue synchronization)
2652+ if ( ! NetworkManager . DistributedAuthorityMode || NetworkManager . DAHost )
26442653 {
2645- Debug . Log ( $ "Synchronizing Client-{ ClientConnectionQueue [ 0 ] } ...") ;
2646- SynchronizeNetworkObjects ( ClientConnectionQueue [ 0 ] ) ;
2654+ return ;
2655+ }
2656+
2657+ // Otherwise, this is a session owner that could have pending clients to synchronize
2658+ if ( NetworkManager . DistributedAuthorityMode && NetworkManager . CMBServiceConnection )
2659+ {
2660+ // Remove the client that just synchronized
2661+ ClientConnectionQueue . Remove ( clientId ) ;
2662+
2663+ // If we have pending clients to synchronize, then make sure they are still connected
2664+ while ( ClientConnectionQueue . Count > 0 )
2665+ {
2666+ // If the next client is no longer connected then remove it from the list
2667+ if ( ! NetworkManager . ConnectedClientsIds . Contains ( ClientConnectionQueue [ 0 ] ) )
2668+ {
2669+ ClientConnectionQueue . RemoveAt ( 0 ) ;
2670+ }
2671+ else
2672+ {
2673+ break ;
2674+ }
2675+ }
2676+
2677+ // If we still have any pending clients waiting, then synchronize the next one
2678+ if ( ClientConnectionQueue . Count > 0 )
2679+ {
2680+ if ( NetworkManager . LogLevel <= LogLevel . Developer )
2681+ {
2682+ Debug . Log ( $ "Synchronizing Client-{ ClientConnectionQueue [ 0 ] } ...") ;
2683+ }
2684+ SynchronizeNetworkObjects ( ClientConnectionQueue [ 0 ] ) ;
2685+ }
26472686 }
26482687 break ;
26492688 }
0 commit comments