Esempio n. 1
0
        public void Update()
        {
            ProcessRecv();

            while (_pluginRecvQueue.TryDequeue(out byte[] data) && data != null && data.Length != 0)
            {
                int length = PacketsTable.GetPacketLength(data[0]);
                int offset = 1;

                if (length == -1)
                {
                    if (data.Length < 3)
                    {
                        continue;
                    }

                    //length = data[2] | (data[1] << 8);
                    offset = 3;
                }

                PacketHandlers.Handlers.AnalyzePacket(data, offset, data.Length);
            }

            ProcessSend();
        }
Esempio n. 2
0
        private static bool GetPacketInfo(CircularBuffer buffer, int bufferLength, out int offset, out int length)
        {
            if (buffer == null || bufferLength <= 0)
            {
                length = 0;
                offset = 0;

                return(false);
            }

            length = PacketsTable.GetPacketLength(buffer.GetID());
            offset = 1;

            if (length == -1)
            {
                if (bufferLength < 3)
                {
                    return(false);
                }

                length = buffer.GetLength();
                offset = 3;
            }

            return(bufferLength >= length);
        }
Esempio n. 3
0
        public PCreateCharacter(string name) : base(0x00)
        {
            int skillcount = 3;

            if (FileManager.ClientVersion >= ClientVersions.CV_70160)
            {
                skillcount++;
                this[0]   = 0xF8;
                IsDynamic = PacketsTable.GetPacketLength(this[0]) < 0;
            }

            WriteUInt(0xEDEDEDED);
            WriteUShort(0xFFFF);
            WriteUShort(0xFFFF);
            WriteByte(0x00);
            WriteASCII(name, 30);
            WriteUShort(0x00);
            uint clientflag = 0;

            /*IFOR(i, 0, g_CharacterList.ClientFlag)
             *  clientFlag |= (1 << i);*/
            WriteUInt(clientflag);
            WriteUInt(0x01);
            WriteUInt(0x0);

            // to terminate...
        }
Esempio n. 4
0
        public PacketWriter(byte id)
        {
            short len = PacketsTable.GetPacketLength(id);

            IsDynamic = len < 0;
            _data     = new byte[IsDynamic ? 3 : len];
            _data[0]  = id;
            Position  = IsDynamic ? 3 : 1;
        }
Esempio n. 5
0
        protected void SetPacketId(byte id)
        {
            short len = PacketsTable.GetPacketLength(id);

            IsDynamic = len < 0;
            _data     = new byte[IsDynamic ? 32 : len];
            _data[0]  = id;
            Position  = IsDynamic ? 3 : 1;
        }
Esempio n. 6
0
        private void ExtractPackets()
        {
            if (!IsConnected || _circularBuffer == null || _circularBuffer.Length <= 0)
            {
                return;
            }

            lock (_circularBuffer)
            {
                int length = _circularBuffer.Length;

                while (length > 0 && IsConnected)
                {
                    byte id           = _circularBuffer.GetID();
                    int  packetlength = PacketsTable.GetPacketLength(id);

                    if (packetlength == -1)
                    {
                        if (length >= 3)
                        {
                            packetlength = _circularBuffer.GetLength();
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (length < packetlength)
                    {
                        break;
                    }
                    byte[] data = /*BUFF_SIZE >= packetlength ? _pool.GetFreeSegment() : */ new byte[packetlength];
                    packetlength = _circularBuffer.Dequeue(data, 0, packetlength);

                    //PacketReceived?.Invoke(null, packet);

                    //_packetsToRead.Enqueue(packet);

                    lock (_sync)
                    {
                        Packet packet = new Packet(data, packetlength);
                        _workingQueue.Enqueue(packet);
                    }

                    length = _circularBuffer.Length;

                    //if (BUFF_SIZE >= packetlength) _pool.AddFreeSegment(data);
                }
            }
        }
Esempio n. 7
0
        private void ExtractPackets()
        {
            if (!IsConnected || _circularBuffer == null || _circularBuffer.Length <= 0)
            {
                return;
            }

            lock (_circularBuffer)
            {
                int length = _circularBuffer.Length;

                while (length > 0 && IsConnected)
                {
                    byte id           = _circularBuffer.GetID();
                    int  packetlength = PacketsTable.GetPacketLength(id);

                    if (packetlength == -1)
                    {
                        if (length >= 3)
                        {
                            packetlength = _circularBuffer.GetLength();
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (length < packetlength)
                    {
                        break;
                    }

                    byte[] data = new byte[packetlength];
                    packetlength = _circularBuffer.Dequeue(data, 0, packetlength);

                    lock (_sync)
                    {
                        Packet packet = new Packet(data, packetlength);
                        _workingQueue.Enqueue(packet);
                        Statistics.TotalPacketsReceived++;
                    }

                    length = _circularBuffer.Length;
                }
            }
        }
Esempio n. 8
0
 public PCastSpell(int idx) : base(0xBF)
 {
     if (Client.Version >= ClientVersion.CV_60142)
     {
         WriteUShort(0x1C);
         WriteUShort(0x02);
         WriteUShort((ushort)idx);
     }
     else
     {
         this[0]   = 0x12;
         IsDynamic = PacketsTable.GetPacketLength(this[0]) < 0;
         WriteByte(0x56);
         WriteASCII(idx.ToString());
         // need a \0 ?
     }
 }
Esempio n. 9
0
 public Packet(byte[] data, int length)
 {
     _data     = data;
     Length    = length;
     IsDynamic = PacketsTable.GetPacketLength(ID) < 0;
 }