Example #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (mOutboundBuffer != null)
            {
                mOutboundBuffer.Clear();
                mOutboundBuffer = null;
            }

            if (mInboundBuffer != null)
            {
                mInboundBuffer.Clear();
                mInboundBuffer = null;
            }

            if (mOutboundStream != null)
            {
                mOutboundStream.Dispose();
                mOutboundStream = null;
            }

            if (mInboundStream != null)
            {
                mInboundStream.Dispose();
                mInboundStream = null;
            }
        }
Example #2
0
        internal bool BufferTCPPacket(TcpPacket pTCPPacket, bool pInbound)
        {
            if (pTCPPacket.Syn && pTCPPacket.Ack)
            {
                mInboundSequence = (uint)(pTCPPacket.SequenceNumber + 1); 
                return true;
            }
            if (pTCPPacket.PayloadData.Length == 0) return true;
            if (_mapleVersion == 0)
            {
                if (pTCPPacket.PayloadData.Length < 13) return false;
                byte[] tcpData = pTCPPacket.PayloadData;

                MaplePacket pr = new MaplePacket(tcpData);
                pr.ReadShort();
                _mapleVersion = pr.ReadUShort();
                var pos = pr.Position;
                {
                    var shrt = pr.ReadShort();
                    if (shrt < 0 || shrt > 0x0020)
                    {
                        return false;
                    }
                }
                pr.Reset(pos);
                _maplePatchLocation = pr.ReadString();
                byte[] localIV = pr.ReadBytes(4);
                byte[] remoteIV = pr.ReadBytes(4);
                _mapleLocale = pr.ReadByte();

                if (pr.Length > pr.Position || _mapleLocale > 0x12)
                {
                    return false;
                }

                pr.Dispose();
                pr = null;

                mOutboundStream = new PacketStream(localIV, _mapleLocale, _mapleVersion, !pInbound);
                mInboundStream = new PacketStream(remoteIV, _mapleLocale, (ushort)(0xFFFF - _mapleVersion), pInbound);
                mInboundSequence += (uint)tcpData.Length;

            }
            if (!pInbound) ProcessTCPPacket(pTCPPacket, ref mOutboundSequence, mOutboundBuffer, mOutboundStream, pInbound);
            else ProcessTCPPacket(pTCPPacket, ref mInboundSequence, mInboundBuffer, mInboundStream, pInbound);

            return true;
        }
Example #3
0
        private void CheckForPackets(PacketStream pStream, bool pInbound)
        {
            while (true)
            {
                MaplePacket packet = pStream.Read();
                if (packet == null)
                    break;

                if (pInbound)
                {
                    Program.RECV_DATA += packet.Length;
                    Program.RECV_PACKETS++;
                }
                else
                {
                    Program.SENT_DATA += packet.Length;
                    Program.SENT_PACKETS++;
                }

                MasterThread.Instance.AddCallback((a) =>
                {
                    ServerConnection.Instance.ForwardPacket(pInbound ? MaplePacket.CommunicationType.ServerPacket : MaplePacket.CommunicationType.ClientPacket, packet);

                    packet.Dispose();
                    packet = null;
                });
            }

        }
Example #4
0
        private void ProcessTCPPacket(TcpPacket pTCPPacket, ref uint pSequence, Dictionary<uint, byte[]> pBuffer, PacketStream pStream, bool pInbound)
        {
            if (pTCPPacket.SequenceNumber > pSequence)
            {
                byte[] data;
                while ((data = pBuffer.GetOrDefault(pSequence, null)) != null)
                {
                    pBuffer.Remove(pSequence);
                    pStream.Append(data);
                    pSequence += (uint)data.Length;
                }
                if (pTCPPacket.SequenceNumber > pSequence)
                {
                    pBuffer[(uint)pTCPPacket.SequenceNumber] = pTCPPacket.PayloadData;
                }
            }
            if (pTCPPacket.SequenceNumber < pSequence)
            {
                int difference = (int)(pSequence - pTCPPacket.SequenceNumber);
                if (difference > 0)
                {
                    byte[] data = pTCPPacket.PayloadData;
                    if (data.Length > difference)
                    {
                        pStream.Append(data, difference, data.Length - difference);
                        pSequence += (uint)(data.Length - difference);
                    }
                }
            }
            else if (pTCPPacket.SequenceNumber == pSequence)
            {
                byte[] data = pTCPPacket.PayloadData;
                pStream.Append(data);
                pSequence += (uint)data.Length;
            }

            CheckForPackets(pStream, pInbound);

        }