com.nukkitx.protocol.bedrock.BedrockPacket Java Examples

The following examples show how to use com.nukkitx.protocol.bedrock.BedrockPacket. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeyserSession.java    From Geyser with MIT License 5 votes vote down vote up
/**
 * Queue a packet to be sent to player.
 *
 * @param packet the bedrock packet from the NukkitX protocol lib
 */
public void sendUpstreamPacket(BedrockPacket packet) {
    if (upstream != null && !upstream.isClosed()) {
        upstream.sendPacket(packet);
    } else {
        connector.getLogger().debug("Tried to send upstream packet " + packet.getClass().getSimpleName() + " but the session was null");
    }
}
 
Example #2
Source File: GeyserSession.java    From Geyser with MIT License 5 votes vote down vote up
/**
 * Send a packet immediately to the player.
 * 
 * @param packet the bedrock packet from the NukkitX protocol lib
 */
public void sendUpstreamPacketImmediately(BedrockPacket packet) {
    if (upstream != null && !upstream.isClosed()) {
        upstream.sendPacketImmediately(packet);
    } else {
        connector.getLogger().debug("Tried to send upstream packet " + packet.getClass().getSimpleName() + " immediately but the session was null");
    }
}
 
Example #3
Source File: DefaultBatchHandler.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(BedrockSession session, ByteBuf compressed, Collection<BedrockPacket> packets) {
    for (BedrockPacket packet : packets) {
        if (session.isLogging() && log.isTraceEnabled()) {
            log.trace("Inbound {}: {}", session.getAddress(), packet);
        }

        BedrockPacketHandler handler = session.getPacketHandler();
        if (handler == null || !packet.handle(handler)) {
            log.debug("Unhandled packet for {}: {}", session.getAddress(), packet);
        }
    }
}
 
Example #4
Source File: UpstreamPacketHandler.java    From Geyser with MIT License 4 votes vote down vote up
private boolean translateAndDefault(BedrockPacket packet) {
    return PacketTranslatorRegistry.BEDROCK_TRANSLATOR.translate(packet.getClass(), packet, session);
}
 
Example #5
Source File: UpstreamPacketHandler.java    From Geyser with MIT License 4 votes vote down vote up
@Override
boolean defaultHandler(BedrockPacket packet) {
    return translateAndDefault(packet);
}
 
Example #6
Source File: UpstreamSession.java    From Geyser with MIT License 4 votes vote down vote up
public void sendPacket(@NonNull BedrockPacket packet) {
    if (isClosed())
        return;

    session.sendPacket(packet);
}
 
Example #7
Source File: UpstreamSession.java    From Geyser with MIT License 4 votes vote down vote up
public void sendPacketImmediately(@NonNull BedrockPacket packet) {
    if (isClosed())
        return;

    session.sendPacketImmediately(packet);
}
 
Example #8
Source File: LoggingPacketHandler.java    From Geyser with MIT License 4 votes vote down vote up
boolean defaultHandler(BedrockPacket packet) {
    connector.getLogger().debug("Handled packet: " + packet.getClass().getSimpleName());
    return false;
}
 
Example #9
Source File: ProxyPlayerSession.java    From ProxyPass with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void handle(BedrockSession session, ByteBuf compressed, Collection<BedrockPacket> packets) {
    boolean packetTesting = ProxyPlayerSession.this.proxy.getConfiguration().isPacketTesting();
    boolean batchHandled = false;
    List<BedrockPacket> unhandled = new ArrayList<>();
    for (BedrockPacket packet : packets) {
        if (!proxy.isIgnoredPacket(packet.getClass())) {
            if (session.isLogging() && log.isTraceEnabled()) {
                log.trace(this.logPrefix + " {}: {}", session.getAddress(), packet);
            }
            ProxyPlayerSession.this.log(() -> logPrefix + packet.toString());
            if (proxy.getConfiguration().isLoggingPackets() &&
                    proxy.getConfiguration().getLogTo().logToConsole) {
                System.out.println(logPrefix + packet.toString());
            }
        }

        BedrockPacketHandler handler = session.getPacketHandler();

        if (handler != null && packet.handle(handler)) {
            batchHandled = true;
        } else {
            unhandled.add(packet);
        }

        if (packetTesting) {
            ByteBuf buffer = ProxyPass.CODEC.tryEncode(packet);
            try {
                BedrockPacket packet2 = ProxyPass.CODEC.tryDecode(buffer);
                if (!Objects.equals(packet, packet2)) {
                    // Something went wrong in serialization.
                    log.warn("Packets instances not equal:\n Original  : {}\nRe-encoded : {}",
                            packet, packet2);
                }
            } finally {
                buffer.release();
            }
        }
    }

    if (!batchHandled) {
        compressed.resetReaderIndex();
        this.session.sendWrapped(compressed, true);
    } else if (!unhandled.isEmpty()) {
        this.session.sendWrapped(unhandled, true);
    }
}
 
Example #10
Source File: BedrockCompressionHandler.java    From Protocol with Apache License 2.0 votes vote down vote up
ByteBuf compressPackets(BedrockPacketCodec packetCodec, Collection<BedrockPacket> packets); 
Example #11
Source File: BedrockCompressionHandler.java    From Protocol with Apache License 2.0 votes vote down vote up
Collection<BedrockPacket> decompressPackets(BedrockPacketCodec packetCodec, ByteBuf compressed); 
Example #12
Source File: BatchHandler.java    From Protocol with Apache License 2.0 votes vote down vote up
void handle(BedrockSession session, ByteBuf compressed, Collection<BedrockPacket> packets);