mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
move TargetRpc NetworkServer.active and conn is ULocalConnectionToServer check out of weaver (#492)
This commit is contained in:
parent
8d96dd77cd
commit
d7b6c8556f
Binary file not shown.
@ -132,6 +132,18 @@ protected void SendRPCInternal(Type invokeClass, string rpcName, NetworkWriter w
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
protected void SendTargetRPCInternal(NetworkConnection conn, Type invokeClass, string rpcName, NetworkWriter writer, int channelId)
|
||||
{
|
||||
// this was in Weaver before
|
||||
if (!NetworkServer.active)
|
||||
{
|
||||
Debug.LogError("TargetRPC Function " + rpcName + " called on client.");
|
||||
return;
|
||||
}
|
||||
// this was in Weaver before
|
||||
if (conn is ULocalConnectionToServer)
|
||||
{
|
||||
Debug.LogError("TargetRPC Function " + rpcName + " called on connection to server");
|
||||
return;
|
||||
}
|
||||
// This cannot use NetworkServer.active, as that is not specific to this object.
|
||||
if (!isServer)
|
||||
{
|
||||
|
@ -42,15 +42,9 @@ public static MethodDefinition ProcessTargetRpcInvoke(TypeDefinition td, MethodD
|
||||
/* generates code like:
|
||||
public void CallTargetTest (NetworkConnection conn, int param)
|
||||
{
|
||||
if (!NetworkServer.get_active ()) {
|
||||
Debug.LogError((object)"TargetRPC Function TargetTest called on client.");
|
||||
} else if (((?)conn) is ULocalConnectionToServer) {
|
||||
Debug.LogError((object)"TargetRPC Function TargetTest called on connection to server");
|
||||
} else {
|
||||
NetworkWriter writer = new NetworkWriter ();
|
||||
writer.WritePackedUInt32 ((uint)param);
|
||||
base.SendTargetRPCInternal (conn, typeof(class), "TargetTest", val);
|
||||
}
|
||||
NetworkWriter writer = new NetworkWriter ();
|
||||
writer.WritePackedUInt32 ((uint)param);
|
||||
base.SendTargetRPCInternal (conn, typeof(class), "TargetTest", val);
|
||||
}
|
||||
*/
|
||||
public static MethodDefinition ProcessTargetRpcCall(TypeDefinition td, MethodDefinition md, CustomAttribute ca)
|
||||
@ -70,20 +64,6 @@ public static MethodDefinition ProcessTargetRpcCall(TypeDefinition td, MethodDef
|
||||
|
||||
NetworkBehaviourProcessor.WriteSetupLocals(rpcWorker);
|
||||
|
||||
NetworkBehaviourProcessor.WriteServerActiveCheck(rpcWorker, md.Name, label, "TargetRPC Function");
|
||||
|
||||
Instruction labelConnectionCheck = rpcWorker.Create(OpCodes.Nop);
|
||||
|
||||
// check specifically for ULocalConnectionToServer so a host is not trying to send
|
||||
// an TargetRPC to the "server" from it's local client.
|
||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldarg_1));
|
||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Isinst, Weaver.ULocalConnectionToServerType));
|
||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Brfalse, labelConnectionCheck));
|
||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ldstr, string.Format("TargetRPC Function {0} called on connection to server", md.Name)));
|
||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Call, Weaver.logErrorReference));
|
||||
rpcWorker.Append(rpcWorker.Create(OpCodes.Ret));
|
||||
rpcWorker.Append(labelConnectionCheck);
|
||||
|
||||
NetworkBehaviourProcessor.WriteCreateWriter(rpcWorker);
|
||||
|
||||
// write all the arguments that the user passed to the TargetRpc call
|
||||
|
@ -61,7 +61,6 @@ class Weaver
|
||||
public static TypeReference MonoBehaviourType;
|
||||
public static TypeReference ScriptableObjectType;
|
||||
public static TypeReference NetworkConnectionType;
|
||||
public static TypeReference ULocalConnectionToServerType;
|
||||
public static TypeReference ULocalConnectionToClientType;
|
||||
|
||||
public static TypeReference MessageBaseType;
|
||||
@ -1123,9 +1122,6 @@ static void SetupTargetTypes()
|
||||
NetworkConnectionType = NetAssembly.MainModule.GetType("Mirror.NetworkConnection");
|
||||
NetworkConnectionType = CurrentAssembly.MainModule.ImportReference(NetworkConnectionType);
|
||||
|
||||
ULocalConnectionToServerType = NetAssembly.MainModule.GetType("Mirror.ULocalConnectionToServer");
|
||||
ULocalConnectionToServerType = CurrentAssembly.MainModule.ImportReference(ULocalConnectionToServerType);
|
||||
|
||||
ULocalConnectionToClientType = NetAssembly.MainModule.GetType("Mirror.ULocalConnectionToClient");
|
||||
ULocalConnectionToClientType = CurrentAssembly.MainModule.ImportReference(ULocalConnectionToClientType);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user