From c5792ce837e9beeb3dc89edc5e8e456413765e8a Mon Sep 17 00:00:00 2001 From: vis2k Date: Thu, 1 Oct 2020 11:33:05 +0200 Subject: [PATCH] Remove Transport.OnDataReceived channelId parameter --- Assets/Mirror/Runtime/MessagePacker.cs | 2 +- Assets/Mirror/Runtime/NetworkClient.cs | 8 ++++---- Assets/Mirror/Runtime/NetworkConnection.cs | 12 ++++++------ Assets/Mirror/Runtime/NetworkServer.cs | 8 ++++---- .../Mirror/Runtime/Transport/TelepathyTransport.cs | 4 ++-- Assets/Mirror/Runtime/Transport/Transport.cs | 4 ++-- Assets/Mirror/Runtime/UNetwork.cs | 2 +- Assets/Mirror/Tests/Common/MemoryTransport.cs | 4 ++-- Assets/Mirror/Tests/Editor/NetworkServerTest.cs | 12 ++++++------ 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Assets/Mirror/Runtime/MessagePacker.cs b/Assets/Mirror/Runtime/MessagePacker.cs index e749e48ed..2eb87ffdb 100644 --- a/Assets/Mirror/Runtime/MessagePacker.cs +++ b/Assets/Mirror/Runtime/MessagePacker.cs @@ -88,7 +88,7 @@ public static bool UnpackMessage(NetworkReader messageReader, out int msgType) internal static NetworkMessageDelegate MessageHandler(Action handler, bool requireAuthenication) where T : struct, NetworkMessage where C : NetworkConnection - => (conn, reader, channelId) => + => (conn, reader) => { // protect against DOS attacks if attackers try to send invalid // data packets to crash the server/client. there are a thousand diff --git a/Assets/Mirror/Runtime/NetworkClient.cs b/Assets/Mirror/Runtime/NetworkClient.cs index 716281ca0..b6d4bfdd7 100644 --- a/Assets/Mirror/Runtime/NetworkClient.cs +++ b/Assets/Mirror/Runtime/NetworkClient.cs @@ -88,14 +88,14 @@ static void OnDisconnected() ClientScene.HandleClientDisconnect(connection); - connection?.InvokeHandler(new DisconnectMessage(), -1); + connection?.InvokeHandler(new DisconnectMessage()); } - internal static void OnDataReceived(ArraySegment data, int channelId) + internal static void OnDataReceived(ArraySegment data) { if (connection != null) { - connection.TransportReceive(data, channelId); + connection.TransportReceive(data); } else Debug.LogError("Skipped Data message handling because connection is null."); } @@ -111,7 +111,7 @@ static void OnConnected() // thus we should set the connected state before calling the handler connectState = ConnectState.Connected; NetworkTime.UpdateClient(); - connection.InvokeHandler(new ConnectMessage(), -1); + connection.InvokeHandler(new ConnectMessage()); } else Debug.LogError("Skipped Connect message handling because connection is null."); } diff --git a/Assets/Mirror/Runtime/NetworkConnection.cs b/Assets/Mirror/Runtime/NetworkConnection.cs index 9154eed5f..a17260788 100644 --- a/Assets/Mirror/Runtime/NetworkConnection.cs +++ b/Assets/Mirror/Runtime/NetworkConnection.cs @@ -194,11 +194,11 @@ internal void RemoveObservers() visList.Clear(); } - internal bool InvokeHandler(int msgType, NetworkReader reader, int channelId) + internal bool InvokeHandler(int msgType, NetworkReader reader) { if (messageHandlers.TryGetValue(msgType, out NetworkMessageDelegate msgDelegate)) { - msgDelegate(this, reader, channelId); + msgDelegate(this, reader); return true; } // Debug.Log("Unknown message ID " + msgType + " " + this + ". May be due to no existing RegisterHandler for this message."); @@ -212,7 +212,7 @@ internal bool InvokeHandler(int msgType, NetworkReader reader, int channelId) /// The message type to unregister. /// The message object to process. /// Returns true if the handler was successfully invoked - public bool InvokeHandler(T msg, int channelId) + public bool InvokeHandler(T msg) where T : struct, NetworkMessage { using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter()) @@ -226,7 +226,7 @@ public bool InvokeHandler(T msg, int channelId) MessagePacker.Pack(msg, writer); ArraySegment segment = writer.ToArraySegment(); using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(segment)) - return InvokeHandler(msgType, networkReader, channelId); + return InvokeHandler(msgType, networkReader); } } @@ -240,7 +240,7 @@ public bool InvokeHandler(T msg, int channelId) /// This function allows custom network connection classes to process data from the network before it is passed to the application. /// /// The data received. - internal void TransportReceive(ArraySegment buffer, int channelId) + internal void TransportReceive(ArraySegment buffer) { // unpack message using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(buffer)) @@ -251,7 +251,7 @@ internal void TransportReceive(ArraySegment buffer, int channelId) // Debug.Log("ConnectionRecv " + this + " msgType:" + msgType + " content:" + BitConverter.ToString(buffer.Array, buffer.Offset, buffer.Count)); // try to invoke the handler for that message - InvokeHandler(msgType, networkReader, channelId); + InvokeHandler(msgType, networkReader); } else { diff --git a/Assets/Mirror/Runtime/NetworkServer.cs b/Assets/Mirror/Runtime/NetworkServer.cs index 7eb7678f8..5e7b0f765 100644 --- a/Assets/Mirror/Runtime/NetworkServer.cs +++ b/Assets/Mirror/Runtime/NetworkServer.cs @@ -419,7 +419,7 @@ internal static void OnConnected(NetworkConnectionToClient conn) // add connection and invoke connected event AddConnection(conn); - conn.InvokeHandler(new ConnectMessage(), -1); + conn.InvokeHandler(new ConnectMessage()); } internal static void OnDisconnected(int connectionId) @@ -438,15 +438,15 @@ internal static void OnDisconnected(int connectionId) static void OnDisconnected(NetworkConnection conn) { - conn.InvokeHandler(new DisconnectMessage(), -1); + conn.InvokeHandler(new DisconnectMessage()); // Debug.Log("Server lost client:" + conn); } - static void OnDataReceived(int connectionId, ArraySegment data, int channelId) + static void OnDataReceived(int connectionId, ArraySegment data) { if (connections.TryGetValue(connectionId, out NetworkConnectionToClient conn)) { - conn.TransportReceive(data, channelId); + conn.TransportReceive(data); } else { diff --git a/Assets/Mirror/Runtime/Transport/TelepathyTransport.cs b/Assets/Mirror/Runtime/Transport/TelepathyTransport.cs index 25647a1bc..4d9995fcf 100644 --- a/Assets/Mirror/Runtime/Transport/TelepathyTransport.cs +++ b/Assets/Mirror/Runtime/Transport/TelepathyTransport.cs @@ -89,7 +89,7 @@ bool ProcessClientMessage() OnClientConnected.Invoke(); break; case Telepathy.EventType.Data: - OnClientDataReceived.Invoke(new ArraySegment(message.data), Channels.DefaultReliable); + OnClientDataReceived.Invoke(new ArraySegment(message.data)); break; case Telepathy.EventType.Disconnected: OnClientDisconnected.Invoke(); @@ -175,7 +175,7 @@ public bool ProcessServerMessage() OnServerConnected.Invoke(message.connectionId); break; case Telepathy.EventType.Data: - OnServerDataReceived.Invoke(message.connectionId, new ArraySegment(message.data), Channels.DefaultReliable); + OnServerDataReceived.Invoke(message.connectionId, new ArraySegment(message.data)); break; case Telepathy.EventType.Disconnected: OnServerDisconnected.Invoke(message.connectionId); diff --git a/Assets/Mirror/Runtime/Transport/Transport.cs b/Assets/Mirror/Runtime/Transport/Transport.cs index 4b2ebf450..f7299aa48 100644 --- a/Assets/Mirror/Runtime/Transport/Transport.cs +++ b/Assets/Mirror/Runtime/Transport/Transport.cs @@ -7,10 +7,10 @@ namespace Mirror { // UnityEvent definitions - [Serializable] public class ClientDataReceivedEvent : UnityEvent, int> { } + [Serializable] public class ClientDataReceivedEvent : UnityEvent> { } [Serializable] public class UnityEventException : UnityEvent { } [Serializable] public class UnityEventInt : UnityEvent { } - [Serializable] public class ServerDataReceivedEvent : UnityEvent, int> { } + [Serializable] public class ServerDataReceivedEvent : UnityEvent> { } [Serializable] public class UnityEventIntException : UnityEvent { } public abstract class Transport : MonoBehaviour diff --git a/Assets/Mirror/Runtime/UNetwork.cs b/Assets/Mirror/Runtime/UNetwork.cs index fe43a94bd..97197b84f 100644 --- a/Assets/Mirror/Runtime/UNetwork.cs +++ b/Assets/Mirror/Runtime/UNetwork.cs @@ -3,7 +3,7 @@ namespace Mirror { // Handles network messages on client and server - public delegate void NetworkMessageDelegate(NetworkConnection conn, NetworkReader reader, int channelId); + public delegate void NetworkMessageDelegate(NetworkConnection conn, NetworkReader reader); // invoke type for Cmd/Rpc public enum MirrorInvokeType diff --git a/Assets/Mirror/Tests/Common/MemoryTransport.cs b/Assets/Mirror/Tests/Common/MemoryTransport.cs index 4f21c8c54..07c8aba1b 100644 --- a/Assets/Mirror/Tests/Common/MemoryTransport.cs +++ b/Assets/Mirror/Tests/Common/MemoryTransport.cs @@ -97,7 +97,7 @@ void ProcessClientMessages() break; case EventType.Data: Debug.Log("MemoryTransport Client Message: Data: " + BitConverter.ToString(message.data)); - OnClientDataReceived.Invoke(new ArraySegment(message.data), 0); + OnClientDataReceived.Invoke(new ArraySegment(message.data)); break; case EventType.Disconnected: Debug.Log("MemoryTransport Client Message: Disconnected"); @@ -174,7 +174,7 @@ void ProcessServerMessages() break; case EventType.Data: Debug.Log("MemoryTransport Server Message: Data: " + BitConverter.ToString(message.data)); - OnServerDataReceived.Invoke(message.connectionId, new ArraySegment(message.data), 0); + OnServerDataReceived.Invoke(message.connectionId, new ArraySegment(message.data)); break; case EventType.Disconnected: Debug.Log("MemoryTransport Server Message: Disconnected"); diff --git a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs index cfbd4a3e1..0c2ea45db 100644 --- a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs @@ -387,7 +387,7 @@ public void OnDataReceivedTest() // -> should call NetworkServer.OnDataReceived // -> conn.TransportReceive // -> Handler(CommandMessage) - Transport.activeTransport.OnServerDataReceived.Invoke(42, segment, 0); + Transport.activeTransport.OnServerDataReceived.Invoke(42, segment); // was our message handler called now? Assert.That(wasReceived, Is.True); @@ -427,7 +427,7 @@ public void OnDataReceivedInvalidConnectionIdTest() // call transport.OnDataReceived with an invalid connectionId // an error log is expected. LogAssert.ignoreFailingMessages = true; - Transport.activeTransport.OnServerDataReceived.Invoke(42, segment, 0); + Transport.activeTransport.OnServerDataReceived.Invoke(42, segment); LogAssert.ignoreFailingMessages = false; // message handler should never be called @@ -464,13 +464,13 @@ public void RegisterUnregisterClearHandlerTest() // serialize first message, send it to server, check if it was handled NetworkWriter writer = new NetworkWriter(); MessagePacker.Pack(new TestMessage1(), writer); - Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment(), 0); + Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment()); Assert.That(variant1Called, Is.EqualTo(1)); // serialize second message, send it to server, check if it was handled writer = new NetworkWriter(); MessagePacker.Pack(new TestMessage2(), writer); - Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment(), 0); + Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment()); Assert.That(variant2Called, Is.EqualTo(1)); // unregister first handler, send, should fail @@ -479,7 +479,7 @@ public void RegisterUnregisterClearHandlerTest() MessagePacker.Pack(new TestMessage1(), writer); // log error messages are expected LogAssert.ignoreFailingMessages = true; - Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment(), 0); + Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment()); LogAssert.ignoreFailingMessages = false; // still 1, not 2 Assert.That(variant1Called, Is.EqualTo(1)); @@ -492,7 +492,7 @@ public void RegisterUnregisterClearHandlerTest() MessagePacker.Pack(new TestMessage1(), writer); // log error messages are expected LogAssert.ignoreFailingMessages = true; - Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment(), 0); + Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment()); LogAssert.ignoreFailingMessages = false; // still 1, not 2 Assert.That(variant2Called, Is.EqualTo(1));