Skip to content

chore: session owner promotion and connection approved updates #3563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop-2.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ internal void SetSessionOwner(ulong sessionOwner)
OnSessionOwnerPromoted?.Invoke(sessionOwner);
}

#if ENABLE_SESSIONOWNER_PROMOTION_NOTIFICATION
public void PromoteSessionOwner(ulong clientId)
#else
internal void PromoteSessionOwner(ulong clientId)
#endif
{
if (!DistributedAuthorityMode)
{
Expand All @@ -256,10 +260,18 @@ internal void PromoteSessionOwner(ulong clientId)
{
SessionOwner = clientId,
};
var clients = ConnectionManager.ConnectedClientIds.Where(c => c != LocalClientId).ToArray();
foreach (var targetClient in clients)

if (CMBServiceConnection)
{
ConnectionManager.SendMessage(ref sessionOwnerMessage, NetworkDelivery.ReliableSequenced, ServerClientId);
}
else
{
ConnectionManager.SendMessage(ref sessionOwnerMessage, NetworkDelivery.ReliableSequenced, targetClient);
var clients = ConnectionManager.ConnectedClientIds.Where(c => c != LocalClientId).ToArray();
foreach (var targetClient in clients)
{
ConnectionManager.SendMessage(ref sessionOwnerMessage, NetworkDelivery.ReliableSequenced, targetClient);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,21 +366,18 @@ public void Handle(ref NetworkContext context)

if (!networkManager.SceneManager.IsRestoringSession)
{
// Synchronize the service with the initial session owner's loaded scenes and spawned objects
networkManager.SceneManager.SynchronizeNetworkObjects(NetworkManager.ServerClientId, true);

// Spawn any in-scene placed NetworkObjects
networkManager.SpawnManager.ServerSpawnSceneObjectsOnStartSweep();

// Synchronize the service with the initial session owner's loaded scenes and spawned objects
networkManager.SceneManager.SynchronizeNetworkObjects(NetworkManager.ServerClientId, true);

// Spawn the local player of the session owner
if (networkManager.AutoSpawnPlayerPrefabClientSide)
{
networkManager.ConnectionManager.CreateAndSpawnPlayer(OwnerClientId);
}

// Synchronize the service with the initial session owner's loaded scenes and spawned objects
networkManager.SceneManager.SynchronizeNetworkObjects(NetworkManager.ServerClientId, true);

// With scene management enabled and since the session owner doesn't send a scene event synchronize to itself,
// we need to notify the session owner that everything should be synchronized/spawned at this time.
networkManager.SpawnManager.NotifyNetworkObjectsSynchronized();
Expand Down