Пример #1
0
        /// <summary>
        /// invoke a remote precedure call.
        /// </summary>
        /// <param name="rpcMethodName">method name</param>
        /// <param name="targets"> <see cref="PlayRPCTargets"/>.</param>
        /// <param name="rpcParameters"></param>
        public static void RPC(string rpcMethodName, PlayRPCTargets targets, params object[] rpcParameters)
        {
            var rpcMessage = new PlayRpcMessage();

            rpcMessage.MethodName = rpcMethodName;
            rpcMessage.Paramters  = rpcParameters;

            if (targets.IsIn(PlayRPCTargets.All, PlayRPCTargets.AllBuffered))
            {
                rpcMessage.Echo = true;
            }

            if (targets.IsIn(PlayRPCTargets.OthersBuffered, PlayRPCTargets.AllBuffered))
            {
                rpcMessage.Cached = true;
            }

            if (targets.IsIn(PlayRPCTargets.MasterClient))
            {
                rpcMessage.ToPeers = new List <string>()
                {
                    Room.MasterClientId,
                };
                if (Play.Player.UserID == Play.Room.MasterClientId)
                {
                    rpcMessage.Echo = true;
                }
            }

            Play.ExecuteRPC(rpcMessage);
        }
Пример #2
0
        /// <summary>
        /// call
        /// </summary>
        /// <param name="rpcMethodName"></param>
        /// <param name="userIds"></param>
        /// <param name="rpcParameters"></param>
        public static void RPC(string rpcMethodName, IEnumerable <string> userIds, params object[] rpcParameters)
        {
            var rpcMessage = new PlayRpcMessage();

            rpcMessage.MethodName = rpcMethodName;
            rpcMessage.Paramters  = rpcParameters;
            rpcMessage.ToPeers    = new List <string>(userIds);
            Play.ExecuteRPC(rpcMessage);
        }
Пример #3
0
        internal static void ExecuteRPC(PlayRpcMessage rpcMessage)
        {
            var rpcCommand = new PlayCommand();

            rpcCommand.Body              = new Dictionary <string, object>();
            rpcCommand.Body["cmd"]       = "direct";
            rpcCommand.Body["cid"]       = Room.Name;
            rpcCommand.Body["msg"]       = rpcMessage.Serialize();
            rpcCommand.Body["echo"]      = rpcMessage.Echo;
            rpcCommand.Body["cached"]    = rpcMessage.Cached;
            rpcCommand.Body["toPeerIds"] = rpcMessage.ToPeers;
            Play.RunSocketCommand(rpcCommand);
        }
Пример #4
0
        internal static void ReceivedRPC(PlayRpcMessage rpcMessage)
        {
            //EventNotification.NotifyUnityGameObjects(rpcMessage.MethodName, rpcMessage.Paramters.ToArray());
            var playRpcEventMessage = new PlayRPCEventMessage()
            {
                rpcMessage = rpcMessage
            };

#if UNITY
            EnqueueEventMessage(playRpcEventMessage);
#else
            var pt = rpcMessage.Paramters.Select(p => p.GetType()).ToArray();

            var rpcMethods = from behaviour in Play.Behaviours
                             let method = Play.Find(behaviour, rpcMessage.MethodName, pt)
                                          where method != null
                                          select new
            {
                host   = behaviour,
                method = method
            };
            rpcMethods.Every(hm => hm.method.Invoke(hm.host, parameters: rpcMessage.Paramters.ToArray()));
#endif
        }
Пример #5
0
        public void OnNoticeReceived(AVIMNotice notice)
        {
            var rpcMessage = new PlayRpcMessage(notice);

            Play.ReceivedRPC(rpcMessage);
        }