NetworkBehaviour.GetInvokerForHash simplified

This commit is contained in:
vis2k 2018-12-30 17:42:36 +01:00
parent c9f68f4b73
commit c52e36af57

View File

@ -269,29 +269,20 @@ internal static bool GetInvokerForHashSyncEvent(int cmdHash, out CmdDelegate inv
static bool GetInvokerForHash(int cmdHash, UNetInvokeType invokeType, out CmdDelegate invokeFunction) static bool GetInvokerForHash(int cmdHash, UNetInvokeType invokeType, out CmdDelegate invokeFunction)
{ {
Invoker invoker; Invoker invoker;
if (!s_CmdHandlerDelegates.TryGetValue(cmdHash, out invoker)) if (s_CmdHandlerDelegates.TryGetValue(cmdHash, out invoker) &&
invoker != null &&
invoker.invokeType == invokeType)
{ {
if (LogFilter.Debug) { Debug.Log("GetInvokerForHash hash:" + cmdHash + " not found"); } invokeFunction = invoker.invokeFunction;
invokeFunction = null; return true;
return false;
} }
if (invoker == null) // debug message if not found, or null, or mismatched type
{ // (no need to throw an error, an attacker might just be trying to
if (LogFilter.Debug) { Debug.Log("GetInvokerForHash hash:" + cmdHash + " invoker null"); } // call an cmd with an rpc's hash)
invokeFunction = null; if (LogFilter.Debug) { Debug.Log("GetInvokerForHash hash:" + cmdHash + " not found"); }
return false; invokeFunction = null;
} return false;
if (invoker.invokeType != invokeType)
{
Debug.LogError("GetInvokerForHash hash:" + cmdHash + " mismatched invokeType");
invokeFunction = null;
return false;
}
invokeFunction = invoker.invokeFunction;
return true;
} }
internal bool InvokeCommandDelegate(int cmdHash, NetworkReader reader) internal bool InvokeCommandDelegate(int cmdHash, NetworkReader reader)