/// <summary> /// Subscribe to an rpc /// </summary> /// <param name="rpcID">id of the rpc</param> /// <param name="rpcProcessor">action to process the rpc with</param> /// <param name="overwriteExisting">overwrite the existing processor if one exists.</param> /// <param name="defaultContinueForwarding">default value for info.continueForwarding</param> /// <returns>Whether or not the rpc was subscribed to. Will return false if an existing rpc was attempted to be subscribed to, and overwriteexisting was set to false</returns> public bool SubscribeToRpc(byte rpcID, Action <NetMessage, NetMessageInfo> rpcProcessor, bool overwriteExisting = true, bool defaultContinueForwarding = true) { if (rpcProcessor == null) { throw new ArgumentNullException("rpcProcessor", "the processor delegate cannot be null"); } if (overwriteExisting) { _rpcProcessors[rpcID] = new RpcProcessor(rpcProcessor, defaultContinueForwarding); return(true); } if (_rpcProcessors.ContainsKey(rpcID)) { return(false); } _rpcProcessors.Add(rpcID, new RpcProcessor(rpcProcessor, defaultContinueForwarding)); return(true); }
/// <summary> /// subscribe a function to an rpc id. The return value of func will be sent back to the client, into the rpc that called it with RpcContinueWith /// </summary> /// <param name="componentId"></param> /// <param name="rpcId"></param> /// <param name="func"></param> /// <param name="overwriteExisting"></param> /// <returns></returns> public bool SubscribeToFunc(byte componentId, byte rpcId, Func <NetMessage, NetMessageInfo, object> func, bool overwriteExisting = true) { if (func == null) { throw new ArgumentNullException("func", "the function delegate cannot be null"); } var id = (componentId << 8) | rpcId; if (overwriteExisting) { _rpcProcessors[id] = new RpcProcessor(func, false); return(true); } if (_rpcProcessors.ContainsKey(id)) { return(false); } _rpcProcessors.Add(id, new RpcProcessor(func, false)); return(true); }