move TargetRpc NetworkServer.active and conn is ULocalConnectionToServer check out of weaver (#492)

This commit is contained in:
vis2k 2019-02-28 15:18:52 +01:00 committed by GitHub
parent 8d96dd77cd
commit d7b6c8556f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 27 deletions

View File

@ -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)
{

View File

@ -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

View File

@ -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);