Detect hash collisions in rpc registration (#231)

This commit is contained in:
Paul Pacheco 2019-01-02 19:32:47 -06:00 committed by GitHub
parent 92d35a6039
commit eb1863a96c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -201,10 +201,24 @@ protected class Invoker
protected static void RegisterDelegate(Type invokeClass, string cmdName, UNetInvokeType invokerType, CmdDelegate func)
{
int cmdHash = (invokeClass + ":" + cmdName).GetStableHashCode(); // type+func so Inventory.RpcUse != Equipment.RpcUse
if (s_CmdHandlerDelegates.ContainsKey(cmdHash))
{
// 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.invokeType = invokerType;
invoker.invokeClass = invokeClass;