com.nukkitx.protocol.bedrock.BedrockSession Java Examples

The following examples show how to use com.nukkitx.protocol.bedrock.BedrockSession. 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: 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 #2
Source File: ProxyPlayerSession.java    From ProxyPass with GNU Affero General Public License v3.0 4 votes vote down vote up
private ProxyBatchHandler(BedrockSession session, boolean upstream) {
    this.session = session;
    this.logPrefix = upstream ? "[SERVER BOUND]  -  " : "[CLIENT BOUND]  -  ";
}
 
Example #3
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 #4
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);