mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
breaking: Removing manual invoke for Cmd and RPC (#2223)
* Removing manual invoke for Cmd and RPC There should be no reason to manaully invoke remote code they are marked with EditorBrowsableState.Never which implies they should not be called by the user * removing tests
This commit is contained in:
parent
a30e8fcd85
commit
2033f7d009
@ -207,17 +207,6 @@ protected void SendCommandInternal(Type invokeClass, string cmdName, NetworkWrit
|
||||
ClientScene.readyConnection.Send(message, channelId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Manually invoke a Command.
|
||||
/// </summary>
|
||||
/// <param name="cmdHash">Hash of the Command name.</param>
|
||||
/// <param name="reader">Parameters to pass to the command.</param>
|
||||
/// <returns>Returns true if successful.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public virtual bool InvokeCommand(int cmdHash, NetworkReader reader)
|
||||
{
|
||||
return RemoteCallHelper.InvokeHandlerDelegate(cmdHash, MirrorInvokeType.Command, reader, this);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Client RPCs
|
||||
@ -295,17 +284,6 @@ protected void SendTargetRPCInternal(NetworkConnection conn, Type invokeClass, s
|
||||
conn.Send(message, channelId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Manually invoke an RPC function.
|
||||
/// </summary>
|
||||
/// <param name="rpcHash">Hash of the RPC name.</param>
|
||||
/// <param name="reader">Parameters to pass to the RPC function.</param>
|
||||
/// <returns>Returns true if successful.</returns>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public virtual bool InvokeRPC(int rpcHash, NetworkReader reader)
|
||||
{
|
||||
return RemoteCallHelper.InvokeHandlerDelegate(rpcHash, MirrorInvokeType.ClientRpc, reader, this);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
@ -392,31 +392,6 @@ public void SendCommandInternal()
|
||||
GameObject.DestroyImmediate(transportGO);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InvokeCommand()
|
||||
{
|
||||
// add command component
|
||||
NetworkBehaviourSendCommandInternalComponent comp = gameObject.AddComponent<NetworkBehaviourSendCommandInternalComponent>();
|
||||
Assert.That(comp.called, Is.EqualTo(0));
|
||||
|
||||
// register the command delegate, otherwise it's not found
|
||||
int registeredHash = RemoteCallHelper.RegisterDelegate(typeof(NetworkBehaviourSendCommandInternalComponent),
|
||||
nameof(NetworkBehaviourSendCommandInternalComponent.CommandGenerated),
|
||||
MirrorInvokeType.Command,
|
||||
NetworkBehaviourSendCommandInternalComponent.CommandGenerated,
|
||||
false);
|
||||
|
||||
// invoke command
|
||||
int cmdHash = RemoteCallHelper.GetMethodHash(
|
||||
typeof(NetworkBehaviourSendCommandInternalComponent),
|
||||
nameof(NetworkBehaviourSendCommandInternalComponent.CommandGenerated));
|
||||
comp.InvokeCommand(cmdHash, new NetworkReader(new byte[0]));
|
||||
Assert.That(comp.called, Is.EqualTo(1));
|
||||
|
||||
// clean up
|
||||
RemoteCallHelper.RemoveDelegate(registeredHash);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SendRPCInternal()
|
||||
{
|
||||
@ -595,30 +570,6 @@ public void SendTargetRPCInternal()
|
||||
GameObject.DestroyImmediate(transportGO);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InvokeRPC()
|
||||
{
|
||||
// add command component
|
||||
NetworkBehaviourSendRPCInternalComponent comp = gameObject.AddComponent<NetworkBehaviourSendRPCInternalComponent>();
|
||||
Assert.That(comp.called, Is.EqualTo(0));
|
||||
|
||||
// register the command delegate, otherwise it's not found
|
||||
int registeredHash = RemoteCallHelper.RegisterDelegate(typeof(NetworkBehaviourSendRPCInternalComponent),
|
||||
nameof(NetworkBehaviourSendRPCInternalComponent.RPCGenerated),
|
||||
MirrorInvokeType.ClientRpc,
|
||||
NetworkBehaviourSendRPCInternalComponent.RPCGenerated);
|
||||
|
||||
// invoke command
|
||||
int rpcHash = RemoteCallHelper.GetMethodHash(
|
||||
typeof(NetworkBehaviourSendRPCInternalComponent),
|
||||
nameof(NetworkBehaviourSendRPCInternalComponent.RPCGenerated));
|
||||
comp.InvokeRPC(rpcHash, new NetworkReader(new byte[0]));
|
||||
Assert.That(comp.called, Is.EqualTo(1));
|
||||
|
||||
// clean up
|
||||
RemoteCallHelper.RemoveDelegate(registeredHash);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RegisterDelegateDoesntOverwrite()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user