Skip to content

feat: make ServerRpc ownership check an error log instead of warning log #1126

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

Merged
merged 1 commit into from
Sep 1, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
return new ILPostProcessResult(new InMemoryAssembly(pe.ToArray(), pdb.ToArray()), m_Diagnostics);
}

private MethodReference m_Debug_LogWarning_MethodRef;
private MethodReference m_Debug_LogError_MethodRef;
private TypeReference m_NetworkManager_TypeRef;
private MethodReference m_NetworkManager_getLocalClientId_MethodRef;
private MethodReference m_NetworkManager_getIsListening_MethodRef;
Expand Down Expand Up @@ -150,7 +150,7 @@ public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
private MethodReference m_NetworkSerializer_SerializeRayArray_MethodRef;
private MethodReference m_NetworkSerializer_SerializeRay2DArray_MethodRef;

private const string k_Debug_LogWarning = nameof(Debug.LogWarning);
private const string k_Debug_LogError = nameof(Debug.LogError);
private const string k_NetworkManager_LocalClientId = nameof(NetworkManager.LocalClientId);
private const string k_NetworkManager_IsListening = nameof(NetworkManager.IsListening);
private const string k_NetworkManager_IsHost = nameof(NetworkManager.IsHost);
Expand Down Expand Up @@ -182,10 +182,10 @@ private bool ImportReferences(ModuleDefinition moduleDefinition)
{
switch (methodInfo.Name)
{
case k_Debug_LogWarning:
case k_Debug_LogError:
if (methodInfo.GetParameters().Length == 1)
{
m_Debug_LogWarning_MethodRef = moduleDefinition.ImportReference(methodInfo);
m_Debug_LogError_MethodRef = moduleDefinition.ImportReference(methodInfo);
}

break;
Expand Down Expand Up @@ -830,9 +830,9 @@ private void InjectWriteAndCallBlocks(MethodDefinition methodDefinition, CustomA
instructions.Add(processor.Create(OpCodes.Ceq));
instructions.Add(processor.Create(OpCodes.Brfalse, logNextInstr));

// Debug.LogWarning(...);
// Debug.LogError(...);
instructions.Add(processor.Create(OpCodes.Ldstr, "Only the owner can invoke a ServerRpc that requires ownership!"));
instructions.Add(processor.Create(OpCodes.Call, m_Debug_LogWarning_MethodRef));
instructions.Add(processor.Create(OpCodes.Call, m_Debug_LogError_MethodRef));

instructions.Add(logNextInstr);

Expand Down Expand Up @@ -1827,9 +1827,9 @@ private MethodDefinition GenerateStaticHandler(MethodDefinition methodDefinition
processor.Emit(OpCodes.Ceq);
processor.Emit(OpCodes.Brfalse, logNextInstr);

// Debug.LogWarning(...);
// Debug.LogError(...);
processor.Emit(OpCodes.Ldstr, "Only the owner can invoke a ServerRpc that requires ownership!");
processor.Emit(OpCodes.Call, m_Debug_LogWarning_MethodRef);
processor.Emit(OpCodes.Call, m_Debug_LogError_MethodRef);

processor.Append(logNextInstr);

Expand Down