Skip to content

Commit d0e540a

Browse files
committed
Fix Connection deferred queue
1 parent a4c4f37 commit d0e540a

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ClientDisconnectedMessage.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public bool Deserialize(FastBufferReader reader, ref NetworkContext context, int
2525
public void Handle(ref NetworkContext context)
2626
{
2727
var networkManager = (NetworkManager)context.SystemOwner;
28+
if (networkManager.DistributedAuthorityMode && networkManager.CMBServiceConnection && networkManager.LocalClient.IsSessionOwner && networkManager.NetworkConfig.EnableSceneManagement)
29+
{
30+
networkManager.SceneManager.ClientConnectionQueue.Remove(ClientId);
31+
}
2832
// All modes support removing NetworkClients
2933
networkManager.ConnectionManager.RemoveClient(ClientId);
3034
networkManager.ConnectionManager.ConnectedClientIds.Remove(ClientId);

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ConnectionApprovedMessage.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,23 @@ public bool Deserialize(FastBufferReader reader, ref NetworkContext context, int
246246
public void Handle(ref NetworkContext context)
247247
{
248248
var networkManager = (NetworkManager)context.SystemOwner;
249-
if (NetworkLog.CurrentLogLevel <= LogLevel.Developer)
250-
{
251-
NetworkLog.LogInfo($"[Client-{OwnerClientId}] Connection approved! Synchronizing...");
252-
}
253249

254250
if (networkManager.CMBServiceConnection && networkManager.LocalClient.IsSessionOwner && networkManager.NetworkConfig.EnableSceneManagement && networkManager.LocalClientId != OwnerClientId)
255251
{
252+
if (NetworkLog.CurrentLogLevel <= LogLevel.Developer)
253+
{
254+
NetworkLog.LogInfo($"[Session Owner] Received connection approved for Client-{OwnerClientId}! Synchronizing...");
255+
}
256+
256257
networkManager.SceneManager.SynchronizeNetworkObjects(OwnerClientId);
257258
return;
258259
}
259260

261+
if (NetworkLog.CurrentLogLevel <= LogLevel.Developer)
262+
{
263+
NetworkLog.LogInfo($"[Client-{OwnerClientId}] Connection approved! Synchronizing...");
264+
}
265+
260266
networkManager.LocalClientId = OwnerClientId;
261267
networkManager.MessageManager.SetLocalClientId(networkManager.LocalClientId);
262268
networkManager.NetworkMetrics.SetConnectionId(networkManager.LocalClientId);

com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,10 @@ private void OnClientLoadedScene(uint sceneEventId, Scene scene)
19251925
/// when many clients attempt to connect at the same time they will be
19261926
/// handled sequentially so as to not saturate the session owner's maximum
19271927
/// reliable messages.
1928+
/// DANGO-TODO: Get clients to track their synchronization status (if they haven't finished synchronizing)
1929+
/// - pending clients can listen to SessionOwnerChanged messages
1930+
/// - If the session owner changes, fire "some sort of event" to the service
1931+
/// - service can fire ConnectionApproved at new session owner
19281932
/// </summary>
19291933
internal List<ulong> ClientConnectionQueue = new List<ulong>();
19301934

@@ -2529,27 +2533,29 @@ private void HandleSessionOwnerEvent(uint sceneEventId, ulong clientId)
25292533
{
25302534
// Remove the client that just synchronized
25312535
ClientConnectionQueue.Remove(clientId);
2532-
2533-
// If we have pending clients to synchronize, then make sure they are still connected
2534-
while (ClientConnectionQueue.Count > 0)
2535-
{
2536-
// If the next client is no longer connected then remove it from the list
2537-
if (!NetworkManager.ConnectedClientsIds.Contains(ClientConnectionQueue[0]))
2538-
{
2539-
ClientConnectionQueue.RemoveAt(0);
2540-
}
2541-
else
2542-
{
2543-
break;
2544-
}
2545-
}
2536+
// Debug.Log($"Remove client-{clientId} from synchronization queue.");
2537+
//
2538+
// // If we have pending clients to synchronize, then make sure they are still connected
2539+
// while (ClientConnectionQueue.Count > 0)
2540+
// {
2541+
// // If the next client is no longer connected then remove it from the list
2542+
// if (!NetworkManager.ConnectedClientsIds.Contains(ClientConnectionQueue[0]))
2543+
// {
2544+
// Debug.Log($"Remove client-{clientId} from synchronization queue as they are no longer connected.");
2545+
// ClientConnectionQueue.RemoveAt(0);
2546+
// }
2547+
// else
2548+
// {
2549+
// break;
2550+
// }
2551+
// }
25462552

25472553
// If we still have any pending clients waiting, then synchronize the next one
25482554
if (ClientConnectionQueue.Count > 0)
25492555
{
25502556
if (NetworkManager.LogLevel <= LogLevel.Developer)
25512557
{
2552-
Debug.Log($"Synchronizing Client-{ClientConnectionQueue[0]}...");
2558+
Debug.Log($"Synchronizing Deferred Client-{ClientConnectionQueue[0]}...");
25532559
}
25542560
SynchronizeNetworkObjects(ClientConnectionQueue[0]);
25552561
}

0 commit comments

Comments
 (0)