public IDisposable Register(IReactorCustomRpc customRpc)
        {
            if (Rpcs.Any(x => x.ModId == customRpc.ModId && x.Id == customRpc.Id))
            {
                throw new ImpostorException("Custom rpc with that id and mod id was already registered");
            }

            Rpcs.Add(customRpc);
            return(new UnregisterDisposable(this, customRpc));
        }
示例#2
0
        public static ValueTask SendReactorRpcAsync(this IInnerNetObject innerNetObject, IClient target, IReactorCustomRpc customRpc, IMessageWriter data, int?targetClientId = null)
        {
            var clientInfo = target.GetReactor();

            if (clientInfo == null)
            {
                throw new ArgumentException("Tried to send reactor rpc to vanilla client");
            }

            var targetMod = clientInfo.Mods.Single(x => x.Id == customRpc.ModId);

            using var writer = innerNetObject.Game.StartRpc(innerNetObject.NetId, (RpcCalls) 255, targetClientId);

            writer.WritePacked(targetMod.NetId);
            writer.WritePacked(customRpc.Id);

            writer.StartMessage(0);
            writer.Write(data.ToByteArray(false));
            writer.EndMessage();

            writer.EndMessage();
            writer.EndMessage();

            return(target.Connection !.SendAsync(writer));
        }
 public UnregisterDisposable(ReactorCustomRpcManager manager, IReactorCustomRpc rpc)
 {
     _manager = manager;
     _rpc     = rpc;
 }