mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
obsolete redundant NetworkClient.RegisterHandler version with NetworkConnection
This commit is contained in:
parent
e0d023828f
commit
461ce519ff
@ -304,7 +304,7 @@ public static void Send<T>(T message, int channelId = Channels.DefaultReliable)
|
|||||||
|
|
||||||
// message handlers ////////////////////////////////////////////////////
|
// message handlers ////////////////////////////////////////////////////
|
||||||
/// <summary>Register a handler for a message type T. Most should require authentication.</summary>
|
/// <summary>Register a handler for a message type T. Most should require authentication.</summary>
|
||||||
// TODO remove. don't need redundant NetworkConnection parameter. it's always .connection anyway.
|
[Obsolete("Use RegisterHandler<T> version without NetworkConnection parameter. It always points to NetworkClient.connection anyway.")]
|
||||||
public static void RegisterHandler<T>(Action<NetworkConnection, T> handler, bool requireAuthentication = true)
|
public static void RegisterHandler<T>(Action<NetworkConnection, T> handler, bool requireAuthentication = true)
|
||||||
where T : struct, NetworkMessage
|
where T : struct, NetworkMessage
|
||||||
{
|
{
|
||||||
@ -320,7 +320,16 @@ public static void RegisterHandler<T>(Action<NetworkConnection, T> handler, bool
|
|||||||
public static void RegisterHandler<T>(Action<T> handler, bool requireAuthentication = true)
|
public static void RegisterHandler<T>(Action<T> handler, bool requireAuthentication = true)
|
||||||
where T : struct, NetworkMessage
|
where T : struct, NetworkMessage
|
||||||
{
|
{
|
||||||
RegisterHandler((NetworkConnection _, T value) => { handler(value); }, requireAuthentication);
|
int msgType = MessagePacking.GetId<T>();
|
||||||
|
if (handlers.ContainsKey(msgType))
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"NetworkClient.RegisterHandler replacing handler for {typeof(T).FullName}, id={msgType}. If replacement is intentional, use ReplaceHandler instead to avoid this warning.");
|
||||||
|
}
|
||||||
|
// we use the same WrapHandler function for server and client.
|
||||||
|
// so let's wrap it to ignore the NetworkConnection parameter.
|
||||||
|
// it's not needed on client. it's always NetworkClient.connection.
|
||||||
|
Action<NetworkConnection, T> handlerWrapped = (_, value) => { handler(value); };
|
||||||
|
handlers[msgType] = MessagePacking.WrapHandler(handlerWrapped, requireAuthentication);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Replace a handler for a particular message type. Should require authentication by default.</summary>
|
/// <summary>Replace a handler for a particular message type. Should require authentication by default.</summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user