Skip to content

Commit

Permalink
fix: fixing RPC with multiple components
Browse files Browse the repository at this point in the history
fix for recent change to RPC collection on Identity
  • Loading branch information
James-Frowen committed Jun 12, 2023
1 parent 29c0b92 commit 2ae9ddc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Assets/Mirage/Runtime/RemoteCalls/ClientRpcSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ public static class ClientRpcSender
{
private static readonly ILogger logger = LogFactory.GetLogger(typeof(ClientRpcSender));

public static void Send(NetworkBehaviour behaviour, int index, NetworkWriter writer, Channel channelId, bool excludeOwner)
public static void Send(NetworkBehaviour behaviour, int relativeIndex, NetworkWriter writer, Channel channelId, bool excludeOwner)
{
var index = behaviour.Identity.RemoteCallCollection.GetIndexOffset(behaviour) + relativeIndex;
var message = CreateMessage(behaviour, index, writer);

// The public facing parameter is excludeOwner in [ClientRpc]
Expand All @@ -21,8 +22,9 @@ public static void Send(NetworkBehaviour behaviour, int index, NetworkWriter wri
behaviour.Identity.SendToRemoteObservers(message, includeOwner, channelId);
}

public static void SendTarget(NetworkBehaviour behaviour, int index, NetworkWriter writer, Channel channelId, INetworkPlayer player)
public static void SendTarget(NetworkBehaviour behaviour, int relativeIndex, NetworkWriter writer, Channel channelId, INetworkPlayer player)
{
var index = behaviour.Identity.RemoteCallCollection.GetIndexOffset(behaviour) + relativeIndex;
var message = CreateMessage(behaviour, index, writer);

// player parameter is optional. use owner if null
Expand Down
4 changes: 4 additions & 0 deletions Assets/Mirage/Runtime/RemoteCalls/RemoteCallHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.CompilerServices;
using Cysharp.Threading.Tasks;
using Mirage.Logging;
using Mirage.Serialization;
Expand Down Expand Up @@ -83,16 +84,19 @@ void CmdWrapper(NetworkBehaviour obj, NetworkReader reader, INetworkPlayer sende
Register(index, name, cmdRequireAuthority, RpcInvokeType.ServerRpc, behaviour, CmdWrapper);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int GetIndexOffset(NetworkBehaviour behaviour)
{
return IndexOffset[behaviour.ComponentIndex];
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public RemoteCall GetRelative(NetworkBehaviour behaviour, int index)
{
return RemoteCalls[GetIndexOffset(behaviour) + index];
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public RemoteCall GetAbsolute(int index)
{
return RemoteCalls[index];
Expand Down
6 changes: 4 additions & 2 deletions Assets/Mirage/Runtime/RemoteCalls/ServerRpcSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ namespace Mirage.RemoteCalls
/// </summary>
public static class ServerRpcSender
{
public static void Send(NetworkBehaviour behaviour, int index, NetworkWriter writer, Channel channelId, bool requireAuthority)
public static void Send(NetworkBehaviour behaviour, int relativeIndex, NetworkWriter writer, Channel channelId, bool requireAuthority)
{
var index = behaviour.Identity.RemoteCallCollection.GetIndexOffset(behaviour) + relativeIndex;
Validate(behaviour, index, requireAuthority);

var message = new ServerRpcMessage
Expand All @@ -23,8 +24,9 @@ public static void Send(NetworkBehaviour behaviour, int index, NetworkWriter wri
behaviour.Client.Send(message, channelId);
}

public static UniTask<T> SendWithReturn<T>(NetworkBehaviour behaviour, int index, NetworkWriter writer, Channel channelId, bool requireAuthority)
public static UniTask<T> SendWithReturn<T>(NetworkBehaviour behaviour, int relativeIndex, NetworkWriter writer, Channel channelId, bool requireAuthority)
{
var index = behaviour.Identity.RemoteCallCollection.GetIndexOffset(behaviour) + relativeIndex;
Validate(behaviour, index, requireAuthority);
var message = new ServerRpcWithReplyMessage
{
Expand Down

0 comments on commit 2ae9ddc

Please sign in to comment.