예제 #1
0
        private void ManipulateBuffer()
        {
            //Do we still want to handle a packet in the buffer
            //even if the client has already disconnected?
            while (m_offset >= 4 && Disposed == false)
            {
                int size = MapleAes.GetLength(m_buffer);

                if (size <= 0)
                {
                    Dispose();
                    return;
                }

                if (m_offset < size + 4)
                {
                    break;
                }

                var packetBuffer = new byte[size];
                Buffer.BlockCopy(m_buffer, 4, packetBuffer, 0, size);

                MapleAes.Transform(packetBuffer, m_riv);
                Shanda.DecryptTransform(packetBuffer);

                m_offset -= size + 4;

                if (m_offset > 0)
                {
                    Buffer.BlockCopy(m_buffer, size + 4, m_buffer, 0, m_offset);
                }

                OnPacket?.Invoke(new CInPacket(packetBuffer));
            }
        }
예제 #2
0
        protected override void ManipulateBuffer()
        {
            while (m_offset >= 4)
            {
                int size = MapleAes.GetLength(ref m_buffer);

                if (size <= 0)
                {
                    Dispose();
                    return;
                }

                //TODO: Check Header

                if (m_offset < size + 4)
                {
                    break;
                }

                var span = new Span <byte>(m_buffer, 4, size);
                MapleAes.Transform(ref span, ref m_riv);
                Shanda.DecryptTransform(ref span);

                var payload = new byte[size];
                Buffer.BlockCopy(m_buffer, 4, payload, 0, size);

                m_offset -= size + 4;

                if (m_offset > 0)
                {
                    Buffer.BlockCopy(m_buffer, size + 4, m_buffer, 0, m_offset);
                }

                InvokeOnPacket(new CInPacket(payload, 0, size)); //OnPacket?.Invoke(new CInPacket(m_buffer, 4, size));
            }
        }