Esempio n. 1
0
        public void Disconnect(RPCUserInfo e)
        {
            foreach (var item in e.RPC_Call.ModuleDiy.Values)
            {
                Type type = item.GetType();

                if (type.BaseType == typeof(RPCObject))
                {
                    type.GetMethod("ClientDisconnect").Invoke(item, new[] { e });
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 创建注册 RPGUSERINFO
        /// </summary>
        /// <param name="socketAsync"></param>
        /// <returns></returns>
        private RPCUserInfo NewRPCUserInfo(SocketAsyncEventArgs socketAsync)
        {
            RPCUserInfo tmp = new RPCUserInfo(socketAsync);

            tmp.RPC_Call.ErrMsgOut += RPC_Call_ErrMsgOut;
            foreach (var item in RegModule)
            {
                tmp.RPC_Call.RegModule(item);
            }

            return(tmp);
        }
Esempio n. 3
0
        private void DataOn(byte[] data, RPCUserInfo user)
        {
            ReadBytes read;
            int       cmd;


            if (!Service.CallModule(data, user, IsUseTaskQueue, out read, out cmd))
            {
                if (BinaryInputOther != null)
                {
                    BinaryInputOther(read, cmd);
                }
            }
        }
Esempio n. 4
0
        private void BinaryInputOffsetHandler(byte[] data, int offset, int count, SocketAsyncEventArgs socketAsync)
        {
            RPCUserInfo userinfo = socketAsync.UserToken as RPCUserInfo;

            if (userinfo == null)
            {
                Server.Disconnect(socketAsync.AcceptSocket);
                return;
            }

            userinfo.Stream.Write(data, offset, count);

            byte[] datax;
            while (userinfo.Stream.Read(out datax))
            {
                DataOn(datax, userinfo);
            }
        }
Esempio n. 5
0
        private void Call(RPCCallPack rpcPack, RPCUserInfo e)
        {
            try
            {
                object returnValue;

                CallContext.SetData("Current", e);
                string msg;
                if (e.RPC_Call.RunModule(rpcPack, out msg, out returnValue))
                {
                    ZYClient_Result_Return var = new ZYClient_Result_Return()
                    {
                        Id        = rpcPack.Id,
                        CallTime  = rpcPack.CallTime,
                        Arguments = rpcPack.Arguments
                    };

                    if (returnValue != null)
                    {
                        var.Return = Serialization.PackSingleObject(returnValue.GetType(), returnValue);
                    }

                    e.BeginSendData(BufferFormat.FormatFCA(var));
                }
            }
            catch (Exception er)
            {
                if (MsgOut != null)
                {
                    if (e.Asyn.RemoteEndPoint != null)
                    {
                        MsgOut(e.Asyn.RemoteEndPoint.ToString() + "::" + rpcPack.CallModule + "->" + rpcPack.Method + "\r\n" + er.ToString(), MsgOutType.Err);
                    }
                    else
                    {
                        MsgOut(rpcPack.CallModule + "->" + rpcPack.Method + "\r\n" + er.ToString(), MsgOutType.Err);
                    }
                }
            }
        }
Esempio n. 6
0
 public virtual void ClientDisconnect(RPCUserInfo userInfo)
 {
     return;
 }
Esempio n. 7
0
        /// <summary>
        /// 调用模块
        /// </summary>
        /// <param name="data"></param>
        /// <returns>true 属于次模块,false 不属于此模块数据</returns>
        public bool CallModule(byte[] data, RPCUserInfo e, out ReadBytes read, out int cmd)
        {
            cmd = -1;

            read = new ReadBytes(data);

            int lengt;

            if (read.ReadInt32(out lengt) && read.Length == lengt && read.ReadInt32(out cmd))
            {
                switch (cmd)
                {
                case 1001000:
                {
                    RPCCallPack tmp;

                    if (read.ReadObject <RPCCallPack>(out tmp))
                    {
                        System.Threading.Tasks.Task.Factory.StartNew(() =>
                            {
                                object returnValue;

                                CallContext.SetData("Current", e);

                                if (e.RPC_Call.RunModule(tmp, out returnValue))
                                {
                                    if (tmp.IsNeedReturn)
                                    {
                                        ZYClient_Result_Return var = new ZYClient_Result_Return()
                                        {
                                            Id        = tmp.Id,
                                            CallTime  = tmp.CallTime,
                                            Arguments = tmp.Arguments
                                        };

                                        if (returnValue != null)
                                        {
                                            var.Return     = Serialization.PackSingleObject(returnValue.GetType(), returnValue);
                                            var.ReturnType = returnValue.GetType();
                                        }

                                        e.EnsureSend(BufferFormat.FormatFCA(var));
                                    }
                                }
                            }, CancellationToken.None, TaskCreationOptions.None, e.QueueScheduler).ContinueWith(p =>
                            {
                                try
                                {
                                    p.Wait();
                                }
                                catch (Exception er)
                                {
                                    if (MsgOut != null)
                                    {
                                        MsgOut(er.ToString());
                                    }
                                }
                            });


                        return(true);
                    }
                }
                break;

                case 1001001:
                {
                    ZYClient_Result_Return val;

                    if (read.ReadObject <ZYClient_Result_Return>(out val))
                    {
                        e.RPC_Call.SetReturnValue(val);

                        return(true);
                    }
                }
                break;
                }
            }

            return(false);
        }
Esempio n. 8
0
        /// <summary>
        /// 调用模块
        /// </summary>
        /// <param name="data"></param>
        /// <returns>true 属于次模块,false 不属于此模块数据</returns>
        public bool CallModule(byte[] data, RPCUserInfo e, bool isTaskQueue, out ReadBytes read, out int cmd)
        {
            cmd = -1;

            read = new ReadBytes(data);

            int lengt;

            if (read.ReadInt32(out lengt) && read.Length == lengt && read.ReadInt32(out cmd))
            {
                switch (cmd)
                {
                case 1001000:
                {
                    RPCCallPack tmp;

                    if (read.ReadObject <RPCCallPack>(out tmp))
                    {
                        if (isTaskQueue)
                        {
                            System.Threading.Tasks.Task.Factory.StartNew((pack) => Call(pack as RPCCallPack, e)
                                                                         , tmp, CancellationToken.None, TaskCreationOptions.None, e.Scheduler).ContinueWith(p =>
                                {
                                    try
                                    {
                                        p.Wait();
                                    }
                                    catch (Exception er)
                                    {
                                        if (MsgOut != null)
                                        {
                                            if (e.Asyn.RemoteEndPoint != null)
                                            {
                                                MsgOut(e.Asyn.RemoteEndPoint.ToString() + "::" + tmp.CallModule + "->" + tmp.Method + "\r\n" + er.ToString(), MsgOutType.Err);
                                            }
                                            else
                                            {
                                                MsgOut(tmp.CallModule + "->" + tmp.Method + "\r\n" + er.ToString(), MsgOutType.Err);
                                            }
                                        }
                                    }
                                });


                            return(true);
                        }
                        else
                        {
                            Call(tmp, e);
                        }
                    }
                }
                break;

                case 1001001:
                {
                    ZYClient_Result_Return val;

                    if (read.ReadObject <ZYClient_Result_Return>(out val))
                    {
                        e.RPC_Call.SetReturnValue(val);

                        return(true);
                    }
                }
                break;
                }
            }

            return(false);
        }