Skip to content

Commit

Permalink
refactor: using new SendToAll method
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed May 6, 2024
1 parent 8b1117b commit 8901b32
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Assets/Mirage/Runtime/NetworkSceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ internal void OnServerFinishedSceneLoad(Scene scene, SceneOperation operation)

// todo this might cause issues if only some players are loading scene
// send to all, excluding host
Server.SendToAll(new SceneReadyMessage(), excludeLocalPlayer: true);
Server.SendToAll(new SceneReadyMessage(), authenticatedOnly: false, excludeLocalPlayer: true);

// clean up and invoke server functions before user events
Server.World.RemoveDestroyedObjects();
Expand Down
3 changes: 2 additions & 1 deletion Assets/Mirage/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,9 @@ internal void AddLocalConnection(NetworkClient client, IConnection connection)
Authenticator.PreAddHostPlayer(player);
}

[Obsolete("Use SendToAll(msg, authenticatedOnly, excludeLocalPlayer, channelId) instead", true)]
[Obsolete("Use SendToAll(msg, authenticatedOnly, excludeLocalPlayer, channelId) instead")]
public void SendToAll<T>(T msg, bool excludeLocalPlayer, Channel channelId = Channel.Reliable) => SendToAll(msg, authenticatedOnly: false, excludeLocalPlayer, channelId);

public void SendToAll<T>(T msg, bool authenticatedOnly, bool excludeLocalPlayer, Channel channelId = Channel.Reliable)
{
if (authenticatedOnly)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void OnStopServer()
{
// note: if in host mode you may not want to send SceneMessage to host player. In that case use the excludeLocalPlayer flag
var msg = new SceneMessage { MainActivateScene = gameScene, SceneOperation = SceneOperation.UnloadAdditive };
Server.SendToAll(msg, excludeLocalPlayer: true);
Server.SendToAll(msg, authenticatedOnly: true, excludeLocalPlayer: true);
StartCoroutine(UnloadSubScenes());
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirage/Samples~/Snippets/SendNetworkMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void SendScore(int score, Vector3 scorePos, int lives)
};

// also send to host player so we can update ui
Server.SendToAll(msg, excludeLocalPlayer: false);
Server.SendToAll(msg, authenticatedOnly: true, excludeLocalPlayer: false);
}
}
// CodeEmbed-End: send-score
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Runtime/ClientServerSendTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override UniTask LateSetup()
[UnityTest]
public IEnumerator SendToAll([Values(true, false)] bool excludeLocal)
{
server.SendToAll(new TestMessage(), excludeLocal);
server.SendToAll(new TestMessage(), authenticatedOnly: true, excludeLocal);
yield return null;

for (var i = 0; i < RemoteClientCount; i++)
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Runtime/HostSendTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected override UniTask LateSetup()
[UnityTest]
public IEnumerator SendToAll([Values(true, false)] bool excludeLocal)
{
server.SendToAll(new TestMessage(), excludeLocal);
server.SendToAll(new TestMessage(), authenticatedOnly: true, excludeLocal);
yield return null;

for (var i = 0; i < ClientCount; i++)
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Runtime/SendToAllocations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void ShouldNotAllocate([Values(true, false)] bool excludeLocal)
{
TestAllocation<NetworkServer>(() =>
{
server.SendToAll(new TestMessage(), excludeLocal);
server.SendToAll(new TestMessage(), authenticatedOnly: true, excludeLocal);
});
}

Expand Down

0 comments on commit 8901b32

Please sign in to comment.