@Override protected void initChannel(SocketChannel socketChannel) throws Exception { UserConnection info = new UserConnection(socketChannel); // init protocol new ProtocolPipeline(info); // Add originals this.method.invoke(this.original, socketChannel); if (socketChannel.pipeline().get("packet-encoder") == null) return; // Don't inject if no packet-encoder if (socketChannel.pipeline().get("packet-decoder") == null) return; // Don't inject if no packet-decoder // Add our transformers BungeeEncodeHandler encoder = new BungeeEncodeHandler(info); BungeeDecodeHandler decoder = new BungeeDecodeHandler(info); socketChannel.pipeline().addBefore("packet-encoder", "via-encoder", encoder); socketChannel.pipeline().addBefore("packet-decoder", "via-decoder", decoder); } }
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper);
/** * Checks if the UUID is on the selected pipe * * @param uuid UUID Object * @return True if on pipe */ protected boolean isOnPipe(UUID uuid) { UserConnection userConnection = getUserConnection(uuid); return userConnection != null && userConnection.get(ProtocolInfo.class).getPipeline().contains(requiredPipeline); }
/** * Cleans the pipe and adds {@link us.myles.ViaVersion.protocols.base.BaseProtocol} * /!\ WARNING - It doesn't add version-specific base Protocol */ public void cleanPipes() { pipes().clear(); registerPackets(); } }
ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline(); user.clearStoredObjects(); pipeline.cleanPipes(); if (protocols == null) { } else { for (Pair<Integer, Protocol> prot : protocols) { pipeline.add(prot.getValue()); pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId)); for (Protocol protocol : pipeline.pipes()) { protocol.init(user);
List<Protocol> protocols = new ArrayList<>(user().get(ProtocolInfo.class).getPipeline().pipes()); if (direction == Direction.OUTGOING) {
@Override protected void encode(ChannelHandlerContext ctx, Object o, List list) throws Exception { // Split chunks bulk packet up in to single chunks packets before it reached the encoder. // This will prevent issues with several plugins and other protocol handlers due to the chunks being sent twice. // It also sends the chunks in the right order possible resolving some issues with added chunks/block/entity data. if (!(o instanceof ByteBuf)) { info.setLastPacket(o); /* This transformer is more for fixing issues which we find hard at packet level :) */ if (info.isActive()) { if (info.get(ProtocolInfo.class).getPipeline().filter(o, list)) { return; } } } list.add(o); } }
ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline(); user.clearStoredObjects(); pipeline.cleanPipes(); if (protocols == null) { } else { for (Pair<Integer, Protocol> prot : protocols) { pipeline.add(prot.getValue()); pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId)); for (Protocol protocol : pipeline.pipes()) { protocol.init(user);
@Override protected void encode(ChannelHandlerContext ctx, Object o, List list) throws Exception { // Split chunks bulk packet up in to single chunks packets before it reached the encoder. // This will prevent issues with several plugins and other protocol handlers due to the chunks being sent twice. // It also sends the chunks in the right order possible resolving some issues with added chunks/block/entity data. if (!(o instanceof ByteBuf)) { info.setLastPacket(o); /* This transformer is more for fixing issues which we find hard at packet level :) */ if (info.isActive()) { if (info.get(ProtocolInfo.class).getPipeline().filter(o, list)) { return; } } } list.add(o); } }
PacketWrapper wrapper = new PacketWrapper(id, oldPacket, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper); wrapper.writeToBuffer(bytebuf); } catch (Exception e) {
@Override public void run() { for (UserConnection info : Via.getManager().getPortedPlayers().values()) { if (info.has(ProtocolInfo.class) && info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket(); if (nextIdleUpdate <= System.currentTimeMillis()) { if (info.getChannel().isOpen()) { Via.getManager().getProviders().get(MovementTransmitterProvider.class).sendPlayer(info); } } } } } }
@Override protected void initChannel(Channel channel) throws Exception { initChannel.invoke(original, channel); UserConnection user = new UserConnection(channel); new ProtocolPipeline(user); // We need to add a separated handler because Velocity uses pipeline().get(MINECRAFT_DECODER) channel.pipeline().addBefore("minecraft-encoder", "via-encoder", new VelocityEncodeHandler(user)); channel.pipeline().addBefore("minecraft-decoder", "via-decoder", new VelocityDecodeHandler(user)); } }
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper); wrapper.writeToBuffer(newPacket);
@Override public Chunk read(ByteBuf input, ClientChunks param) throws Exception { boolean replacePistons = param.getUser().get(ProtocolInfo.class).getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons(); int replacementId = Via.getConfig().getPistonReplacementId();
@Override protected void initChannel(SocketChannel socketChannel) throws Exception { UserConnection info = new UserConnection(socketChannel); // init protocol new ProtocolPipeline(info); // Add originals this.method.invoke(this.original, socketChannel); HandlerConstructor constructor = ClassGenerator.getConstructor(); // Add our transformers MessageToByteEncoder encoder = constructor.newEncodeHandler(info, (MessageToByteEncoder) socketChannel.pipeline().get("encoder")); ByteToMessageDecoder decoder = constructor.newDecodeHandler(info, (ByteToMessageDecoder) socketChannel.pipeline().get("decoder")); BukkitPacketHandler chunkHandler = new BukkitPacketHandler(info); socketChannel.pipeline().replace("encoder", "encoder", encoder); socketChannel.pipeline().replace("decoder", "decoder", decoder); socketChannel.pipeline().addAfter("packet_handler", "viaversion_packet_handler", chunkHandler); } }
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper); wrapper.writeToBuffer(newPacket);
@EventHandler public void onServerConnect(ServerConnectEvent event) { // Ignore if it doesn't exist (Like BungeeCord 1.8) if (setMainHand == null || getSettings == null) return; UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null) return; try { if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { Object settings = getSettings.invoke(event.getPlayer()); if (settings != null) { if (user.has(EntityTracker.class)) { setMainHand.invoke(settings, user.get(EntityTracker.class).getMainHand()); } } } } catch (Exception e) { e.printStackTrace(); } } }
@Override protected void initChannel(Channel channel) throws Exception { // Ensure ViaVersion is loaded if (ProtocolRegistry.SERVER_PROTOCOL != -1 && channel instanceof SocketChannel) { // channel can be LocalChannel on internal server UserConnection info = new UserConnection((SocketChannel) channel); // init protocol new ProtocolPipeline(info); // Add originals this.method.invoke(this.original, channel); // Add our transformers MessageToByteEncoder encoder = new SpongeEncodeHandler(info, (MessageToByteEncoder) channel.pipeline().get("encoder")); ByteToMessageDecoder decoder = new SpongeDecodeHandler(info, (ByteToMessageDecoder) channel.pipeline().get("decoder")); SpongePacketHandler chunkHandler = new SpongePacketHandler(info); channel.pipeline().replace("encoder", "encoder", encoder); channel.pipeline().replace("decoder", "decoder", decoder); channel.pipeline().addAfter("packet_handler", "viaversion_packet_handler", chunkHandler); } else { this.method.invoke(this.original, channel); } } }
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper); wrapper.writeToBuffer(newPacket);
@Override public Chunk read(ByteBuf input, ClientWorld world) throws Exception { boolean replacePistons = world.getUser().get(ProtocolInfo.class).getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons(); int replacementId = Via.getConfig().getPistonReplacementId();