Exemple #1
0
        private void HandleMsg(Conn conn, ProtocolBase protoBase)
        {
            string name       = protoBase.GetName();
            string methodName = "Msg" + name;

            //连接协议分发
            if (conn.player == null || name == "HeartBeat" || name == "Logout")
            {
                MethodInfo methodInfo = handleConnMsg.GetType().GetMethod(methodName);
                if (methodInfo == null)
                {
                    Console.WriteLine("[警告]HandleMsg没有处理连接方法" + methodName);
                    return;
                }

                Object[] obj = new Object[] { conn, protoBase };
                methodInfo.Invoke(handleConnMsg, obj);
            }
            //角色协议分发
            else
            {
                MethodInfo methodInfo = HandlePlayerMsg.GetType().GetMethod(methodName);
                if (methodInfo == null)
                {
                    Console.WriteLine("[警告]HandleMsg没有处理连接方法" + methodName);
                    return;
                }

                Object[] obj = new Object[] { conn.player, protoBase };
                methodInfo.Invoke(HandlePlayerMsg, obj);
            }
        }
Exemple #2
0
        /// <summary>
        /// According to the protocol name, call different function to handle problem.
        /// </summary>
        /// <param name="conn">Conn.</param>
        /// <param name="protoBase">Proto base.</param>
        void HandleMsg(Conn conn, ProtocolBase protoBase)
        {
            string name       = protoBase.GetName();
            string methodName = "Msg" + name;

            if (conn.player == null || name == "HeartBeat" || name == "Logout")
            {
                MethodInfo mm = handleConnMsg.GetType().GetMethod(methodName);
                if (mm == null)
                {
                    Console.WriteLine("[ServNet.HandleMsg] ConnMsgHandler has no appropriate function.");
                    return;
                }
                Object[] obj = new object[] { conn, protoBase };
                Console.WriteLine("[ServNet.HandleMsg] Handle ConnMsg : " + conn.GetAddress() + " [" + name + "]");
                mm.Invoke(handleConnMsg, obj);
            }
            else
            {
                MethodInfo mm = handlePlayerMsg.GetType().GetMethod(methodName);
                if (mm == null)
                {
                    Console.WriteLine("[ServNet.HandleMsg] PlayerMsgHandler has no appropriate function.");
                    return;
                }
                Object[] obj = new object[] { conn.player, protoBase };
                mm.Invoke(handlePlayerMsg, obj);
            }
        }
        public void HandleMsg(Conn conn, ProtocolBase protoBase)
        {
            string name       = protoBase.GetName();
            string methodName = "Msg" + name;

            //处理玩家连接
            if (conn.player == null || name == "HeatBeat" || name == "Logout" || name == "Login" || name == "isserver")
            {
                MethodInfo mm = handleConnMsg.GetType().GetMethod(methodName);
                if (mm == null)
                {
                    string str = "[警告]HandleMsg没有处理连接方法";
                    Console.WriteLine(str + methodName);
                    return;
                }
                Object[] obj = new object[] { conn, protoBase };
                //Console.WriteLine("[处理连接的消息]" + conn.GetAddress() + "[" + name + "]");
                mm.Invoke(handleConnMsg, obj);
            }
            //处理玩家方法
            else
            {
                MethodInfo mm = handleplayerMsg.GetType().GetMethod(methodName);
                if (mm == null)
                {
                    string str = "[警告]handleMsg没有处理玩家方法";
                    Console.WriteLine(str + methodName);
                    return;
                }
                Object[] obj = new object[] { conn.player, protoBase };
                Console.WriteLine("[处理玩家的消息]" + conn.player.username + "[" + name + "]");
                mm.Invoke(handleplayerMsg, obj);
            }
        }
Exemple #4
0
        public void HandleMsg(Conn conn, ProtocolBase protocolBase)
        {
            string name = protocolBase.GetName();

            if (name != "UpdateInfo")
            {
                Console.WriteLine("[收到协议] " + name);
            }
            string methodName = "Msg" + name;

            //连接协议分发
            if (conn.player == null || name == "HeartBeat" || name == "Logout" || name == "Login" || name == "Register")
            {
                MethodInfo mm = handleConnMsg.GetType().GetMethod(methodName);
                if (mm == null)
                {
                    string str = "[警告]HandleMsg没有处理连接方法";
                    Console.WriteLine(str + methodName);
                    return;
                }
                Object[] obj = new object[] { conn, protocolBase };
                Console.WriteLine("[处理连接信息] " + conn.GetAddr() + " : " + name);
                mm.Invoke(handleConnMsg, obj);
            }
            //角色协议分发
            else
            {
                MethodInfo mm = handlePlayerMsg.GetType().GetMethod(methodName);
                if (mm == null)
                {
                    string str = "[警告]HandleMsg没有处理玩家方法";
                    Console.WriteLine(str + methodName);
                    return;
                }
                Object[] obj = new object[] { conn.player, protocolBase };
                if (name != "UpdateInfo")
                {
                    Console.WriteLine("[处理玩家信息] " + conn.player.id + " : " + name);
                }
                mm.Invoke(handlePlayerMsg, obj);
            }
        }