Example #1
0
        //Shorthand for SubPacket with account type
        public SubPacket(bool register, ushort lengthOfUsername, ushort lengthOfPassword, uint sourceId, uint targetId, byte[] data, SubPacketTypes spt)
        {
            header        = new SubPacketHeader();
            accountHeader = new AccountHeader();
            if (register)
            {
                accountHeader.setForRegister = 1;
            }
            else
            {
                accountHeader.setForRegister = 0;
            }
            accountHeader.lengthOfUserName = lengthOfUsername;
            accountHeader.lengthOfPassword = lengthOfPassword;
            accountHeader.timeStamp        = Utils.UnixTimeStampUTC();
            accountHeader.misc2            = 0;
            accountHeader.misc3            = 0;
            accountHeader.misc4            = 0;
            header.sourceId = sourceId;
            header.targetId = targetId;

            header.type          = (ushort)spt;
            header.subpacketMisc = 0x00;

            this.data            = data;
            header.subpacketSize = (ushort)(SUBPACKET_SIZE + ACCOUNTMESSAGE_SIZE + data.Length);
        }
Example #2
0
        public unsafe SubPacket(byte[] bytes, ref int offset)
        {
            if (bytes.Length < offset + SUBPACKET_SIZE)
            {
                throw new OverflowException("Packet Error: Subpacket was too small");

                fixed(byte *pdata = &bytes[offset])
                {
                    header = (SubPacketHeader)Marshal.PtrToStructure(new IntPtr(pdata), typeof(SubPacketHeader));
                }

                if (header.type == (ushort)SubPacketTypes.GamePacket)
                {
                    fixed(byte *pdata = &bytes[offset + GAMEMESSAGE_SIZE])
                    {
                        gameMessage = (GameMessageHeader)Marshal.PtrToStructure(new IntPtr(pdata), typeof(GameMessageHeader));
                    }
                }

                if (header.type == (ushort)SubPacketTypes.Account)
                {
                    fixed(byte *pdata = &bytes[offset + ACCOUNTMESSAGE_SIZE])
                    {
                        accountHeader = (AccountHeader)Marshal.PtrToStructure(new IntPtr(pdata), typeof(AccountHeader));
                    }
                }

                if (bytes.Length < offset + header.subpacketSize)
                {
                    throw new OverflowException("Packet Error: Subpacket size didn't equal subpacket data");
                }

                if (header.type == (ushort)SubPacketTypes.GamePacket) // if type in the header is a game packet copy the gamepacket header into 16bit array
                {
                    data = new byte[header.subpacketSize - SUBPACKET_SIZE - GAMEMESSAGE_SIZE];
                    Array.Copy(bytes, offset + SUBPACKET_SIZE + GAMEMESSAGE_SIZE, data, 0, data.Length);
                }
                else if (header.type == (ushort)SubPacketTypes.Account)
                {
                    data = new byte[header.subpacketSize - SUBPACKET_SIZE - ACCOUNTMESSAGE_SIZE];
                    Array.Copy(bytes, offset + SUBPACKET_SIZE + ACCOUNTMESSAGE_SIZE, data, 0, data.Length);
                }
                else //else no second header just data
                {
                    data = new byte[header.subpacketSize - SUBPACKET_SIZE];
                    Array.Copy(bytes, offset + SUBPACKET_SIZE, data, 0, data.Length);
                }

                offset += header.subpacketSize;
        }