mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Detect hash collisions in rpc registration (#231)
This commit is contained in:
parent
92d35a6039
commit
eb1863a96c
@ -201,9 +201,23 @@ protected class Invoker
|
|||||||
protected static void RegisterDelegate(Type invokeClass, string cmdName, UNetInvokeType invokerType, CmdDelegate func)
|
protected static void RegisterDelegate(Type invokeClass, string cmdName, UNetInvokeType invokerType, CmdDelegate func)
|
||||||
{
|
{
|
||||||
int cmdHash = (invokeClass + ":" + cmdName).GetStableHashCode(); // type+func so Inventory.RpcUse != Equipment.RpcUse
|
int cmdHash = (invokeClass + ":" + cmdName).GetStableHashCode(); // type+func so Inventory.RpcUse != Equipment.RpcUse
|
||||||
|
|
||||||
if (s_CmdHandlerDelegates.ContainsKey(cmdHash))
|
if (s_CmdHandlerDelegates.ContainsKey(cmdHash))
|
||||||
{
|
{
|
||||||
return;
|
// something already registered this hash
|
||||||
|
Invoker oldInvoker = s_CmdHandlerDelegates[cmdHash];
|
||||||
|
if (oldInvoker.invokeClass == invokeClass && oldInvoker.invokeType == invokerType && oldInvoker.invokeFunction == func)
|
||||||
|
{
|
||||||
|
// it's all right, it was the same function
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.LogError(string.Format(
|
||||||
|
"Function {0}.{1} and {2}.{3} have the same hash. Please rename one of them",
|
||||||
|
oldInvoker.invokeClass,
|
||||||
|
oldInvoker.invokeFunction.GetMethodName(),
|
||||||
|
invokeClass,
|
||||||
|
oldInvoker.invokeFunction.GetMethodName()));
|
||||||
}
|
}
|
||||||
Invoker invoker = new Invoker();
|
Invoker invoker = new Invoker();
|
||||||
invoker.invokeType = invokerType;
|
invoker.invokeType = invokerType;
|
||||||
|
Loading…
Reference in New Issue
Block a user