Search in sources :

Example 1 with PING_DataPacket

use of cn.nukkit.raknet.protocol.packet.PING_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)

Aggregations

DataPacket (cn.nukkit.network.protocol.DataPacket)1 PING_DataPacket (cn.nukkit.raknet.protocol.packet.PING_DataPacket)1 MainLogger (cn.nukkit.utils.MainLogger)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1