/** * Applies a pipeline from an index to the wrapper * * @param direction The direction * @param state The state * @param index The index to start from * @param pipeline The pipeline * @return The current packetwrapper * @throws Exception If it fails to transform a packet, exception will be thrown */ public PacketWrapper apply(Direction direction, State state, int index, List<Protocol> pipeline) throws Exception { for (int i = index; i < pipeline.size(); i++) { // Copy to prevent from removal. pipeline.get(i).transform(direction, state, this); // Reset the reader for the packetWrapper (So it can be recycled across packets) resetReader(); } return this; }
@Override public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception { super.transform(direction, state, packetWrapper); if (direction == Direction.INCOMING && state == State.HANDSHAKE) { // Disable if it isn't a handshake packet. if (packetWrapper.getId() != 0) { packetWrapper.user().setActive(false); } } } }
@Override public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception { CompressionSendStorage compressionSendStorage = packetWrapper.user().get(CompressionSendStorage.class); if (compressionSendStorage.isCompressionSend()) { Channel channel = packetWrapper.user().getChannel(); channel.pipeline().replace("decompress", "decompress", new EmptyChannelHandler()); channel.pipeline().replace("compress", "compress", new ForwardMessageToByteEncoder()); compressionSendStorage.setCompressionSend(false); } super.transform(direction, state, packetWrapper); }
super.transform(direction, state, packetWrapper);