mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkBehaviour.GetInvokerForHash actually returns the invoker and a new GetInvokerFunctionForHash function returns the function. Can be reused in InvokeHandlerDelegateOfType now too.
This commit is contained in:
parent
376cfebcdf
commit
5bf7244533
@ -250,14 +250,12 @@ protected static void RegisterEventDelegate(Type invokeClass, string eventName,
|
||||
if (LogFilter.Debug) { Debug.Log("RegisterEventDelegate hash:" + eventHash + " " + func.GetMethodName()); }
|
||||
}
|
||||
|
||||
static bool GetInvokerForHash(int cmdHash, UNetInvokeType invokeType, out CmdDelegate invokeFunction)
|
||||
static bool GetInvokerForHash(int cmdHash, UNetInvokeType invokeType, out Invoker invoker)
|
||||
{
|
||||
Invoker invoker;
|
||||
if (s_CmdHandlerDelegates.TryGetValue(cmdHash, out invoker) &&
|
||||
invoker != null &&
|
||||
invoker.invokeType == invokeType)
|
||||
{
|
||||
invokeFunction = invoker.invokeFunction;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -265,6 +263,17 @@ static bool GetInvokerForHash(int cmdHash, UNetInvokeType invokeType, out CmdDel
|
||||
// (no need to throw an error, an attacker might just be trying to
|
||||
// call an cmd with an rpc's hash)
|
||||
if (LogFilter.Debug) { Debug.Log("GetInvokerForHash hash:" + cmdHash + " not found"); }
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool GetInvokerFunctionForHash(int cmdHash, UNetInvokeType invokeType, out CmdDelegate invokeFunction)
|
||||
{
|
||||
Invoker invoker;
|
||||
if (GetInvokerForHash(cmdHash, invokeType, out invoker))
|
||||
{
|
||||
invokeFunction = invoker.invokeFunction;
|
||||
return true;
|
||||
}
|
||||
invokeFunction = null;
|
||||
return false;
|
||||
}
|
||||
@ -272,25 +281,24 @@ static bool GetInvokerForHash(int cmdHash, UNetInvokeType invokeType, out CmdDel
|
||||
// wrapper fucntions for each type of network operation
|
||||
internal static bool GetInvokerForHashCommand(int cmdHash, out CmdDelegate invokeFunction)
|
||||
{
|
||||
return GetInvokerForHash(cmdHash, UNetInvokeType.Command, out invokeFunction);
|
||||
return GetInvokerFunctionForHash(cmdHash, UNetInvokeType.Command, out invokeFunction);
|
||||
}
|
||||
|
||||
internal static bool GetInvokerForHashClientRpc(int cmdHash, out CmdDelegate invokeFunction)
|
||||
{
|
||||
return GetInvokerForHash(cmdHash, UNetInvokeType.ClientRpc, out invokeFunction);
|
||||
return GetInvokerFunctionForHash(cmdHash, UNetInvokeType.ClientRpc, out invokeFunction);
|
||||
}
|
||||
|
||||
internal static bool GetInvokerForHashSyncEvent(int cmdHash, out CmdDelegate invokeFunction)
|
||||
{
|
||||
return GetInvokerForHash(cmdHash, UNetInvokeType.SyncEvent, out invokeFunction);
|
||||
return GetInvokerFunctionForHash(cmdHash, UNetInvokeType.SyncEvent, out invokeFunction);
|
||||
}
|
||||
|
||||
// InvokeCmd/Rpc/SyncEventDelegate can all use the same function here
|
||||
internal bool InvokeHandlerDelegateOfType(int cmdHash, UNetInvokeType invokeType, NetworkReader reader)
|
||||
{
|
||||
Invoker invoker;
|
||||
if (s_CmdHandlerDelegates.TryGetValue(cmdHash, out invoker) &&
|
||||
invoker.invokeType == invokeType &&
|
||||
if (GetInvokerForHash(cmdHash, invokeType, out invoker) &&
|
||||
invoker.invokeClass.IsInstanceOfType(this))
|
||||
{
|
||||
invoker.invokeFunction(this, reader);
|
||||
|
Loading…
Reference in New Issue
Block a user