mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-19 15:51:54 +00:00
RpcLocalHandling
This commit is contained in:
3 files changed
+19
-7
No files matched your search
@@ -19,7 +19,7 @@ namespace Reactor.Example
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ShouldHandleLocally => true;
|
||||
public override RpcLocalHandling LocalHandling => RpcLocalHandling.Before;
|
||||
|
||||
public override void Write(MessageWriter writer, Data data)
|
||||
{
|
||||
|
||||
+15
-3
@@ -9,6 +9,13 @@ using Hazel;
|
||||
|
||||
namespace Reactor
|
||||
{
|
||||
public enum RpcLocalHandling
|
||||
{
|
||||
None,
|
||||
Before,
|
||||
After
|
||||
}
|
||||
|
||||
public abstract class UnsafeCustomRpc
|
||||
{
|
||||
public int? Id { get; internal set; }
|
||||
@@ -18,7 +25,7 @@ namespace Reactor
|
||||
|
||||
public abstract Type InnerNetObjectType { get; }
|
||||
|
||||
public abstract bool ShouldHandleLocally { get; }
|
||||
public abstract RpcLocalHandling LocalHandling { get; }
|
||||
|
||||
protected UnsafeCustomRpc(BasePlugin plugin)
|
||||
{
|
||||
@@ -106,7 +113,7 @@ namespace Reactor
|
||||
throw new InvalidOperationException("Can't send unregistered CustomRpc");
|
||||
}
|
||||
|
||||
if (customRpc.ShouldHandleLocally)
|
||||
if (customRpc.LocalHandling == RpcLocalHandling.Before)
|
||||
{
|
||||
customRpc.UnsafeHandle(netObject, data);
|
||||
}
|
||||
@@ -118,7 +125,7 @@ namespace Reactor
|
||||
};
|
||||
|
||||
writer.Write(customRpc.PluginId);
|
||||
writer.Write(customRpc.Id.Value);
|
||||
writer.Write(customRpc.Id!.Value);
|
||||
customRpc.UnsafeWrite(writer, data);
|
||||
|
||||
if (immediately)
|
||||
@@ -129,6 +136,11 @@ namespace Reactor
|
||||
{
|
||||
writer.EndMessage();
|
||||
}
|
||||
|
||||
if (customRpc.LocalHandling == RpcLocalHandling.After)
|
||||
{
|
||||
customRpc.UnsafeHandle(netObject, data);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
|
||||
@@ -64,10 +64,10 @@ namespace Reactor.Patches
|
||||
|
||||
handshake.WritePacked(plugins.Count);
|
||||
|
||||
foreach (var plugin in plugins)
|
||||
foreach (var (pluginId, plugin) in plugins)
|
||||
{
|
||||
handshake.Write(plugin.Key);
|
||||
handshake.Write(plugin.Value.Metadata.Version.ToString());
|
||||
handshake.Write(pluginId);
|
||||
handshake.Write(plugin.Metadata.Version.ToString());
|
||||
}
|
||||
|
||||
__result = handshake.ToByteArray(false);
|
||||
|
||||
Reference in new issue
Block a user