diff --git a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs index 4382e52c5..713c36cf8 100644 --- a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs @@ -167,6 +167,32 @@ public void OnConnectedOnlyAllowsGreaterZeroConnectionIdsTest() NetworkServer.Shutdown(); } + [Test] + public void ConnectDuplicateConnectionIdsTest() + { + // 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 first + Transport.activeTransport.OnServerConnected.Invoke(42); + Assert.That(NetworkServer.connections.Count, Is.EqualTo(1)); + NetworkConnectionToClient original = NetworkServer.connections[42]; + + // connect duplicate - shouldn't overwrite first one + Transport.activeTransport.OnServerConnected.Invoke(42); + Assert.That(NetworkServer.connections.Count, Is.EqualTo(1)); + Assert.That(NetworkServer.connections[42], Is.EqualTo(original)); + + // shutdown + NetworkServer.Shutdown(); + } + [Test] public void SetLocalConnectionTest() {