Skip to content

Commit

Permalink
fix: logging message name for Unauthenticated Message
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Feb 10, 2025
1 parent 6956167 commit bd1b12b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions Assets/Mirage/Runtime/MessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void RegisterHandler<T>(MessageDelegateWithPlayer<T> handler, bool allowU
}

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

private static NetworkMessageDelegate MessageWrapper<T>(MessageDelegateWithPlayer<T> handler)
Expand Down Expand Up @@ -158,7 +158,7 @@ private bool CheckAuthentication(INetworkPlayer player, int msgType, Handler han
logger.Log($"Unauthenticated Message {type} received from {player}, player is not Authenticated so handler will not be invoked");
}

logger.LogError("Disconnecting Unauthenticated player");
logger.LogError(handler.UnauthenticatedError);
player.Disconnect();

return false;
Expand All @@ -175,11 +175,16 @@ internal class Handler
{
public readonly NetworkMessageDelegate Delegate;
public readonly bool AllowUnauthenticated;
public readonly string UnauthenticatedError;

public Handler(NetworkMessageDelegate @delegate, bool allowUnauthenticated)
public Handler(NetworkMessageDelegate @delegate, bool allowUnauthenticated, Type type)
{
Delegate = @delegate;
AllowUnauthenticated = allowUnauthenticated;

// cache the error message with the type, so we can log it on server with less allocations
if (!allowUnauthenticated)
UnauthenticatedError = $"Unauthenticated Message {type.FullName}, Disconnecting player";
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Tests/Runtime/Serialization/MessageHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void DoesNotInvokesMessageHandler_WhenNotAuthenticated()
var messageId = MessagePacker.GetId<SceneReadyMessage>();
messageHandler.InvokeHandler(player, messageId, reader);
}
, LogType.Error, $"Disconnecting Unauthenticated player");
, LogType.Error, $"Unauthenticated Message {typeof(SceneReadyMessage).FullName}, Disconnecting player");

Assert.That(invoked, Is.EqualTo(0), "Should not have been invoked");
connection.Received(1).Disconnect();
Expand Down

0 comments on commit bd1b12b

Please sign in to comment.