Skip to content

fix: Disallowed async keyword in RPCs #1587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
- Fixed error when serializing ConnectionApprovalMessage with scene management disabled when one or more objects is hidden via the CheckObjectVisibility delegate (#1509)
- Fixed The NetworkConfig's checksum hash includes the NetworkTick so that clients with a different tickrate than the server are identified and not allowed to connect. (#1513)
- Fixed OwnedObjects not being properly modified when using ChangeOwnership. (#1572)
- Disallowed async keyword in RPCs (1587)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
- Disallowed async keyword in RPCs (1587)
- Disallowed async keyword in RPCs (#1587)


### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,17 @@ private void ProcessNetworkBehaviour(TypeDefinition typeDefinition, string[] ass
continue;
}

if (methodDefinition.HasCustomAttributes)
{
foreach (var attribute in methodDefinition.CustomAttributes)
{
if (attribute.AttributeType.Name == nameof(AsyncStateMachineAttribute))
{
m_Diagnostics.AddError(methodDefinition, $"{methodDefinition.FullName}: RPCs cannot be 'async'");
}
}
}

InjectWriteAndCallBlocks(methodDefinition, rpcAttribute, rpcMethodId);

rpcHandlers.Add((rpcMethodId, GenerateStaticHandler(methodDefinition, rpcAttribute)));
Expand Down Expand Up @@ -937,14 +948,14 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA
if (paramType.FullName == CodeGenHelpers.ClientRpcSendParams_FullName ||
paramType.FullName == CodeGenHelpers.ClientRpcReceiveParams_FullName)
{
m_Diagnostics.AddError($"Rpcs may not accept {paramType.FullName} as a parameter. Use {nameof(ClientRpcParams)} instead.");
m_Diagnostics.AddError(methodDefinition, $"Rpcs may not accept {paramType.FullName} as a parameter. Use {nameof(ClientRpcParams)} instead.");
continue;
}

if (paramType.FullName == CodeGenHelpers.ServerRpcSendParams_FullName ||
paramType.FullName == CodeGenHelpers.ServerRpcReceiveParams_FullName)
{
m_Diagnostics.AddError($"Rpcs may not accept {paramType.FullName} as a parameter. Use {nameof(ServerRpcParams)} instead.");
m_Diagnostics.AddError(methodDefinition, $"Rpcs may not accept {paramType.FullName} as a parameter. Use {nameof(ServerRpcParams)} instead.");
continue;
}
// ServerRpcParams
Expand All @@ -956,7 +967,7 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA
}
if (!isServerRpc)
{
m_Diagnostics.AddError($"ClientRpcs may not accept {nameof(ServerRpcParams)} as a parameter.");
m_Diagnostics.AddError(methodDefinition, $"ClientRpcs may not accept {nameof(ServerRpcParams)} as a parameter.");
}
continue;
}
Expand All @@ -969,7 +980,7 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA
}
if (isServerRpc)
{
m_Diagnostics.AddError($"ServerRpcs may not accept {nameof(ClientRpcParams)} as a parameter.");
m_Diagnostics.AddError(methodDefinition, $"ServerRpcs may not accept {nameof(ClientRpcParams)} as a parameter.");
}
continue;
}
Expand Down