From c5a772d6db2b826a723913f2b57c20a94c749504 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Sat, 29 Apr 2023 22:31:49 +0200 Subject: [PATCH] Removed now not needed anymore code --- .../FixedUnconnectedPingEncoder.java | 60 --------------- .../FixedUnconnectedPongDecoder.java | 74 ------------------- .../proxy/session/BedrockProxyConnection.java | 11 --- 3 files changed, 145 deletions(-) delete mode 100644 src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/raknet_fix/FixedUnconnectedPingEncoder.java delete mode 100644 src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/raknet_fix/FixedUnconnectedPongDecoder.java diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/raknet_fix/FixedUnconnectedPingEncoder.java b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/raknet_fix/FixedUnconnectedPingEncoder.java deleted file mode 100644 index 51c75f1..0000000 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/raknet_fix/FixedUnconnectedPingEncoder.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.raphimc.viaproxy.protocolhack.viaproxy.raknet_fix; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelOutboundHandlerAdapter; -import io.netty.channel.ChannelPromise; -import io.netty.channel.socket.DatagramPacket; -import org.cloudburstmc.netty.channel.raknet.RakClientChannel; -import org.cloudburstmc.netty.channel.raknet.RakPing; -import org.cloudburstmc.netty.channel.raknet.config.RakChannelOption; - -import static org.cloudburstmc.netty.channel.raknet.RakConstants.ID_UNCONNECTED_PING; - -// Temporary fix until the library fixes the issue -public class FixedUnconnectedPingEncoder extends ChannelOutboundHandlerAdapter { - - private final RakClientChannel rakClientChannel; - - public FixedUnconnectedPingEncoder(final RakClientChannel rakClientChannel) { - this.rakClientChannel = rakClientChannel; - } - - @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { - if (!(msg instanceof RakPing)) { - ctx.write(msg, promise); - return; - } - - RakPing ping = (RakPing) msg; - ByteBuf magicBuf = this.rakClientChannel.config().getOption(RakChannelOption.RAK_UNCONNECTED_MAGIC); - long guid = this.rakClientChannel.config().getOption(RakChannelOption.RAK_GUID); - - ByteBuf pingBuffer = ctx.alloc().ioBuffer(magicBuf.readableBytes() + 17); - pingBuffer.writeByte(ID_UNCONNECTED_PING); - pingBuffer.writeLong(ping.getPingTime()); - pingBuffer.writeBytes(magicBuf, magicBuf.readerIndex(), magicBuf.readableBytes()); - pingBuffer.writeLong(guid); - ctx.write(new DatagramPacket(pingBuffer, ping.getSender())); - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/raknet_fix/FixedUnconnectedPongDecoder.java b/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/raknet_fix/FixedUnconnectedPongDecoder.java deleted file mode 100644 index 7f7c9dc..0000000 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/viaproxy/raknet_fix/FixedUnconnectedPongDecoder.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy - * Copyright (C) 2023 RK_01/RaphiMC and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.raphimc.viaproxy.protocolhack.viaproxy.raknet_fix; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufUtil; -import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.socket.DatagramPacket; -import org.cloudburstmc.netty.channel.raknet.RakClientChannel; -import org.cloudburstmc.netty.channel.raknet.RakPong; -import org.cloudburstmc.netty.channel.raknet.config.RakChannelOption; -import org.cloudburstmc.netty.handler.codec.raknet.AdvancedChannelInboundHandler; - -import static org.cloudburstmc.netty.channel.raknet.RakConstants.ID_UNCONNECTED_PONG; - -// Temporary fix until the library fixes the issue -public class FixedUnconnectedPongDecoder extends AdvancedChannelInboundHandler { - - private final RakClientChannel rakClientChannel; - - public FixedUnconnectedPongDecoder(final RakClientChannel rakClientChannel) { - this.rakClientChannel = rakClientChannel; - } - - @Override - protected boolean acceptInboundMessage(ChannelHandlerContext ctx, Object msg) throws Exception { - if (!super.acceptInboundMessage(ctx, msg)) { - return false; - } - - DatagramPacket packet = (DatagramPacket) msg; - ByteBuf buf = packet.content(); - return buf.isReadable() && buf.getUnsignedByte(buf.readerIndex()) == ID_UNCONNECTED_PONG; - } - - @Override - protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket packet) throws Exception { - ByteBuf buf = packet.content(); - buf.readUnsignedByte(); // Packet ID - - long pingTime = buf.readLong(); - long guid = buf.readLong(); - - ByteBuf magicBuf = this.rakClientChannel.config().getOption(RakChannelOption.RAK_UNCONNECTED_MAGIC); - if (!buf.isReadable(magicBuf.readableBytes()) || !ByteBufUtil.equals(buf.readSlice(magicBuf.readableBytes()), magicBuf)) { - // Magic does not match - return; - } - - ByteBuf pongData = Unpooled.EMPTY_BUFFER; - if (buf.isReadable(2)) { // Length - pongData = buf.readRetainedSlice(buf.readUnsignedShort()); - } - ctx.fireChannelRead(new RakPong(pingTime, guid, pongData, packet.sender())); - } - -} diff --git a/src/main/java/net/raphimc/viaproxy/proxy/session/BedrockProxyConnection.java b/src/main/java/net/raphimc/viaproxy/proxy/session/BedrockProxyConnection.java index c5c1ba6..69af3fc 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/session/BedrockProxyConnection.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/session/BedrockProxyConnection.java @@ -33,13 +33,8 @@ import net.raphimc.netminecraft.util.ServerAddress; import net.raphimc.viaprotocolhack.netty.VPHPipeline; import net.raphimc.viaprotocolhack.netty.viabedrock.PingEncapsulationCodec; import net.raphimc.viaprotocolhack.util.VersionEnum; -import net.raphimc.viaproxy.protocolhack.viaproxy.raknet_fix.FixedUnconnectedPingEncoder; -import net.raphimc.viaproxy.protocolhack.viaproxy.raknet_fix.FixedUnconnectedPongDecoder; import org.cloudburstmc.netty.channel.raknet.RakChannelFactory; -import org.cloudburstmc.netty.channel.raknet.RakClientChannel; import org.cloudburstmc.netty.channel.raknet.config.RakChannelOption; -import org.cloudburstmc.netty.handler.codec.raknet.common.UnconnectedPingEncoder; -import org.cloudburstmc.netty.handler.codec.raknet.common.UnconnectedPongDecoder; import java.net.InetSocketAddress; import java.util.concurrent.ThreadLocalRandom; @@ -93,12 +88,6 @@ public class BedrockProxyConnection extends ProxyConnection { this.initialize(new Bootstrap()); } this.getChannel().bind(new InetSocketAddress(0)).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE).syncUninterruptibly(); - final RakClientChannel channel = (RakClientChannel) this.getChannel(); - - { // Temporary fix for the ping encoder - channel.parent().pipeline().replace(UnconnectedPingEncoder.NAME, UnconnectedPingEncoder.NAME, new FixedUnconnectedPingEncoder(channel)); - channel.parent().pipeline().replace(UnconnectedPongDecoder.NAME, UnconnectedPongDecoder.NAME, new FixedUnconnectedPongDecoder(channel)); - } this.getChannel().pipeline().replace(VPHPipeline.VIABEDROCK_FRAME_ENCAPSULATION_HANDLER_NAME, "ping_encapsulation", new PingEncapsulationCodec(serverAddress.toSocketAddress())); this.getChannel().pipeline().remove(VPHPipeline.VIABEDROCK_PACKET_ENCAPSULATION_HANDLER_NAME);