Skip to content

Commit

Permalink
feat: adding option to stop spanwn on unauthenticated
Browse files Browse the repository at this point in the history
Adding optional check for IsAuthenticated for objects using default visiblity.
Will check IsAuthenticated before adding observer in AddAllReadyServerConnectionsToObservers
  • Loading branch information
James-Frowen committed Oct 8, 2022
1 parent 71cc0c4 commit 629fab8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Assets/Mirage/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,14 @@ internal void AddAllReadyServerConnectionsToObservers()
// add all server connections
foreach (var player in Server.Players)
{
if (player.SceneIsReady)
AddObserver(player);
if (!player.SceneIsReady)
continue;

// todo replace this with a better visibility system (where default checks auth/scene ready)
if (ServerObjectManager.OnlySpawnOnAuthenticated && !player.IsAuthenticated)
continue;

AddObserver(player);
}

// add local host connection (if any)
Expand Down
5 changes: 5 additions & 0 deletions Assets/Mirage/Runtime/ServerObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public class ServerObjectManager : MonoBehaviour
[FormerlySerializedAs("networkSceneManager")]
public NetworkSceneManager NetworkSceneManager;

[Header("Authentication")]
[Tooltip("Will only send spawn message to Players who are Authenticated. Checks the Player.IsAuthenticated property")]
public bool OnlySpawnOnAuthenticated;

public INetIdGenerator NetIdGenerator;
private uint _nextNetworkId = 1;

Expand Down Expand Up @@ -554,6 +558,7 @@ public void Spawn(NetworkIdentity identity, INetworkPlayer owner)

internal void SendSpawnMessage(NetworkIdentity identity, INetworkPlayer player)
{
logger.Assert(!OnlySpawnOnAuthenticated || player.IsAuthenticated, "SendSpawnMessage should only be called if OnlySpanwOnAuthenticated is false or player is authenticated");
if (logger.LogEnabled()) logger.Log($"Server SendSpawnMessage: name={identity.name} sceneId={identity.SceneId:X} netId={identity.NetId}");

// one writer for owner, one for observers
Expand Down

0 comments on commit 629fab8

Please sign in to comment.