Пример #1
0
        private void HandleMsg(Conn conn, ProtocolBase protocol)
        {
            string name       = protocol.GetName();
            string methodName = "Msg" + name;

            //Console.WriteLine("[收到协议]" + methodName+"*");
            Console.WriteLine(conn.player);
            if (conn.player == null || name == "HeatBeat" || name == "Logout")
            {
                MethodInfo mm = handleConnMsg.GetType().GetMethod(methodName);
                if (mm == null)
                {
                    string str = "[警告]HandleConnMsg 没有处理连接方法";
                    Console.WriteLine(str + methodName);
                    return;
                }
                Object [] obj = new object[] { conn, protocol };
                Console.WriteLine("[处理连接信息]" + conn.GetAdress() + ":" + name);
                mm.Invoke(handleConnMsg, obj);
            }
            else
            {
                MethodInfo mm = handlePlayerMsg.GetType().GetMethod(methodName);
                if (mm == null)
                {
                    string str = "[警告]handlePlayerMsg没有处理玩家方法 ";
                    Console.WriteLine(str + methodName);
                    return;
                }
                Object[] obj = new object[] { conn.player, protocol };
                Console.WriteLine("[处理玩家消息]" + conn.player.id + ":" + name);
                mm.Invoke(handlePlayerMsg, obj);
            }
        }