mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
adding RemoteCallType (#1936)
* adding RemoteCallType * Update Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs
This commit is contained in:
parent
7205d3a705
commit
b1e47d5b6a
@ -123,7 +123,7 @@ public static MethodDefinition ProcessCommandInvoke(TypeDefinition td, MethodDef
|
|||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ProcessMethodsValidateCommand(MethodDefinition md, CustomAttribute commandAttr)
|
public static bool ProcessMethodsValidateCommand(MethodDefinition md)
|
||||||
{
|
{
|
||||||
if (!md.Name.StartsWith("Cmd"))
|
if (!md.Name.StartsWith("Cmd"))
|
||||||
{
|
{
|
||||||
@ -139,7 +139,7 @@ public static bool ProcessMethodsValidateCommand(MethodDefinition md, CustomAttr
|
|||||||
|
|
||||||
// validate
|
// validate
|
||||||
return NetworkBehaviourProcessor.ProcessMethodsValidateFunction(md) &&
|
return NetworkBehaviourProcessor.ProcessMethodsValidateFunction(md) &&
|
||||||
NetworkBehaviourProcessor.ProcessMethodsValidateParameters(md, commandAttr);
|
NetworkBehaviourProcessor.ProcessMethodsValidateParameters(md, RemoteCallType.Command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,13 @@
|
|||||||
|
|
||||||
namespace Mirror.Weaver
|
namespace Mirror.Weaver
|
||||||
{
|
{
|
||||||
|
public enum RemoteCallType
|
||||||
|
{
|
||||||
|
Command,
|
||||||
|
ClientRpc,
|
||||||
|
TargetRpc,
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// processes SyncVars, Cmds, Rpcs, etc. of NetworkBehaviours
|
/// processes SyncVars, Cmds, Rpcs, etc. of NetworkBehaviours
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -820,33 +827,45 @@ public static bool ProcessMethodsValidateFunction(MethodReference md)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ProcessMethodsValidateParameters(MethodReference md, CustomAttribute ca)
|
public static bool ProcessMethodsValidateParameters(MethodReference method, RemoteCallType callType)
|
||||||
{
|
{
|
||||||
bool isTargetRpc = ca.AttributeType.FullName == Weaver.TargetRpcType.FullName;
|
for (int i = 0; i < method.Parameters.Count; ++i)
|
||||||
|
{
|
||||||
|
ParameterDefinition param = method.Parameters[i];
|
||||||
|
|
||||||
for (int i = 0; i < md.Parameters.Count; ++i)
|
bool valid = ValidateParameter(method, param, callType, i == 0);
|
||||||
|
|
||||||
|
if (!valid)
|
||||||
{
|
{
|
||||||
ParameterDefinition p = md.Parameters[i];
|
|
||||||
if (p.IsOut)
|
|
||||||
{
|
|
||||||
Weaver.Error($"{md.Name} cannot have out parameters", md);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (p.IsOptional)
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ValidateParameter(MethodReference method, ParameterDefinition param, RemoteCallType callType, bool firstParam)
|
||||||
{
|
{
|
||||||
Weaver.Error($"{md.Name} cannot have optional parameters", md);
|
bool isNetworkConnection = param.ParameterType.FullName == Weaver.NetworkConnectionType.FullName;
|
||||||
|
|
||||||
|
if (param.IsOut)
|
||||||
|
{
|
||||||
|
Weaver.Error($"{method.Name} cannot have out parameters", method);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFirstParam = i == 0;
|
|
||||||
bool isNetworkConnection = p.ParameterType.FullName == Weaver.NetworkConnectionType.FullName;
|
|
||||||
|
|
||||||
// TargetRPC is an exception to this rule and can have a NetworkConnection as first parameter
|
// TargetRPC is an exception to this rule and can have a NetworkConnection as first parameter
|
||||||
if (isNetworkConnection && !(isTargetRpc && isFirstParam))
|
if (isNetworkConnection && !(callType == RemoteCallType.TargetRpc && firstParam))
|
||||||
{
|
{
|
||||||
Weaver.Error($"{md.Name} has invalid parameter {p}. Cannot pass NeworkConnections", md);
|
Weaver.Error($"{method.Name} has invalid parameter {param}. Cannot pass NeworkConnections", method);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sender connection can be optional
|
||||||
|
if (param.IsOptional)
|
||||||
|
{
|
||||||
|
Weaver.Error($"{method.Name} cannot have optional parameters", method);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -886,7 +905,7 @@ void ProcessMethods()
|
|||||||
|
|
||||||
void ProcessClientRpc(HashSet<string> names, MethodDefinition md, CustomAttribute clientRpcAttr)
|
void ProcessClientRpc(HashSet<string> names, MethodDefinition md, CustomAttribute clientRpcAttr)
|
||||||
{
|
{
|
||||||
if (!RpcProcessor.ProcessMethodsValidateRpc(md, clientRpcAttr))
|
if (!RpcProcessor.ProcessMethodsValidateRpc(md))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -910,7 +929,7 @@ void ProcessClientRpc(HashSet<string> names, MethodDefinition md, CustomAttribut
|
|||||||
|
|
||||||
void ProcessTargetRpc(HashSet<string> names, MethodDefinition md, CustomAttribute targetRpcAttr)
|
void ProcessTargetRpc(HashSet<string> names, MethodDefinition md, CustomAttribute targetRpcAttr)
|
||||||
{
|
{
|
||||||
if (!TargetRpcProcessor.ProcessMethodsValidateTargetRpc(md, targetRpcAttr))
|
if (!TargetRpcProcessor.ProcessMethodsValidateTargetRpc(md))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (names.Contains(md.Name))
|
if (names.Contains(md.Name))
|
||||||
@ -932,7 +951,7 @@ void ProcessTargetRpc(HashSet<string> names, MethodDefinition md, CustomAttribut
|
|||||||
|
|
||||||
void ProcessCommand(HashSet<string> names, MethodDefinition md, CustomAttribute commandAttr)
|
void ProcessCommand(HashSet<string> names, MethodDefinition md, CustomAttribute commandAttr)
|
||||||
{
|
{
|
||||||
if (!CommandProcessor.ProcessMethodsValidateCommand(md, commandAttr))
|
if (!CommandProcessor.ProcessMethodsValidateCommand(md))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (names.Contains(md.Name))
|
if (names.Contains(md.Name))
|
||||||
|
@ -100,7 +100,7 @@ public static MethodDefinition ProcessRpcCall(TypeDefinition td, MethodDefinitio
|
|||||||
return rpc;
|
return rpc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ProcessMethodsValidateRpc(MethodDefinition md, CustomAttribute clientRpcAttr)
|
public static bool ProcessMethodsValidateRpc(MethodDefinition md)
|
||||||
{
|
{
|
||||||
if (!md.Name.StartsWith("Rpc"))
|
if (!md.Name.StartsWith("Rpc"))
|
||||||
{
|
{
|
||||||
@ -116,7 +116,7 @@ public static bool ProcessMethodsValidateRpc(MethodDefinition md, CustomAttribut
|
|||||||
|
|
||||||
// validate
|
// validate
|
||||||
return NetworkBehaviourProcessor.ProcessMethodsValidateFunction(md) &&
|
return NetworkBehaviourProcessor.ProcessMethodsValidateFunction(md) &&
|
||||||
NetworkBehaviourProcessor.ProcessMethodsValidateParameters(md, clientRpcAttr);
|
NetworkBehaviourProcessor.ProcessMethodsValidateParameters(md, RemoteCallType.ClientRpc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ public static MethodDefinition ProcessTargetRpcCall(TypeDefinition td, MethodDef
|
|||||||
return rpc;
|
return rpc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ProcessMethodsValidateTargetRpc(MethodDefinition md, CustomAttribute targetRpcAttr)
|
public static bool ProcessMethodsValidateTargetRpc(MethodDefinition md)
|
||||||
{
|
{
|
||||||
if (!md.Name.StartsWith("Target"))
|
if (!md.Name.StartsWith("Target"))
|
||||||
{
|
{
|
||||||
@ -161,7 +161,7 @@ public static bool ProcessMethodsValidateTargetRpc(MethodDefinition md, CustomAt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
return NetworkBehaviourProcessor.ProcessMethodsValidateParameters(md, targetRpcAttr);
|
return NetworkBehaviourProcessor.ProcessMethodsValidateParameters(md, RemoteCallType.TargetRpc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user