feature: remote call overloads are now allowed for [ClientRpc] too. they are possible now due to 0cdeccbe71 using .FullName instead of .Name

This commit is contained in:
vis2k 2022-01-19 18:30:13 +08:00
parent fb025d7de7
commit b6f4c641de
4 changed files with 32 additions and 11 deletions

View File

@ -1129,13 +1129,6 @@ void ProcessClientRpc(HashSet<string> names, MethodDefinition md, CustomAttribut
return;
}
if (names.Contains(md.Name))
{
Log.Error($"Duplicate ClientRpc name {md.Name}", md);
WeavingFailed = true;
return;
}
bool includeOwner = clientRpcAttr.GetField("includeOwner", true);
names.Add(md.Name);

View File

@ -35,6 +35,18 @@ public void RpcSendMonster(MockMonsterBase someMonster) =>
onSendMonsterBase?.Invoke(someMonster);
}
class RpcOverloads : NetworkBehaviour
{
public int firstCalled = 0;
public int secondCalled = 0;
[ClientRpc]
public void RpcTest(int _) => ++firstCalled;
[ClientRpc]
public void RpcTest(string _) => ++secondCalled;
}
public class ClientRpcTest : RemoteTestBase
{
[Test]
@ -123,5 +135,21 @@ public void RpcIsCalledWithAbstractNetworkBehaviourParameter()
ProcessMessages();
Assert.That(called, Is.EqualTo(2));
}
// RemoteCalls uses md.FullName which gives us the full command/rpc name
// like "System.Void Mirror.Tests.RemoteAttrributeTest.AuthorityBehaviour::SendInt(System.Int32)"
// which means overloads with same name but different types should work.
[Test]
public void RpcOverload()
{
// spawn with owner
CreateNetworkedAndSpawn(out GameObject _, out NetworkIdentity _, out RpcOverloads hostBehaviour, NetworkServer.localConnection);
hostBehaviour.RpcTest(42);
hostBehaviour.RpcTest("A");
ProcessMessages();
Assert.That(hostBehaviour.firstCalled, Is.EqualTo(1));
Assert.That(hostBehaviour.secondCalled, Is.EqualTo(1));
}
}
}

View File

@ -211,8 +211,7 @@ public void NetworkBehaviourClientRpcParamNetworkConnection()
[Test]
public void NetworkBehaviourClientRpcDuplicateName()
{
HasError("Duplicate ClientRpc name RpcCantHaveSameName",
"System.Void WeaverNetworkBehaviourTests.NetworkBehaviourClientRpcDuplicateName.NetworkBehaviourClientRpcDuplicateName::RpcCantHaveSameName(System.Int32,System.Int32)");
IsSuccess();
}
[Test]

View File

@ -4,10 +4,11 @@ namespace WeaverNetworkBehaviourTests.NetworkBehaviourClientRpcDuplicateName
{
class NetworkBehaviourClientRpcDuplicateName : NetworkBehaviour
{
// remote call overloads are now supported
[ClientRpc]
public void RpcCantHaveSameName(int abc) { }
public void RpcWithSameName(int abc) {}
[ClientRpc]
public void RpcCantHaveSameName(int abc, int def) { }
public void RpcWithSameName(int abc, int def) {}
}
}