Skip to content

Commit

Permalink
feat: improving log for RegisterHandler
Browse files Browse the repository at this point in the history
logging new handler even if it is not replaced
  • Loading branch information
James-Frowen committed May 24, 2023
1 parent e272411 commit c6d4efd
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Assets/Mirage/Runtime/MessageHandler.cs
Expand Up @@ -23,13 +23,18 @@ public MessageHandler(IObjectLocator objectLocator, bool disconnectOnException)

public void RegisterHandler<T>(MessageDelegateWithPlayer<T> handler, bool allowUnauthenticated)
{
var msgType = MessagePacker.GetId<T>();
var msgId = MessagePacker.GetId<T>();

if (logger.LogEnabled() && _messageHandlers.ContainsKey(msgType))
logger.Log($"RegisterHandler replacing {msgType}");
if (logger.LogEnabled())
{
if (_messageHandlers.ContainsKey(msgId))
logger.Log($"Replacing handler for id:{msgId} type:{typeof(T)}");
else
logger.Log($"New handler for id:{msgId} type:{typeof(T)}");
}

var del = MessageWrapper(handler);
_messageHandlers[msgType] = new Handler(del, false);
_messageHandlers[msgId] = new Handler(del, allowUnauthenticated);
}

private static NetworkMessageDelegate MessageWrapper<T>(MessageDelegateWithPlayer<T> handler)
Expand Down

0 comments on commit c6d4efd

Please sign in to comment.