Example #1
0
        internal void SendPacket(byte[] packet)
        {
            if (Disposed)
            {
                return;
            }

            //TODO: Phase this lock out one day :^)
            lock (m_sendSync)
            {
                if (Disposed)
                {
                    return;
                }

                byte[] final = new byte[packet.Length + 4];

                MapleAes.GetHeader(final, m_siv, m_version);

                Shanda.EncryptTransform(packet);
                MapleAes.Transform(packet, m_siv);

                Buffer.BlockCopy(packet, 0, final, 4, packet.Length);

                SendRaw(final);
            }
        }
Example #2
0
        public override void SendPacket(COutPacket outPacket)
        {
            if (Disposed)
            {
                return;
            }

            lock (m_sendSync)    //TODO: Phase this lock out one day :^)
            {
                if (Disposed)
                {
                    return;
                }

                var packetLen = outPacket.Length;
                var packet    = outPacket.ToArray(); //TODO: phase out this allocation

                var finalLen = packet.Length + 4;
                var final    = BufferPool.Rent(finalLen);

                MapleAes.GetHeader(ref final, ref m_siv, packetLen, m_version);
                Buffer.BlockCopy(packet, 0, final, 4, packetLen);

                var span = new Span <byte>(final, 4, packetLen);
                Shanda.EncryptTransform(ref span);
                MapleAes.Transform(ref span, ref m_siv);

                SendAsync(final, 0, finalLen, final);
            }
        }
Example #3
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));
            }
        }
Example #4
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));
            }
        }