CustomRpc SendTo

This commit is contained in:
js6pak committed 2021-01-22 11:03:14 +01:00
1 parent 58b28d8e9c
commit 3299ffc071
4 files changed
+15 -4

No files matched your search

+2 -1
View File
@@ -35,10 +35,11 @@ namespace Reactor.Example
private void Update() private void Update()
{ {
if (Input.GetKeyDown(KeyCode.F3)) if (Input.GetKeyDown(KeyCode.F3) && AmongUsClient.Instance && PlayerControl.LocalPlayer)
{ {
Plugin.Log.LogWarning("Sending example rpc"); Plugin.Log.LogWarning("Sending example rpc");
PlayerControl.LocalPlayer.Send<ExampleRpc>(new ExampleRpc.Data("Cześć :)")); PlayerControl.LocalPlayer.Send<ExampleRpc>(new ExampleRpc.Data("Cześć :)"));
PlayerControl.LocalPlayer.SendTo<ExampleRpc>(AmongUsClient.Instance.HostId, new ExampleRpc.Data("host :O"));
} }
} }
} }
+1 -1
View File
@@ -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) public override void Write(MessageWriter writer, Data data)
{ {
+7 -2
View File
@@ -126,7 +126,12 @@ namespace Reactor
UnsafeSend(netObject, List.Single(x => x.GetType() == typeof(TCustomRpc)), data, immediately); 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<TCustomRpc>(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 (netObject == null) throw new ArgumentNullException(nameof(netObject));
if (customRpc == null) throw new ArgumentNullException(nameof(customRpc)); if (customRpc == null) throw new ArgumentNullException(nameof(customRpc));
@@ -145,7 +150,7 @@ namespace Reactor
var writer = immediately switch var writer = immediately switch
{ {
false => AmongUsClient.Instance.StartRpc(netObject.NetId, CallId, SendOption.Reliable), 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)) if (PluginIdMap.TryGetValue(customRpc.PluginId, out var pluginId))
+5
View File
@@ -134,5 +134,10 @@ namespace Reactor.Extensions
{ {
PluginSingleton<ReactorPlugin>.Instance.CustomRpcManager.Send<TCustomRpc>(netObject, data, immediately); PluginSingleton<ReactorPlugin>.Instance.CustomRpcManager.Send<TCustomRpc>(netObject, data, immediately);
} }
public static void SendTo<TCustomRpc>(this InnerNetObject netObject, int targetId, object data)
{
PluginSingleton<ReactorPlugin>.Instance.CustomRpcManager.SendTo<TCustomRpc>(netObject, targetId, data);
}
} }
} }