From fa9b6fd976821bb8a8b247891afbafd9e61e53ba Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Tue, 15 Oct 2024 20:42:03 +0200 Subject: [PATCH] Added support for 3D Shareware clients --- README.md | 1 + .../impl/ViaProxyVLPipeline.java | 5 ++--- .../providers/ViaProxyVersionProvider.java | 21 +++++++++++++++++-- .../Client2ProxyChannelInitializer.java | 11 ++++++++++ .../client2proxy/Client2ProxyHandler.java | 2 +- .../Proxy2ServerChannelInitializer.java | 9 ++++---- 6 files changed, 38 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6306671..5184970 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ For a full user guide go to the [Usage for Players](#usage-for-players-gui) sect ## Supported Client versions - Release (1.7.2 - 1.21.1) +- April Fools (3D Shareware) - Bedrock Edition (Requires the [Geyser plugin](https://geysermc.org/download)) - Beta 1.7.3 (Requires the [Beta2Release plugin](https://github.com/ViaVersionAddons/ViaProxyBeta2Release)) - Classic, Alpha, Beta, Release 1.0 - 1.6.4 (Only passthrough) diff --git a/src/main/java/net/raphimc/viaproxy/protocoltranslator/impl/ViaProxyVLPipeline.java b/src/main/java/net/raphimc/viaproxy/protocoltranslator/impl/ViaProxyVLPipeline.java index 4931ba9..ee8b477 100644 --- a/src/main/java/net/raphimc/viaproxy/protocoltranslator/impl/ViaProxyVLPipeline.java +++ b/src/main/java/net/raphimc/viaproxy/protocoltranslator/impl/ViaProxyVLPipeline.java @@ -18,15 +18,14 @@ package net.raphimc.viaproxy.protocoltranslator.impl; import com.viaversion.viaversion.api.connection.UserConnection; -import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import io.netty.channel.ChannelHandler; import net.raphimc.netminecraft.constants.MCPipeline; import net.raphimc.vialoader.netty.VLPipeline; public class ViaProxyVLPipeline extends VLPipeline { - public ViaProxyVLPipeline(UserConnection user, ProtocolVersion version) { - super(user, version); + public ViaProxyVLPipeline(final UserConnection user) { + super(user); } @Override diff --git a/src/main/java/net/raphimc/viaproxy/protocoltranslator/providers/ViaProxyVersionProvider.java b/src/main/java/net/raphimc/viaproxy/protocoltranslator/providers/ViaProxyVersionProvider.java index d4640f0..1600d18 100644 --- a/src/main/java/net/raphimc/viaproxy/protocoltranslator/providers/ViaProxyVersionProvider.java +++ b/src/main/java/net/raphimc/viaproxy/protocoltranslator/providers/ViaProxyVersionProvider.java @@ -19,17 +19,34 @@ package net.raphimc.viaproxy.protocoltranslator.providers; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import com.viaversion.viaversion.api.protocol.version.VersionType; +import com.viaversion.viaversion.protocol.RedirectProtocolVersion; import com.viaversion.viaversion.protocol.version.BaseVersionProvider; import net.raphimc.viaproxy.proxy.session.ProxyConnection; public class ViaProxyVersionProvider extends BaseVersionProvider { @Override - public ProtocolVersion getClosestServerProtocol(UserConnection connection) throws Exception { + public ProtocolVersion getClientProtocol(UserConnection connection) { + final ProtocolVersion clientProtocol = connection.getProtocolInfo().protocolVersion(); + if (clientProtocol.getVersionType() == VersionType.SPECIAL && ProtocolVersion.isRegistered(VersionType.SPECIAL, clientProtocol.getOriginalVersion())) { + return ProtocolVersion.getProtocol(VersionType.SPECIAL, clientProtocol.getOriginalVersion()); + } else { + return super.getClientProtocol(connection); + } + } + + @Override + public ProtocolVersion getClosestServerProtocol(UserConnection connection) { + final ProtocolVersion clientProtocol = connection.getProtocolInfo().protocolVersion(); if (connection.isClientSide()) { return ProxyConnection.fromUserConnection(connection).getServerVersion(); + } else if (clientProtocol.getVersionType() == VersionType.RELEASE) { + return clientProtocol; + } else if (clientProtocol instanceof RedirectProtocolVersion redirectProtocolVersion) { + return redirectProtocolVersion.getOrigin(); } else { - return super.getClosestServerProtocol(connection); + return ProtocolVersion.v1_7_2; } } diff --git a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyChannelInitializer.java b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyChannelInitializer.java index 6ab1b47..bbb3c65 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyChannelInitializer.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyChannelInitializer.java @@ -17,15 +17,21 @@ */ package net.raphimc.viaproxy.proxy.client2proxy; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.connection.UserConnectionImpl; +import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.handler.codec.haproxy.HAProxyMessageDecoder; import net.raphimc.netminecraft.constants.MCPipeline; +import net.raphimc.netminecraft.netty.codec.NoReadFlowControlHandler; import net.raphimc.netminecraft.netty.connection.MinecraftChannelInitializer; import net.raphimc.netminecraft.packet.registry.DefaultPacketRegistry; +import net.raphimc.vialoader.netty.VLPipeline; import net.raphimc.viaproxy.ViaProxy; import net.raphimc.viaproxy.plugins.events.Client2ProxyChannelInitializeEvent; import net.raphimc.viaproxy.plugins.events.types.ITyped; +import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyVLPipeline; import net.raphimc.viaproxy.proxy.client2proxy.passthrough.LegacyPassthroughInitialHandler; import java.util.function.Supplier; @@ -58,6 +64,11 @@ public class Client2ProxyChannelInitializer extends MinecraftChannelInitializer super.initChannel(channel); channel.attr(MCPipeline.PACKET_REGISTRY_ATTRIBUTE_KEY).set(new DefaultPacketRegistry(false, -1)); + final UserConnection user = new UserConnectionImpl(channel, false); + new ProtocolPipelineImpl(user); + channel.pipeline().addLast(new ViaProxyVLPipeline(user)); + channel.pipeline().addAfter(VLPipeline.VIA_CODEC_NAME, "via-" + MCPipeline.FLOW_CONTROL_HANDLER_NAME, new NoReadFlowControlHandler()); + if (ViaProxy.EVENT_MANAGER.call(new Client2ProxyChannelInitializeEvent(ITyped.Type.POST, channel, false)).isCancelled()) { channel.close(); } diff --git a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java index 88bca92..6d05023 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java @@ -120,7 +120,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler { this.proxyConnection.setClientVersion(clientVersion); this.proxyConnection.setC2pConnectionState(packet.intendedState.getConnectionState()); - if (!clientVersion.isKnown()) { + if (!ProtocolVersion.isRegistered(clientVersion.getVersionType(), clientVersion.getOriginalVersion())) { this.proxyConnection.kickClient("§cYour client version is not supported by ViaProxy!"); } diff --git a/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerChannelInitializer.java b/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerChannelInitializer.java index 9850d36..9c159a7 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerChannelInitializer.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerChannelInitializer.java @@ -62,10 +62,6 @@ public class Proxy2ServerChannelInitializer extends MinecraftChannelInitializer final ProxyConnection proxyConnection = ProxyConnection.fromChannel(channel); - final UserConnection user = new UserConnectionImpl(channel, true); - new ProtocolPipelineImpl(user); - proxyConnection.setUserConnection(user); - if (ViaProxy.getConfig().getBackendProxyUrl() != null && !proxyConnection.getServerVersion().equals(BedrockProtocolVersion.bedrockLatest)) { channel.pipeline().addLast(VIAPROXY_PROXY_HANDLER_NAME, this.getProxyHandler()); } @@ -76,7 +72,10 @@ public class Proxy2ServerChannelInitializer extends MinecraftChannelInitializer super.initChannel(channel); channel.attr(MCPipeline.PACKET_REGISTRY_ATTRIBUTE_KEY).set(new DefaultPacketRegistry(true, proxyConnection.getClientVersion().getVersion())); - channel.pipeline().addLast(new ViaProxyVLPipeline(user, proxyConnection.getServerVersion())); + final UserConnection user = new UserConnectionImpl(channel, true); + new ProtocolPipelineImpl(user); + proxyConnection.setUserConnection(user); + channel.pipeline().addLast(new ViaProxyVLPipeline(user)); channel.pipeline().addAfter(VLPipeline.VIA_CODEC_NAME, "via-" + MCPipeline.FLOW_CONTROL_HANDLER_NAME, new NoReadFlowControlHandler()); if (proxyConnection.getServerVersion().equals(BedrockProtocolVersion.bedrockLatest)) { channel.pipeline().remove(MCPipeline.COMPRESSION_HANDLER_NAME);