diff --git a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs index b44462f0c..4382e52c5 100644 --- a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs @@ -136,6 +136,37 @@ public void ConnectionsDictTest() NetworkServer.Shutdown(); } + [Test] + public void OnConnectedOnlyAllowsGreaterZeroConnectionIdsTest() + { + // OnConnected should only allow connectionIds >= 0 + // 0 is for local player + // <0 is never used + + // message handlers + NetworkServer.RegisterHandler((conn, msg) => {}, false); + NetworkServer.RegisterHandler((conn, msg) => {}, false); + NetworkServer.RegisterHandler((conn, msg) => {}, false); + + // listen + NetworkServer.Listen(2); + Assert.That(NetworkServer.connections.Count, Is.EqualTo(0)); + + // connect 0 + // (it will show an error message, which is expected) + LogAssert.ignoreFailingMessages = true; + Transport.activeTransport.OnServerConnected.Invoke(0); + Assert.That(NetworkServer.connections.Count, Is.EqualTo(0)); + + // connect <0 + Transport.activeTransport.OnServerConnected.Invoke(-1); + Assert.That(NetworkServer.connections.Count, Is.EqualTo(0)); + LogAssert.ignoreFailingMessages = false; + + // shutdown + NetworkServer.Shutdown(); + } + [Test] public void SetLocalConnectionTest() {