public void Send(params byte[][] packets) { if (!m_connected) { return; } lock (m_locker) { int length = 0; int offset = 0; foreach (byte[] buffer in packets) { length += 4; //header length length += buffer.Length; //packet length } byte[] finalPacket = new byte[length]; foreach (byte[] buffer in packets) { m_sendCipher.GetHeaderToClient(finalPacket, offset, buffer.Length); offset += 4; //header space m_sendCipher.Transform(buffer); Buffer.BlockCopy(buffer, 0, finalPacket, offset, buffer.Length); offset += buffer.Length; //packet space } SendRaw(finalPacket); //send the giant crypted packet } }
private void ManipulateBuffer() { while (m_offset > HeaderSize) //header room { int packetSize = MapleCipher.GetPacketLength(m_packet); if (m_offset < packetSize + HeaderSize) //header + packet room { break; } byte[] packetBuffer = new byte[packetSize]; Buffer.BlockCopy(m_packet, 4, packetBuffer, 0, packetSize); //copy packet m_recvCipher.Transform(packetBuffer); //decrypt m_offset -= packetSize + HeaderSize; //fix len if (m_offset > 0) //move reamining bytes { Buffer.BlockCopy(m_packet, packetSize + HeaderSize, m_packet, 0, m_offset); } OnPacket(packetBuffer); } }