fix(NetworkServer): Improve Warnings (#3727)

* fix(NetworkServer): Improve Warnings
- Attempt to dig up the Object, component, and method name to make debugging easier
- Changes identity to identity.name so the object name is logged correctly.

* Update Assets/Mirror/Core/NetworkServer.cs

Co-authored-by: mischa <16416509+miwarnec@users.noreply.github.com>

* Update Assets/Mirror/Core/NetworkServer.cs

Co-authored-by: mischa <16416509+miwarnec@users.noreply.github.com>

* Use GetFunctionMethodName

* cleanup

---------

Co-authored-by: mischa <16416509+miwarnec@users.noreply.github.com>
This commit is contained in:
MrGadget 2024-01-10 07:46:48 -05:00 committed by GitHub
parent ac72d3670d
commit 9b9b9cc400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -315,7 +315,18 @@ static void OnCommandMessage(NetworkConnectionToClient conn, CommandMessage msg,
// Ignore commands that may have been in flight before client received NotReadyMessage message.
// Unreliable messages may be out of order, so don't spam warnings for those.
if (channelId == Channels.Reliable)
{
// Attempt to identify the target object, component, and method to narrow down the cause of the error.
if (spawned.TryGetValue(msg.netId, out NetworkIdentity netIdentity))
if (msg.componentIndex < netIdentity.NetworkBehaviours.Length && netIdentity.NetworkBehaviours[msg.componentIndex] is NetworkBehaviour component)
if (RemoteProcedureCalls.GetFunctionMethodName(msg.functionHash, out string methodName))
{
Debug.LogWarning($"Command {methodName} received for {netIdentity.name} [netId={msg.netId}] component {component.name} [index={msg.componentIndex}] when client not ready.\nThis may be ignored if client intentionally set NotReady.");
return;
}
Debug.LogWarning("Command received while client is not ready.\nThis may be ignored if client intentionally set NotReady.");
}
return;
}
@ -336,7 +347,15 @@ static void OnCommandMessage(NetworkConnectionToClient conn, CommandMessage msg,
bool requiresAuthority = RemoteProcedureCalls.CommandRequiresAuthority(msg.functionHash);
if (requiresAuthority && identity.connectionToClient != conn)
{
Debug.LogWarning($"Command for object without authority [netId={msg.netId}]");
// Attempt to identify the component and method to narrow down the cause of the error.
if (msg.componentIndex < identity.NetworkBehaviours.Length && identity.NetworkBehaviours[msg.componentIndex] is NetworkBehaviour component)
if (RemoteProcedureCalls.GetFunctionMethodName(msg.functionHash, out string methodName))
{
Debug.LogWarning($"Command {methodName} received for {identity.name} [netId={msg.netId}] component {component.name} [index={msg.componentIndex}] without authority");
return;
}
Debug.LogWarning($"Command received for {identity.name} [netId={msg.netId}] without authority");
return;
}