mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
RemoteCallHelper cleanup
This commit is contained in:
parent
0b9539b8de
commit
ba9b9ec85b
@ -4,11 +4,7 @@
|
||||
|
||||
namespace Mirror.RemoteCalls
|
||||
{
|
||||
/// <summary>
|
||||
/// Delegate for Command functions.
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <param name="reader"></param>
|
||||
// command function delegate
|
||||
public delegate void CmdDelegate(NetworkBehaviour obj, NetworkReader reader, NetworkConnectionToClient senderConnection);
|
||||
|
||||
class Invoker
|
||||
@ -31,19 +27,11 @@ public struct CommandInfo
|
||||
public bool requiresAuthority;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to help manage remote calls for NetworkBehaviours
|
||||
/// </summary>
|
||||
/// <summary>Used to help manage remote calls for NetworkBehaviours</summary>
|
||||
public static class RemoteCallHelper
|
||||
{
|
||||
static readonly Dictionary<int, Invoker> cmdHandlerDelegates = new Dictionary<int, Invoker>();
|
||||
|
||||
/// <summary>
|
||||
/// Creates hash from Type and method name
|
||||
/// </summary>
|
||||
/// <param name="invokeClass"></param>
|
||||
/// <param name="methodName"></param>
|
||||
/// <returns></returns>
|
||||
internal static int GetMethodHash(Type invokeClass, string methodName)
|
||||
{
|
||||
// (invokeClass + ":" + cmdName).GetStableHashCode() would cause allocations.
|
||||
@ -55,16 +43,6 @@ internal static int GetMethodHash(Type invokeClass, string methodName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// helper function register a Command/Rpc delegate
|
||||
/// </summary>
|
||||
/// <param name="invokeClass"></param>
|
||||
/// <param name="cmdName"></param>
|
||||
/// <param name="invokerType"></param>
|
||||
/// <param name="func"></param>
|
||||
/// <param name="cmdIgnoreAuthority"></param>
|
||||
/// <returns>remote function hash</returns>
|
||||
internal static int RegisterDelegate(Type invokeClass, string cmdName, MirrorInvokeType invokerType, CmdDelegate func, bool cmdRequiresAuthority = true)
|
||||
{
|
||||
// type+func so Inventory.RpcUse != Equipment.RpcUse
|
||||
@ -117,9 +95,7 @@ public static void RegisterRpcDelegate(Type invokeClass, string rpcName, CmdDele
|
||||
RegisterDelegate(invokeClass, rpcName, MirrorInvokeType.ClientRpc, func);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// We need this in order to clean up tests
|
||||
/// </summary>
|
||||
// We need this in order to clean up tests
|
||||
internal static void RemoveDelegate(int hash)
|
||||
{
|
||||
cmdHandlerDelegates.Remove(hash);
|
||||
@ -136,7 +112,6 @@ static bool GetInvokerForHash(int cmdHash, MirrorInvokeType invokeType, out Invo
|
||||
// (no need to throw an error, an attacker might just be trying to
|
||||
// call an cmd with an rpc's hash)
|
||||
// Debug.Log("GetInvokerForHash hash:" + cmdHash + " not found");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -146,7 +121,6 @@ internal static bool InvokeHandlerDelegate(int cmdHash, MirrorInvokeType invokeT
|
||||
if (GetInvokerForHash(cmdHash, invokeType, out Invoker invoker) && invoker.invokeClass.IsInstanceOfType(invokingType))
|
||||
{
|
||||
invoker.invokeFunction(invokingType, reader, senderConnection);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -164,12 +138,7 @@ internal static CommandInfo GetCommandInfo(int cmdHash, NetworkBehaviour invokin
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the handler function for a given hash
|
||||
/// Can be used by profilers and debuggers
|
||||
/// </summary>
|
||||
/// <param name="cmdHash">rpc function hash</param>
|
||||
/// <returns>The function delegate that will handle the command</returns>
|
||||
/// <summary>Gets the handler function by hash. Useful for profilers & debuggers.</summary>
|
||||
public static CmdDelegate GetDelegate(int cmdHash)
|
||||
{
|
||||
if (cmdHandlerDelegates.TryGetValue(cmdHash, out Invoker invoker))
|
||||
|
Loading…
Reference in New Issue
Block a user