public void doData(byte[] data) { tempindex = 0; byte command = DataPro.getByte(data, ref tempindex); switch (command) { case PacketDefine.UserIn: isON = true; Packet p = new Packet(); p.addByte(PacketDefine.ConnectionSucess); p.addInt(m_id); Console.WriteLine("玩家: {0}", m_id); sendPacket(p); break; case PacketDefine.EnterMap: Enter(data); break; case PacketDefine.MoveInMap: Move(data); break; } }
//数据解析 public void parse() { byte packageLength = DataPro.getByte(m_buffer, ref m_postion); if ((packageLength + m_postion) <= m_endIndex) { Console.WriteLine("Complete Package"); byte[] data = new byte[packageLength]; DataPro.getByteArray(m_buffer, ref m_postion, data); ThreadMessage tm = new ThreadMessage(); tm.data = data; tm.mc = m_cc; //推入线程池 MyGlobal.mpool.addJob(tm); parse(); } else { m_postion--; } }