diff --git a/Reactor.Example/ExamplePlugin.cs b/Reactor.Example/ExamplePlugin.cs index 1408598..3959961 100644 --- a/Reactor.Example/ExamplePlugin.cs +++ b/Reactor.Example/ExamplePlugin.cs @@ -35,10 +35,11 @@ namespace Reactor.Example private void Update() { - if (Input.GetKeyDown(KeyCode.F3)) + if (Input.GetKeyDown(KeyCode.F3) && AmongUsClient.Instance && PlayerControl.LocalPlayer) { Plugin.Log.LogWarning("Sending example rpc"); PlayerControl.LocalPlayer.Send(new ExampleRpc.Data("Cześć :)")); + PlayerControl.LocalPlayer.SendTo(AmongUsClient.Instance.HostId, new ExampleRpc.Data("host :O")); } } } diff --git a/Reactor.Example/ExampleRpc.cs b/Reactor.Example/ExampleRpc.cs index 027d8f9..178bbd6 100644 --- a/Reactor.Example/ExampleRpc.cs +++ b/Reactor.Example/ExampleRpc.cs @@ -19,7 +19,7 @@ namespace Reactor.Example } } - public override RpcLocalHandling LocalHandling => RpcLocalHandling.Before; + public override RpcLocalHandling LocalHandling => RpcLocalHandling.None; public override void Write(MessageWriter writer, Data data) { diff --git a/Reactor/CustomRpc.cs b/Reactor/CustomRpc.cs index 4958561..7a27694 100644 --- a/Reactor/CustomRpc.cs +++ b/Reactor/CustomRpc.cs @@ -126,7 +126,12 @@ namespace Reactor UnsafeSend(netObject, List.Single(x => x.GetType() == typeof(TCustomRpc)), data, immediately); } - public void UnsafeSend(InnerNetObject netObject, UnsafeCustomRpc customRpc, object data, bool immediately = false) + public void SendTo(InnerNetObject netObject, int targetId, object data) + { + UnsafeSend(netObject, List.Single(x => x.GetType() == typeof(TCustomRpc)), data, true, targetId); + } + + public void UnsafeSend(InnerNetObject netObject, UnsafeCustomRpc customRpc, object data, bool immediately = false, int targetClientId = -1) { if (netObject == null) throw new ArgumentNullException(nameof(netObject)); if (customRpc == null) throw new ArgumentNullException(nameof(customRpc)); @@ -145,7 +150,7 @@ namespace Reactor var writer = immediately switch { false => AmongUsClient.Instance.StartRpc(netObject.NetId, CallId, SendOption.Reliable), - true => AmongUsClient.Instance.StartRpcImmediately(netObject.NetId, CallId, SendOption.Reliable, -1) + true => AmongUsClient.Instance.StartRpcImmediately(netObject.NetId, CallId, SendOption.Reliable, targetClientId) }; if (PluginIdMap.TryGetValue(customRpc.PluginId, out var pluginId)) diff --git a/Reactor/Extensions/Extensions.cs b/Reactor/Extensions/Extensions.cs index 2011fed..d2ccdff 100644 --- a/Reactor/Extensions/Extensions.cs +++ b/Reactor/Extensions/Extensions.cs @@ -134,5 +134,10 @@ namespace Reactor.Extensions { PluginSingleton.Instance.CustomRpcManager.Send(netObject, data, immediately); } + + public static void SendTo(this InnerNetObject netObject, int targetId, object data) + { + PluginSingleton.Instance.CustomRpcManager.SendTo(netObject, targetId, data); + } } }