diff --git a/Assets/Mirror/Runtime/NetworkConnectionToClient.cs b/Assets/Mirror/Runtime/NetworkConnectionToClient.cs index 5932c3873..c866df192 100644 --- a/Assets/Mirror/Runtime/NetworkConnectionToClient.cs +++ b/Assets/Mirror/Runtime/NetworkConnectionToClient.cs @@ -91,7 +91,7 @@ internal void SendBatch(int channelId, Batch batch) writer.Position + segment.Count >= max) { // flush & reset writer - Transport.activeTransport.ServerSend(connectionId, channelId, writer.ToArraySegment()); + Transport.activeTransport.ServerSend(connectionId, writer.ToArraySegment(), channelId); writer.SetLength(0); } @@ -113,7 +113,7 @@ internal void SendBatch(int channelId, Batch batch) // send it. if (writer.Position > 0) { - Transport.activeTransport.ServerSend(connectionId, channelId, writer.ToArraySegment()); + Transport.activeTransport.ServerSend(connectionId, writer.ToArraySegment(), channelId); writer.SetLength(0); } } @@ -144,7 +144,7 @@ internal override void Send(ArraySegment segment, int channelId = Channels batch.messages.Enqueue(writer); } // otherwise send directly to minimize latency - else Transport.activeTransport.ServerSend(connectionId, channelId, segment); + else Transport.activeTransport.ServerSend(connectionId, segment, channelId); } } diff --git a/Assets/Mirror/Runtime/NetworkConnectionToServer.cs b/Assets/Mirror/Runtime/NetworkConnectionToServer.cs index 29b1827bc..434147cda 100644 --- a/Assets/Mirror/Runtime/NetworkConnectionToServer.cs +++ b/Assets/Mirror/Runtime/NetworkConnectionToServer.cs @@ -13,7 +13,7 @@ internal override void Send(ArraySegment segment, int channelId = Channels // validate packet size first. if (ValidatePacketSize(segment, channelId)) { - Transport.activeTransport.ClientSend(channelId, segment); + Transport.activeTransport.ClientSend(segment, channelId); } } diff --git a/Assets/Mirror/Runtime/Transport/FallbackTransport.cs b/Assets/Mirror/Runtime/Transport/FallbackTransport.cs index a66f04dbb..4d784fe97 100644 --- a/Assets/Mirror/Runtime/Transport/FallbackTransport.cs +++ b/Assets/Mirror/Runtime/Transport/FallbackTransport.cs @@ -93,9 +93,9 @@ public override void ClientDisconnect() available.ClientDisconnect(); } - public override void ClientSend(int channelId, ArraySegment segment) + public override void ClientSend(ArraySegment segment, int channelId) { - available.ClientSend(channelId, segment); + available.ClientSend(segment, channelId); } // right now this just returns the first available uri, @@ -117,9 +117,9 @@ public override void ServerDisconnect(int connectionId) available.ServerDisconnect(connectionId); } - public override void ServerSend(int connectionId, int channelId, ArraySegment segment) + public override void ServerSend(int connectionId, ArraySegment segment, int channelId) { - available.ServerSend(connectionId, channelId, segment); + available.ServerSend(connectionId, segment, channelId); } public override void ServerStart() diff --git a/Assets/Mirror/Runtime/Transport/KCP/MirrorTransport/KcpTransport.cs b/Assets/Mirror/Runtime/Transport/KCP/MirrorTransport/KcpTransport.cs index d5ce80044..1b6e6191b 100644 --- a/Assets/Mirror/Runtime/Transport/KCP/MirrorTransport/KcpTransport.cs +++ b/Assets/Mirror/Runtime/Transport/KCP/MirrorTransport/KcpTransport.cs @@ -90,7 +90,7 @@ public override void ClientConnect(string address) { client.Connect(address, Port, NoDelay, Interval, FastResend, CongestionWindow, SendWindowSize, ReceiveWindowSize); } - public override void ClientSend(int channelId, ArraySegment segment) + public override void ClientSend(ArraySegment segment, int channelId) { // switch to kcp channel. // unreliable or reliable. @@ -149,7 +149,7 @@ public override Uri ServerUri() } public override bool ServerActive() => server.IsActive(); public override void ServerStart() => server.Start(Port); - public override void ServerSend(int connectionId, int channelId, ArraySegment segment) + public override void ServerSend(int connectionId, ArraySegment segment, int channelId) { // switch to kcp channel. // unreliable or reliable. diff --git a/Assets/Mirror/Runtime/Transport/LatencySimulation.cs b/Assets/Mirror/Runtime/Transport/LatencySimulation.cs index 550a8a123..d6f836d48 100644 --- a/Assets/Mirror/Runtime/Transport/LatencySimulation.cs +++ b/Assets/Mirror/Runtime/Transport/LatencySimulation.cs @@ -91,7 +91,7 @@ float SimulateLatency(int channeldId) } // helper function to simulate a send with latency/loss/scramble - void SimulateSend(int connectionId, int channelId, ArraySegment segment, float latency, List reliableQueue, List unreliableQueue) + void SimulateSend(int connectionId, ArraySegment segment, int channelId, float latency, List reliableQueue, List unreliableQueue) { // segment is only valid after returning. copy it. // (allocates for now. it's only for testing anyway.) @@ -161,10 +161,10 @@ public override void ClientDisconnect() unreliableClientToServer.Clear(); } - public override void ClientSend(int channelId, ArraySegment segment) + public override void ClientSend(ArraySegment segment, int channelId) { float latency = SimulateLatency(channelId); - SimulateSend(0, channelId, segment, latency, reliableClientToServer, unreliableClientToServer); + SimulateSend(0, segment, channelId, latency, reliableClientToServer, unreliableClientToServer); } public override Uri ServerUri() => wrap.ServerUri(); @@ -175,10 +175,10 @@ public override void ClientSend(int channelId, ArraySegment segment) public override void ServerDisconnect(int connectionId) => wrap.ServerDisconnect(connectionId); - public override void ServerSend(int connectionId, int channelId, ArraySegment segment) + public override void ServerSend(int connectionId, ArraySegment segment, int channelId) { float latency = SimulateLatency(channelId); - SimulateSend(connectionId, channelId, segment, latency, reliableServerToClient, unreliableServerToClient); + SimulateSend(connectionId, segment, channelId, latency, reliableServerToClient, unreliableServerToClient); } public override void ServerStart() @@ -209,7 +209,7 @@ public override void ClientLateUpdate() if (message.time <= Time.time) { // send and eat - wrap.ClientSend(Channels.Reliable, new ArraySegment(message.bytes)); + wrap.ClientSend(new ArraySegment(message.bytes), Channels.Reliable); reliableClientToServer.RemoveAt(0); } // not enough time elapsed yet @@ -224,7 +224,7 @@ public override void ClientLateUpdate() if (message.time <= Time.time) { // send and eat - wrap.ClientSend(Channels.Unreliable, new ArraySegment(message.bytes)); + wrap.ClientSend(new ArraySegment(message.bytes), Channels.Unreliable); unreliableClientToServer.RemoveAt(0); } // not enough time elapsed yet @@ -244,7 +244,7 @@ public override void ServerLateUpdate() if (message.time <= Time.time) { // send and eat - wrap.ServerSend(message.connectionId, Channels.Reliable, new ArraySegment(message.bytes)); + wrap.ServerSend(message.connectionId, new ArraySegment(message.bytes), Channels.Reliable); reliableServerToClient.RemoveAt(0); } // not enough time elapsed yet @@ -259,7 +259,7 @@ public override void ServerLateUpdate() if (message.time <= Time.time) { // send and eat - wrap.ServerSend(message.connectionId, Channels.Unreliable, new ArraySegment(message.bytes)); + wrap.ServerSend(message.connectionId, new ArraySegment(message.bytes), Channels.Unreliable); unreliableServerToClient.RemoveAt(0); } // not enough time elapsed yet diff --git a/Assets/Mirror/Runtime/Transport/MiddlewareTransport.cs b/Assets/Mirror/Runtime/Transport/MiddlewareTransport.cs index 61e3f2e29..a0a64ad92 100644 --- a/Assets/Mirror/Runtime/Transport/MiddlewareTransport.cs +++ b/Assets/Mirror/Runtime/Transport/MiddlewareTransport.cs @@ -30,7 +30,7 @@ public override void ClientConnect(string address) public override bool ClientConnected() => inner.ClientConnected(); public override void ClientDisconnect() => inner.ClientDisconnect(); - public override void ClientSend(int channelId, ArraySegment segment) => inner.ClientSend(channelId, segment); + public override void ClientSend(ArraySegment segment, int channelId) => inner.ClientSend(segment, channelId); #endregion #region Server @@ -45,7 +45,7 @@ public override void ServerStart() } public override void ServerStop() => inner.ServerStop(); - public override void ServerSend(int connectionId, int channelId, ArraySegment segment) => inner.ServerSend(connectionId, channelId, segment); + public override void ServerSend(int connectionId, ArraySegment segment, int channelId) => inner.ServerSend(connectionId, segment, channelId); public override void ServerDisconnect(int connectionId) => inner.ServerDisconnect(connectionId); public override string ServerGetClientAddress(int connectionId) => inner.ServerGetClientAddress(connectionId); public override Uri ServerUri() => inner.ServerUri(); diff --git a/Assets/Mirror/Runtime/Transport/MultiplexTransport.cs b/Assets/Mirror/Runtime/Transport/MultiplexTransport.cs index fe57714ae..0d0503d5c 100644 --- a/Assets/Mirror/Runtime/Transport/MultiplexTransport.cs +++ b/Assets/Mirror/Runtime/Transport/MultiplexTransport.cs @@ -137,9 +137,9 @@ public override void ClientDisconnect() available.ClientDisconnect(); } - public override void ClientSend(int channelId, ArraySegment segment) + public override void ClientSend(ArraySegment segment, int channelId) { - available.ClientSend(channelId, segment); + available.ClientSend(segment, channelId); } #endregion @@ -231,7 +231,7 @@ public override void ServerDisconnect(int connectionId) transports[transportId].ServerDisconnect(baseConnectionId); } - public override void ServerSend(int connectionId, int channelId, ArraySegment segment) + public override void ServerSend(int connectionId, ArraySegment segment, int channelId) { int baseConnectionId = ToBaseId(connectionId); int transportId = ToTransportId(connectionId); @@ -240,7 +240,7 @@ public override void ServerSend(int connectionId, int channelId, ArraySegment segment) + public override void ClientSend(ArraySegment segment, int channelId) { if (!ClientConnected()) { @@ -244,7 +244,7 @@ public override void ServerDisconnect(int connectionId) server.KickClient(connectionId); } - public override void ServerSend(int connectionId, int channelId, ArraySegment segment) + public override void ServerSend(int connectionId, ArraySegment segment, int channelId) { if (!ServerActive()) { @@ -265,7 +265,6 @@ public override void ServerSend(int connectionId, int channelId, ArraySegment segment) => client.Send(segment); + public override void ClientSend(ArraySegment segment, int channelId) => client.Send(segment); public override void ClientDisconnect() => client.Disconnect(); // messages should always be processed in early update public override void ClientEarlyUpdate() @@ -158,7 +158,7 @@ public override Uri ServerUri() } public override bool ServerActive() => server.Active; public override void ServerStart() => server.Start(port); - public override void ServerSend(int connectionId, int channelId, ArraySegment segment) => server.Send(connectionId, segment); + public override void ServerSend(int connectionId, ArraySegment segment, int channelId) => server.Send(connectionId, segment); public override void ServerDisconnect(int connectionId) => server.Disconnect(connectionId); public override string ServerGetClientAddress(int connectionId) { diff --git a/Assets/Mirror/Tests/Common/MemoryTransport.cs b/Assets/Mirror/Tests/Common/MemoryTransport.cs index a54efa9ce..902164c4c 100644 --- a/Assets/Mirror/Tests/Common/MemoryTransport.cs +++ b/Assets/Mirror/Tests/Common/MemoryTransport.cs @@ -52,7 +52,7 @@ public override void ClientConnect(string address) clientConnected = true; } } - public override void ClientSend(int channelId, ArraySegment segment) + public override void ClientSend(ArraySegment segment, int channelId) { // only if client connected if (clientConnected) @@ -115,7 +115,7 @@ public override void ClientEarlyUpdate() public override bool ServerActive() => serverActive; public override Uri ServerUri() => throw new NotImplementedException(); public override void ServerStart() { serverActive = true; } - public override void ServerSend(int connectionId, int channelId, ArraySegment segment) + public override void ServerSend(int connectionId, ArraySegment segment, int channelId) { // only if server is running and client is connected if (serverActive && clientConnected) diff --git a/Assets/Mirror/Tests/Editor/MiddlewareTransportTest.cs b/Assets/Mirror/Tests/Editor/MiddlewareTransportTest.cs index 2b2bd8a6e..bb24fd8d9 100644 --- a/Assets/Mirror/Tests/Editor/MiddlewareTransportTest.cs +++ b/Assets/Mirror/Tests/Editor/MiddlewareTransportTest.cs @@ -106,14 +106,12 @@ public void TestClientSend(int channel) const int count = 5; ArraySegment segment = new ArraySegment(array, offset, count); - middleware.ClientSend(channel, segment); + middleware.ClientSend(segment, channel); - inner.Received(1).ClientSend(channel, Arg.Is>(x => x.Array == array && x.Offset == offset && x.Count == count)); - inner.Received(0).ClientSend(Arg.Is(x => x != channel), Arg.Any>()); + inner.Received(1).ClientSend(Arg.Is>(x => x.Array == array && x.Offset == offset && x.Count == count), channel); + inner.Received(0).ClientSend(Arg.Any>(), Arg.Is(x => x != channel)); } - - [Test] [TestCase(true)] [TestCase(false)] @@ -154,11 +152,11 @@ public void TestServerSend(int id, int channel) const int count = 5; ArraySegment segment = new ArraySegment(array, offset, count); - middleware.ServerSend(id, channel, segment); + middleware.ServerSend(id, segment, channel); - inner.Received(1).ServerSend(id, channel, Arg.Is>(x => x.Array == array && x.Offset == offset && x.Count == count)); + inner.Received(1).ServerSend(id, Arg.Is>(x => x.Array == array && x.Offset == offset && x.Count == count), channel); // only need to check first arg, - inner.Received(0).ServerSend(Arg.Is(x => x != id), Arg.Any(), Arg.Any>()); + inner.Received(0).ServerSend(Arg.Is(x => x != id), Arg.Any>(), Arg.Any()); } [Test] diff --git a/Assets/Mirror/Tests/Editor/MultiplexTest.cs b/Assets/Mirror/Tests/Editor/MultiplexTest.cs index 58c6aec5e..3c0567a38 100644 --- a/Assets/Mirror/Tests/Editor/MultiplexTest.cs +++ b/Assets/Mirror/Tests/Editor/MultiplexTest.cs @@ -128,9 +128,9 @@ public void TestClientSend() byte[] data = { 1, 2, 3 }; ArraySegment segment = new ArraySegment(data); - transport.ClientSend(3, segment); + transport.ClientSend(segment, 3); - transport1.Received().ClientSend(3, segment); + transport1.Received().ClientSend(segment, 3); } [Test] @@ -175,11 +175,10 @@ public void TestServerConnected() byte[] data = { 1, 2, 3 }; ArraySegment segment = new ArraySegment(data); - // on connect, send a message back void SendMessage(int connectionId) { - transport.ServerSend(connectionId, 5, segment); + transport.ServerSend(connectionId, segment, 5); } // set event and Start to give event to inner @@ -188,7 +187,7 @@ void SendMessage(int connectionId) transport1.OnServerConnected.Invoke(1); - transport1.Received().ServerSend(1, 5, segment); + transport1.Received().ServerSend(1, segment, 5); }