Search in sources :

Example 6 with DataPacket

use of cn.nukkit.network.protocol.DataPacket in project Nukkit by Nukkit.

the class RakNetInterface method handleEncapsulated.

@Override
public void handleEncapsulated(String identifier, EncapsulatedPacket packet, int flags) {
    if (this.players.containsKey(identifier)) {
        DataPacket pk = null;
        try {
            if (packet.buffer.length > 0) {
                if (packet.buffer[0] == PING_DataPacket.ID) {
                    PING_DataPacket pingPacket = new PING_DataPacket();
                    pingPacket.buffer = packet.buffer;
                    pingPacket.decode();
                    this.networkLatency.put(identifier, (int) pingPacket.pingID);
                    return;
                }
                pk = this.getPacket(packet.buffer);
                if (pk != null) {
                    pk.decode();
                    this.players.get(identifier).handleDataPacket(pk);
                }
            }
        } catch (Exception e) {
            this.server.getLogger().logException(e);
            if (Nukkit.DEBUG > 1 && pk != null) {
                MainLogger logger = this.server.getLogger();
                // if (logger != null) {
                logger.debug("Packet " + pk.getClass().getName() + " 0x" + Binary.bytesToHexString(packet.buffer));
            // logger.logException(e);
            // }
            }
            if (this.players.containsKey(identifier)) {
                this.handler.blockAddress(this.players.get(identifier).getAddress(), 5);
            }
        }
    }
}
Also used : PING_DataPacket(cn.nukkit.raknet.protocol.packet.PING_DataPacket) MainLogger(cn.nukkit.utils.MainLogger) PING_DataPacket(cn.nukkit.raknet.protocol.packet.PING_DataPacket) DataPacket(cn.nukkit.network.protocol.DataPacket) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with DataPacket

use of cn.nukkit.network.protocol.DataPacket in project Nukkit by Nukkit.

the class DestroyBlockParticle method encode.

@Override
public DataPacket[] encode() {
    LevelEventPacket pk = new LevelEventPacket();
    pk.evid = LevelEventPacket.EVENT_PARTICLE_DESTROY;
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.data = this.data;
    return new DataPacket[] { pk };
}
Also used : LevelEventPacket(cn.nukkit.network.protocol.LevelEventPacket) DataPacket(cn.nukkit.network.protocol.DataPacket)

Example 8 with DataPacket

use of cn.nukkit.network.protocol.DataPacket in project Nukkit by Nukkit.

the class FloatingTextParticle method encode.

@Override
public DataPacket[] encode() {
    ArrayList<DataPacket> packets = new ArrayList<>();
    if (this.entityId == -1) {
        this.entityId = 1095216660480L + ThreadLocalRandom.current().nextLong(0, 0x7fffffffL);
    } else {
        RemoveEntityPacket pk = new RemoveEntityPacket();
        pk.eid = this.entityId;
        packets.add(pk);
    }
    if (!this.invisible) {
        AddPlayerPacket pk = new AddPlayerPacket();
        pk.uuid = UUID.randomUUID();
        pk.username = "";
        pk.entityUniqueId = this.entityId;
        pk.entityRuntimeId = this.entityId;
        pk.x = (float) this.x;
        pk.y = (float) (this.y - 0.75);
        pk.z = (float) this.z;
        pk.speedX = 0;
        pk.speedY = 0;
        pk.speedZ = 0;
        pk.yaw = 0;
        pk.pitch = 0;
        long flags = ((1L << Entity.DATA_FLAG_CAN_SHOW_NAMETAG) | (1L << Entity.DATA_FLAG_ALWAYS_SHOW_NAMETAG) | (1L << Entity.DATA_FLAG_IMMOBILE));
        pk.metadata = new EntityMetadata().putLong(Entity.DATA_FLAGS, flags).putString(Entity.DATA_NAMETAG, this.title + (!this.text.isEmpty() ? "\n" + this.text : "")).putLong(Entity.DATA_LEAD_HOLDER_EID, -1).putFloat(Entity.DATA_SCALE, // zero causes problems on debug builds?
        0.01f);
        pk.item = Item.get(Item.AIR);
        packets.add(pk);
    }
    return packets.stream().toArray(DataPacket[]::new);
}
Also used : RemoveEntityPacket(cn.nukkit.network.protocol.RemoveEntityPacket) AddPlayerPacket(cn.nukkit.network.protocol.AddPlayerPacket) EntityMetadata(cn.nukkit.entity.data.EntityMetadata) ArrayList(java.util.ArrayList) DataPacket(cn.nukkit.network.protocol.DataPacket)

Example 9 with DataPacket

use of cn.nukkit.network.protocol.DataPacket in project Nukkit by Nukkit.

the class MobSpawnParticle method encode.

@Override
public DataPacket[] encode() {
    LevelEventPacket packet = new LevelEventPacket();
    packet.evid = LevelEventPacket.EVENT_PARTICLE_SPAWN;
    packet.x = (float) this.x;
    packet.y = (float) this.y;
    packet.z = (float) this.z;
    packet.data = (this.width & 0xff) + ((this.height & 0xff) << 8);
    return new DataPacket[] { packet };
}
Also used : LevelEventPacket(cn.nukkit.network.protocol.LevelEventPacket) DataPacket(cn.nukkit.network.protocol.DataPacket)

Example 10 with DataPacket

use of cn.nukkit.network.protocol.DataPacket in project Nukkit by Nukkit.

the class PunchBlockParticle method encode.

@Override
public DataPacket[] encode() {
    LevelEventPacket pk = new LevelEventPacket();
    pk.evid = LevelEventPacket.EVENT_PARTICLE_PUNCH_BLOCK;
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.data = this.data;
    return new DataPacket[] { pk };
}
Also used : LevelEventPacket(cn.nukkit.network.protocol.LevelEventPacket) DataPacket(cn.nukkit.network.protocol.DataPacket)

Aggregations

DataPacket (cn.nukkit.network.protocol.DataPacket)11 LevelEventPacket (cn.nukkit.network.protocol.LevelEventPacket)6 PING_DataPacket (cn.nukkit.raknet.protocol.packet.PING_DataPacket)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Player (cn.nukkit.Player)1 EntityMetadata (cn.nukkit.entity.data.EntityMetadata)1 CompressBatchedTask (cn.nukkit.network.CompressBatchedTask)1 AddPlayerPacket (cn.nukkit.network.protocol.AddPlayerPacket)1 RemoveEntityPacket (cn.nukkit.network.protocol.RemoveEntityPacket)1 EncapsulatedPacket (cn.nukkit.raknet.protocol.EncapsulatedPacket)1 MainLogger (cn.nukkit.utils.MainLogger)1 ArrayList (java.util.ArrayList)1