Search in sources :

Example 6 with PEBinaryReader

use of org.dragonet.utilities.io.PEBinaryReader in project Dragonet-Legacy by DragonetMC.

the class DisconnectPacket method decode.

@Override
public void decode() {
    try {
        PEBinaryReader reader = new PEBinaryReader(new ByteArrayInputStream(this.getData()));
        //PID
        reader.readByte();
        this.message = reader.readString();
        this.setLength(reader.totallyRead());
    } catch (IOException e) {
    }
}
Also used : PEBinaryReader(org.dragonet.utilities.io.PEBinaryReader) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException)

Example 7 with PEBinaryReader

use of org.dragonet.utilities.io.PEBinaryReader in project Dragonet-Legacy by DragonetMC.

the class DropItemPacket method decode.

@Override
public void decode() {
    try {
        setChannel(NetworkChannel.CHANNEL_ENTITY_SPAWNING);
        PEBinaryReader reader = new PEBinaryReader(new ByteArrayInputStream(this.getData()));
        //PID
        reader.readByte();
        this.type = reader.readByte();
        this.slot = PEInventorySlot.readSlot(reader);
        this.setLength(reader.totallyRead());
    } catch (IOException e) {
    }
}
Also used : PEBinaryReader(org.dragonet.utilities.io.PEBinaryReader) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException)

Example 8 with PEBinaryReader

use of org.dragonet.utilities.io.PEBinaryReader in project Dragonet-Legacy by DragonetMC.

the class LoginPacket method decode.

@Override
public void decode() {
    try {
        PEBinaryReader reader = new PEBinaryReader(new ByteArrayInputStream(this.getData()));
        //PID
        reader.readByte();
        this.username = reader.readString();
        this.protocol1 = reader.readInt();
        this.protocol2 = reader.readInt();
        this.clientID = reader.readLong();
        this.clientUuid = reader.readUUID();
        this.serverAddress = reader.readString();
        this.clientSecret = reader.readString();
        this.slim = (reader.readByte() & 0xF) > 0;
        this.skinTransparent = (reader.readByte() & 0xF) > 0;
        int len = reader.readShort();
        this.skin = reader.read(len);
        this.setLength(reader.totallyRead());
    } catch (IOException e) {
    }
}
Also used : PEBinaryReader(org.dragonet.utilities.io.PEBinaryReader) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException)

Example 9 with PEBinaryReader

use of org.dragonet.utilities.io.PEBinaryReader in project Dragonet-Legacy by DragonetMC.

the class BatchPacket method decode.

@Override
public void decode() {
    try {
        packets = new ArrayList<>();
        PEBinaryReader reader = new PEBinaryReader(new ByteArrayInputStream(this.getData()));
        //PID
        reader.readByte();
        int size = reader.readInt();
        byte[] payload = reader.read(size);
        Inflater inf = new Inflater();
        inf.setInput(payload);
        byte[] decompressedPayload = new byte[1024 * 1024 * 64];
        int decompressedSize = 0;
        try {
            decompressedSize = inf.inflate(decompressedPayload);
        } catch (DataFormatException ex) {
            this.setLength(reader.totallyRead());
            return;
        }
        inf.end();
        PEBinaryReader dataReader = new PEBinaryReader(new ByteArrayInputStream(decompressedPayload));
        int offset = 0;
        while (offset < decompressedSize) {
            int pkLen = dataReader.readInt();
            offset += 4;
            byte[] pkData = dataReader.read(pkLen);
            offset += pkLen;
            PEPacket pk = Protocol.decode(pkData);
            if (pk == null || pk.getLength() == 0) {
                packets.clear();
                return;
            }
            packets.add(pk);
        }
        this.setLength(reader.totallyRead());
    } catch (IOException e) {
    }
}
Also used : PEBinaryReader(org.dragonet.utilities.io.PEBinaryReader) DataFormatException(java.util.zip.DataFormatException) ByteArrayInputStream(java.io.ByteArrayInputStream) Inflater(java.util.zip.Inflater) IOException(java.io.IOException)

Example 10 with PEBinaryReader

use of org.dragonet.utilities.io.PEBinaryReader in project Dragonet-Legacy by DragonetMC.

the class ChatPacket method decode.

@Override
public void decode() {
    try {
        PEBinaryReader reader = new PEBinaryReader(new ByteArrayInputStream(this.getData()));
        //PID
        reader.readByte();
        this.type = TextType.fromNum(reader.readByte());
        switch(this.type) {
            case POPUP:
            case CHAT:
                this.source = reader.readString();
            case RAW:
            case TIP:
            case SYSTEM:
                this.message = reader.readString();
                break;
            case TRANSLATION:
                this.message = reader.readString();
                int cnt = reader.readByte();
                this.params = new String[cnt];
                for (int i = 0; i < cnt; i++) {
                    this.params[i] = reader.readString();
                }
                break;
        }
        this.setLength(reader.totallyRead());
    } catch (IOException e) {
    }
}
Also used : PEBinaryReader(org.dragonet.utilities.io.PEBinaryReader) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)17 IOException (java.io.IOException)17 PEBinaryReader (org.dragonet.utilities.io.PEBinaryReader)17 DataFormatException (java.util.zip.DataFormatException)1 Inflater (java.util.zip.Inflater)1