From 9b9b9cc400b40dde762e896cbd8dd4b68ff84746 Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Wed, 10 Jan 2024 07:46:48 -0500 Subject: [PATCH] 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> --- Assets/Mirror/Core/NetworkServer.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Assets/Mirror/Core/NetworkServer.cs b/Assets/Mirror/Core/NetworkServer.cs index a3e4c695c..7ae96d821 100644 --- a/Assets/Mirror/Core/NetworkServer.cs +++ b/Assets/Mirror/Core/NetworkServer.cs @@ -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; }