public MethodInfo GetRPC(int id) { if (!RPCs.ContainsKey(id)) { return(null); } return(RPCs[id].Key); }
/// <summary> /// To Invoke an RPC on a given Networking Stream RPC /// </summary> /// <param name="stream">Networking Stream RPC to read from</param> public bool InvokeRPC(NetworkingStreamRPC stream) { lock (rpcStackMutex) { tmpRPCMapId = ObjectMapper.Map <int>(stream); if (!RPCs.ContainsKey(tmpRPCMapId)) { return(true); } stream.SetName(RPCs[tmpRPCMapId].Key.Name); List <object> args = new List <object>(); MethodInfo invoke = null; List <IBRPCIntercept> attributes = null; foreach (KeyValuePair <int, KeyValuePair <MethodInfo, List <IBRPCIntercept> > > m in RPCs) { if (m.Value.Key.Name == stream.MethodName) { invoke = m.Value.Key; attributes = m.Value.Value; break; } } int start = stream.Bytes.StartIndex(stream.ByteReadIndex); ParameterInfo[] pars = invoke.GetParameters(); foreach (ParameterInfo p in pars) { if (p.ParameterType == typeof(MessageInfo)) { args.Add(new MessageInfo(stream.RealSenderId, stream.FrameIndex)); } else { args.Add(ObjectMapper.Map(p.ParameterType, stream)); } } stream.SetArguments(args.ToArray()); if (ReferenceEquals(this, NetworkingManager.Instance)) { if (OwningNetWorker.IsServer) { if (stream.MethodName == NetworkingStreamRPC.INSTANTIATE_METHOD_NAME) { stream.Arguments[1] = stream.SetupInstantiateId(stream, start); } else if (stream.MethodName == NetworkingStreamRPC.DESTROY_METHOD_NAME) { if (OwningNetWorker.ClearBufferedInstantiateFromID((ulong)args[0])) { // Set flag if method removed instantiate IsClearedForBuffer = !stream.BufferedRPC; } } } } foreach (IBRPCIntercept interceptor in attributes) { if (!interceptor.ValidateRPC(stream)) { return(false); } } rpcStack.Add(stream); return(true); } }