Skip to content

Commit

Permalink
breaking: Rename [Command] to [ServerRpc] (#271)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Renamed [Command] to [ServerRpc]
  • Loading branch information
Lymdun committed Jul 13, 2020
1 parent 9a32bc8 commit fff7459
Show file tree
Hide file tree
Showing 64 changed files with 345 additions and 345 deletions.
16 changes: 8 additions & 8 deletions Assets/Mirror/Components/Experimental/NetworkRigidbody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void SyncToClients()
}

/// <summary>
/// Uses Command to send values to server
/// Uses ServerRpc to send values to server
/// </summary>
[Client]
void SendToServer()
Expand Down Expand Up @@ -247,7 +247,7 @@ void SendVelocity()
[Client]
void SendRigidBodySettings()
{
// These shouldn't change often so it is ok to send in their own Command
// These shouldn't change often so it is ok to send in their own ServerRpc
if (previousValue.isKinematic != target.isKinematic)
{
CmdSendIsKinematic(target.isKinematic);
Expand All @@ -273,7 +273,7 @@ void SendRigidBodySettings()
/// <summary>
/// Called when only Velocity has changed on the client
/// </summary>
[Command]
[ServerRpc]
void CmdSendVelocity(Vector3 velocity)
{
// Ignore messages from client if not in client authority mode
Expand All @@ -287,7 +287,7 @@ void CmdSendVelocity(Vector3 velocity)
/// <summary>
/// Called when angularVelocity has changed on the client
/// </summary>
[Command]
[ServerRpc]
void CmdSendVelocityAndAngular(Vector3 velocity, Vector3 angularVelocity)
{
// Ignore messages from client if not in client authority mode
Expand All @@ -305,7 +305,7 @@ void CmdSendVelocityAndAngular(Vector3 velocity, Vector3 angularVelocity)
target.angularVelocity = angularVelocity;
}

[Command]
[ServerRpc]
void CmdSendIsKinematic(bool isKinematic)
{
// Ignore messages from client if not in client authority mode
Expand All @@ -316,7 +316,7 @@ void CmdSendIsKinematic(bool isKinematic)
target.isKinematic = isKinematic;
}

[Command]
[ServerRpc]
void CmdSendUseGravity(bool useGravity)
{
// Ignore messages from client if not in client authority mode
Expand All @@ -327,7 +327,7 @@ void CmdSendUseGravity(bool useGravity)
target.useGravity = useGravity;
}

[Command]
[ServerRpc]
void CmdSendDrag(float drag)
{
// Ignore messages from client if not in client authority mode
Expand All @@ -338,7 +338,7 @@ void CmdSendDrag(float drag)
target.drag = drag;
}

[Command]
[ServerRpc]
void CmdSendAngularDrag(float angularDrag)
{
// Ignore messages from client if not in client authority mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ bool NeedsTeleport()
}

// local authority client sends sync message to server for broadcasting
[Command]
[ServerRpc]
void CmdClientToServerSync(Vector3 position, Quaternion rotation, Vector3 scale)
{
// Ignore messages from client if not in client authority mode
Expand Down
8 changes: 4 additions & 4 deletions Assets/Mirror/Components/NetworkAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public void ResetTrigger(int hash)

#region server message handlers

[Command]
[ServerRpc]
void CmdOnAnimationServerMessage(int stateHash, float normalizedTime, int layerId, byte[] parameters)
{
// Ignore messages from client if not in client authority mode
Expand All @@ -476,7 +476,7 @@ void CmdOnAnimationServerMessage(int stateHash, float normalizedTime, int layerI
}
}

[Command]
[ServerRpc]
void CmdOnAnimationParametersServerMessage(byte[] parameters)
{
// Ignore messages from client if not in client authority mode
Expand All @@ -491,7 +491,7 @@ void CmdOnAnimationParametersServerMessage(byte[] parameters)
}
}

[Command]
[ServerRpc]
void CmdOnAnimationTriggerServerMessage(int hash)
{
// Ignore messages from client if not in client authority mode
Expand All @@ -503,7 +503,7 @@ void CmdOnAnimationTriggerServerMessage(int hash)
RpcOnAnimationTriggerClientMessage(hash);
}

[Command]
[ServerRpc]
void CmdOnAnimationResetTriggerServerMessage(int hash)
{
// Ignore messages from client if not in client authority mode
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Components/NetworkTransformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public override void OnDeserialize(NetworkReader reader, bool initialState)
}

// local authority client sends sync message to server for broadcasting
[Command]
[ServerRpc]
void CmdClientToServerSync(byte[] payload)
{
// Ignore messages from client if not in client authority mode
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Editor/Weaver/Processors/MethodProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void FixRemoteCallToBaseMethod(TypeDefinition type, MethodDefiniti
{
string callName = method.Name;

// all Commands/Rpc start with "UserCode_"
// all ServerRpcs/Rpc start with "UserCode_"
// eg CallCmdDoSomething
if (!callName.StartsWith(UserCodePrefix))
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ static void ProcessSyncVars(TypeDefinition td)

static void ProcessMethods(TypeDefinition td)
{
// find command and RPC functions
// find ServerRpc and RPC functions
foreach (MethodDefinition md in td.Methods)
{
foreach (CustomAttribute ca in md.CustomAttributes)
{
if (ca.AttributeType.FullName == Weaver.CommandType.FullName)
if (ca.AttributeType.FullName == Weaver.ServerRpcType.FullName)
{
Weaver.Error($"Command {md.Name} must be declared inside a NetworkBehaviour", md);
Weaver.Error($"ServerRpc {md.Name} must be declared inside a NetworkBehaviour", md);
}

if (ca.AttributeType.FullName == Weaver.ClientRpcType.FullName)
Expand Down
52 changes: 26 additions & 26 deletions Assets/Mirror/Editor/Weaver/Processors/NetworkBehaviourProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Mirror.Weaver
{
public enum RemoteCallType
{
Command,
ServerRpc,
ClientRpc,
TargetRpc,
SyncEvent
Expand All @@ -22,11 +22,11 @@ class NetworkBehaviourProcessor
readonly List<FieldDefinition> syncObjects = new List<FieldDefinition>();
// <SyncVarField,NetIdField>
readonly Dictionary<FieldDefinition, FieldDefinition> syncVarNetIds = new Dictionary<FieldDefinition, FieldDefinition>();
readonly List<CmdResult> commands = new List<CmdResult>();
readonly List<CmdResult> serverRpcs = new List<CmdResult>();
readonly List<ClientRpcResult> clientRpcs = new List<ClientRpcResult>();
readonly List<MethodDefinition> targetRpcs = new List<MethodDefinition>();
readonly List<EventDefinition> eventRpcs = new List<EventDefinition>();
readonly List<MethodDefinition> commandSkeletonFuncs = new List<MethodDefinition>();
readonly List<MethodDefinition> serverRpcSkeletonFuncs = new List<MethodDefinition>();
readonly List<MethodDefinition> clientRpcSkeletonFuncs = new List<MethodDefinition>();
readonly List<MethodDefinition> targetRpcSkeletonFuncs = new List<MethodDefinition>();
readonly List<MethodDefinition> eventRpcInvocationFuncs = new List<MethodDefinition>();
Expand Down Expand Up @@ -84,7 +84,7 @@ public void Process()
/*
generates code like:
if (!obj.netIdentity.client.active)
Debug.LogError((object) "Command function CmdRespawn called on server.");
Debug.LogError((object) "ServerRpc function CmdRespawn called on server.");
which is used in InvokeCmd, InvokeRpc, etc.
*/
Expand All @@ -105,7 +105,7 @@ public static void WriteClientActiveCheck(ILProcessor worker, string mdName, Ins
/*
generates code like:
if (!obj.netIdentity.server.active)
Debug.LogError((object) "Command CmdMsgWhisper called on client.");
Debug.LogError((object) "ServerRpc CmdMsgWhisper called on client.");
*/
public static void WriteServerActiveCheck(ILProcessor worker, string mdName, Instruction label, string errString)
{
Expand Down Expand Up @@ -165,7 +165,7 @@ public static bool WriteArguments(ILProcessor worker, MethodDefinition method, R
argNum += 1;
continue;
}
// skip SenderConnection in Command
// skip SenderConnection in ServerRpc
if (IsNetworkConnection(param.ParameterType))
{
argNum += 1;
Expand Down Expand Up @@ -214,7 +214,7 @@ public static void MarkAsProcessed(TypeDefinition td)

void GenerateConstants()
{
if (commands.Count == 0 && clientRpcs.Count == 0 && targetRpcs.Count == 0 && eventRpcs.Count == 0 && syncObjects.Count == 0)
if (serverRpcs.Count == 0 && clientRpcs.Count == 0 && targetRpcs.Count == 0 && eventRpcs.Count == 0 && syncObjects.Count == 0)
return;

Weaver.DLog(netBehaviourSubclass, " GenerateConstants ");
Expand Down Expand Up @@ -274,10 +274,10 @@ void GenerateConstants()
ILProcessor ctorWorker = ctor.Body.GetILProcessor();
ILProcessor cctorWorker = cctor.Body.GetILProcessor();

for (int i = 0; i < commands.Count; ++i)
for (int i = 0; i < serverRpcs.Count; ++i)
{
CmdResult cmdResult = commands[i];
GenerateRegisterCommandDelegate(cctorWorker, Weaver.registerCommandDelegateReference, commandSkeletonFuncs[i], cmdResult);
CmdResult cmdResult = serverRpcs[i];
GenerateRegisterServerRpcDelegate(cctorWorker, Weaver.registerServerRpcDelegateReference, serverRpcSkeletonFuncs[i], cmdResult);
}

for (int i = 0; i < clientRpcs.Count; ++i)
Expand Down Expand Up @@ -316,7 +316,7 @@ void GenerateConstants()

/*
// This generates code like:
NetworkBehaviour.RegisterCommandDelegate(base.GetType(), "CmdThrust", new NetworkBehaviour.CmdDelegate(ShipControl.InvokeCmdCmdThrust));
NetworkBehaviour.RegisterServerRpcDelegate(base.GetType(), "CmdThrust", new NetworkBehaviour.CmdDelegate(ShipControl.InvokeCmdCmdThrust));
*/
void GenerateRegisterRemoteDelegate(ILProcessor worker, MethodReference registerMethod, MethodDefinition func, string cmdName)
{
Expand All @@ -331,7 +331,7 @@ void GenerateRegisterRemoteDelegate(ILProcessor worker, MethodReference register
worker.Append(worker.Create(OpCodes.Call, registerMethod));
}

void GenerateRegisterCommandDelegate(ILProcessor worker, MethodReference registerMethod, MethodDefinition func, CmdResult cmdResult)
void GenerateRegisterServerRpcDelegate(ILProcessor worker, MethodReference registerMethod, MethodDefinition func, CmdResult cmdResult)
{
string cmdName = cmdResult.method.Name;
bool requireAuthority = cmdResult.requireAuthority;
Expand Down Expand Up @@ -808,7 +808,7 @@ public static bool ReadArguments(MethodDefinition method, ILProcessor worker, Re
argNum += 1;
continue;
}
// skip SenderConnection in Command
// skip SenderConnection in ServerRpc
if (IsNetworkConnection(param.ParameterType))
{
argNum += 1;
Expand Down Expand Up @@ -844,7 +844,7 @@ public static void AddInvokeParameters(ICollection<ParameterDefinition> collecti
{
collection.Add(new ParameterDefinition("obj", ParameterAttributes.None, Weaver.CurrentAssembly.MainModule.ImportReference(Weaver.NetworkBehaviourType)));
collection.Add(new ParameterDefinition("reader", ParameterAttributes.None, Weaver.CurrentAssembly.MainModule.ImportReference(Weaver.NetworkReaderType)));
// senderConnection is only used for commands but NetworkBehaviour.CmdDelegate is used for all remote calls
// senderConnection is only used for ServerRpcs but NetworkBehaviour.CmdDelegate is used for all remote calls
collection.Add(new ParameterDefinition("senderConnection", ParameterAttributes.None, Weaver.CurrentAssembly.MainModule.ImportReference(Weaver.INetworkConnectionType)));
}

Expand Down Expand Up @@ -900,7 +900,7 @@ static bool ValidateParameter(MethodReference method, ParameterDefinition param,
return true;
}

if (callType == RemoteCallType.Command)
if (callType == RemoteCallType.ServerRpc)
{
return true;
}
Expand Down Expand Up @@ -929,14 +929,14 @@ void ProcessMethods()

// copy the list of methods because we will be adding methods in the loop
var methods = new List<MethodDefinition>(netBehaviourSubclass.Methods);
// find command and RPC functions
// find ServerRpc and RPC functions
foreach (MethodDefinition md in methods)
{
foreach (CustomAttribute ca in md.CustomAttributes)
{
if (ca.AttributeType.FullName == Weaver.CommandType.FullName)
if (ca.AttributeType.FullName == Weaver.ServerRpcType.FullName)
{
ProcessCommand(names, md, ca);
ProcessServerRpc(names, md, ca);
break;
}

Expand Down Expand Up @@ -1008,32 +1008,32 @@ void ProcessTargetRpc(HashSet<string> names, MethodDefinition md, CustomAttribut
}
}

void ProcessCommand(HashSet<string> names, MethodDefinition md, CustomAttribute commandAttr)
void ProcessServerRpc(HashSet<string> names, MethodDefinition md, CustomAttribute serverRpcAttr)
{
if (!CommandProcessor.Validate(md))
if (!ServerRpcProcessor.Validate(md))
return;

if (names.Contains(md.Name))
{
Weaver.Error($"Duplicate Command name {md.Name}", md);
Weaver.Error($"Duplicate ServerRpc name {md.Name}", md);
return;
}

bool requireAuthority = commandAttr.GetField("requireAuthority", false);
bool requireAuthority = serverRpcAttr.GetField("requireAuthority", false);

names.Add(md.Name);
commands.Add(new CmdResult
serverRpcs.Add(new CmdResult
{
method = md,
requireAuthority = requireAuthority
});

MethodDefinition userCodeFunc = CommandProcessor.GenerateStub(md, commandAttr);
MethodDefinition userCodeFunc = ServerRpcProcessor.GenerateStub(md, serverRpcAttr);

MethodDefinition skeletonFunc = CommandProcessor.GenerateSkeleton(md, userCodeFunc);
MethodDefinition skeletonFunc = ServerRpcProcessor.GenerateSkeleton(md, userCodeFunc);
if (skeletonFunc != null)
{
commandSkeletonFuncs.Add(skeletonFunc);
serverRpcSkeletonFuncs.Add(skeletonFunc);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirror/Editor/Weaver/Processors/RpcProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static MethodDefinition GenerateSkeleton(MethodDefinition md, MethodDefin
if (!NetworkBehaviourProcessor.ReadArguments(md, worker, RemoteCallType.ClientRpc))
return null;

// invoke actual command function
// invoke actual ServerRpc function
worker.Append(worker.Create(OpCodes.Callvirt, userCodeFunc));
worker.Append(worker.Create(OpCodes.Ret));

Expand All @@ -61,7 +61,7 @@ public static MethodDefinition GenerateSkeleton(MethodDefinition md, MethodDefin
/// </summary>
/// <param name="td">The class containing the method </param>
/// <param name="md">The method to be stubbed </param>
/// <param name="commandAttr">The attribute that made this an RPC</param>
/// <param name="ServerRpcAttr">The attribute that made this an RPC</param>
/// <returns>The method containing the original code</returns>
/// <remarks>
/// Generates code like this:
Expand Down

0 comments on commit fff7459

Please sign in to comment.