public static void Run(short id, MapleBuffer mapleBuffer, CMapleClient client) { if (mHandler.ContainsKey(id)) { object[] attributes = mHandler[id].GetType().GetCustomAttributes(typeof(PacketHead), true);//.Attributes; foreach (object packethead in attributes) { if (packethead is PacketHead) { Console.WriteLine("运行:" + ((PacketHead)packethead).Text); } } mHandler[id].Handle(mapleBuffer, client); } else { System.Console.WriteLine("包头:{0}[{1}]", id, mapleBuffer.ToString()); } }
public override void ChannelRead(IChannelHandlerContext context, object message) { try { MapleBuffer buffer = new MapleBuffer((byte[])message); if (buffer.Available < 2) { return; } System.Console.WriteLine("封包: {0}", buffer.ToString()); CMapleClient client = context.GetAttribute <CMapleClient>(CMapleClient.attributeKey).Get(); if (client != null) { short packetId = buffer.read <byte>(); CommonGlobal.Run(packetId, buffer, client); } } catch (Exception e) { System.Console.WriteLine("错误:" + e); } }