Skip to content

Commit

Permalink
Revert "Don't require Cmd, Rpc and Target prefixes (#127)"
Browse files Browse the repository at this point in the history
This reverts commit 590630f.

If you don't use the prefix,  you get stack overflow with the [Commands]
  • Loading branch information
paulpach committed Dec 15, 2018
1 parent c85391a commit 96992c3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Mirror/Weaver/UNetBehaviourProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,13 @@ bool ProcessMethodsValidateParameters(MethodReference md, CustomAttribute ca, st

private bool ProcessMethodsValidateCommand(MethodDefinition md, CustomAttribute ca)
{
if (md.Name.Length > 2 && md.Name.Substring(0, 3) != "Cmd")
{
Log.Error("Command function [" + m_td.FullName + ":" + md.Name + "] doesnt have 'Cmd' prefix");
Weaver.fail = true;
return false;
}

if (md.IsStatic)
{
Log.Error("Command function [" + m_td.FullName + ":" + md.Name + "] cant be a static method");
Expand All @@ -1287,6 +1294,16 @@ private bool ProcessMethodsValidateCommand(MethodDefinition md, CustomAttribute

bool ProcessMethodsValidateTargetRpc(MethodDefinition md, CustomAttribute ca)
{
const string targetPrefix = "Target";
int prefixLen = targetPrefix.Length;

if (md.Name.Length > prefixLen && md.Name.Substring(0, prefixLen) != targetPrefix)
{
Log.Error("Target Rpc function [" + m_td.FullName + ":" + md.Name + "] doesnt have 'Target' prefix");
Weaver.fail = true;
return false;
}

if (md.IsStatic)
{
Log.Error("TargetRpc function [" + m_td.FullName + ":" + md.Name + "] cant be a static method");
Expand Down Expand Up @@ -1322,6 +1339,13 @@ bool ProcessMethodsValidateTargetRpc(MethodDefinition md, CustomAttribute ca)

bool ProcessMethodsValidateRpc(MethodDefinition md, CustomAttribute ca)
{
if (md.Name.Length > 2 && md.Name.Substring(0, 3) != "Rpc")
{
Log.Error("Rpc function [" + m_td.FullName + ":" + md.Name + "] doesnt have 'Rpc' prefix");
Weaver.fail = true;
return false;
}

if (md.IsStatic)
{
Log.Error("ClientRpc function [" + m_td.FullName + ":" + md.Name + "] cant be a static method");
Expand Down

0 comments on commit 96992c3

Please sign in to comment.