mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Remove Transport.OnDataReceived channelId parameter
This commit is contained in:
parent
1afdfd91d0
commit
c5792ce837
@ -88,7 +88,7 @@ public static bool UnpackMessage(NetworkReader messageReader, out int msgType)
|
||||
internal static NetworkMessageDelegate MessageHandler<T, C>(Action<C, T> 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
|
||||
|
@ -88,14 +88,14 @@ static void OnDisconnected()
|
||||
|
||||
ClientScene.HandleClientDisconnect(connection);
|
||||
|
||||
connection?.InvokeHandler(new DisconnectMessage(), -1);
|
||||
connection?.InvokeHandler(new DisconnectMessage());
|
||||
}
|
||||
|
||||
internal static void OnDataReceived(ArraySegment<byte> data, int channelId)
|
||||
internal static void OnDataReceived(ArraySegment<byte> 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.");
|
||||
}
|
||||
|
@ -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)
|
||||
/// <typeparam name="T">The message type to unregister.</typeparam>
|
||||
/// <param name="msg">The message object to process.</param>
|
||||
/// <returns>Returns true if the handler was successfully invoked</returns>
|
||||
public bool InvokeHandler<T>(T msg, int channelId)
|
||||
public bool InvokeHandler<T>(T msg)
|
||||
where T : struct, NetworkMessage
|
||||
{
|
||||
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
|
||||
@ -226,7 +226,7 @@ public bool InvokeHandler<T>(T msg, int channelId)
|
||||
MessagePacker.Pack(msg, writer);
|
||||
ArraySegment<byte> 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>(T msg, int channelId)
|
||||
/// This function allows custom network connection classes to process data from the network before it is passed to the application.
|
||||
/// </summary>
|
||||
/// <param name="buffer">The data received.</param>
|
||||
internal void TransportReceive(ArraySegment<byte> buffer, int channelId)
|
||||
internal void TransportReceive(ArraySegment<byte> buffer)
|
||||
{
|
||||
// unpack message
|
||||
using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(buffer))
|
||||
@ -251,7 +251,7 @@ internal void TransportReceive(ArraySegment<byte> 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
|
||||
{
|
||||
|
@ -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<byte> data, int channelId)
|
||||
static void OnDataReceived(int connectionId, ArraySegment<byte> data)
|
||||
{
|
||||
if (connections.TryGetValue(connectionId, out NetworkConnectionToClient conn))
|
||||
{
|
||||
conn.TransportReceive(data, channelId);
|
||||
conn.TransportReceive(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -89,7 +89,7 @@ bool ProcessClientMessage()
|
||||
OnClientConnected.Invoke();
|
||||
break;
|
||||
case Telepathy.EventType.Data:
|
||||
OnClientDataReceived.Invoke(new ArraySegment<byte>(message.data), Channels.DefaultReliable);
|
||||
OnClientDataReceived.Invoke(new ArraySegment<byte>(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<byte>(message.data), Channels.DefaultReliable);
|
||||
OnServerDataReceived.Invoke(message.connectionId, new ArraySegment<byte>(message.data));
|
||||
break;
|
||||
case Telepathy.EventType.Disconnected:
|
||||
OnServerDisconnected.Invoke(message.connectionId);
|
||||
|
@ -7,10 +7,10 @@
|
||||
namespace Mirror
|
||||
{
|
||||
// UnityEvent definitions
|
||||
[Serializable] public class ClientDataReceivedEvent : UnityEvent<ArraySegment<byte>, int> { }
|
||||
[Serializable] public class ClientDataReceivedEvent : UnityEvent<ArraySegment<byte>> { }
|
||||
[Serializable] public class UnityEventException : UnityEvent<Exception> { }
|
||||
[Serializable] public class UnityEventInt : UnityEvent<int> { }
|
||||
[Serializable] public class ServerDataReceivedEvent : UnityEvent<int, ArraySegment<byte>, int> { }
|
||||
[Serializable] public class ServerDataReceivedEvent : UnityEvent<int, ArraySegment<byte>> { }
|
||||
[Serializable] public class UnityEventIntException : UnityEvent<int, Exception> { }
|
||||
|
||||
public abstract class Transport : MonoBehaviour
|
||||
|
@ -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
|
||||
|
@ -97,7 +97,7 @@ void ProcessClientMessages()
|
||||
break;
|
||||
case EventType.Data:
|
||||
Debug.Log("MemoryTransport Client Message: Data: " + BitConverter.ToString(message.data));
|
||||
OnClientDataReceived.Invoke(new ArraySegment<byte>(message.data), 0);
|
||||
OnClientDataReceived.Invoke(new ArraySegment<byte>(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<byte>(message.data), 0);
|
||||
OnServerDataReceived.Invoke(message.connectionId, new ArraySegment<byte>(message.data));
|
||||
break;
|
||||
case EventType.Disconnected:
|
||||
Debug.Log("MemoryTransport Server Message: Disconnected");
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user