Skip to content

Commit

Permalink
Added support for 3D Shareware clients
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Oct 15, 2024
1 parent 920de17 commit fa9b6fd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,34 @@

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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,6 +64,11 @@ protected void initChannel(Channel channel) {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void handleHandshake(final C2SHandshakingClientIntentionPacket packet) {
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!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ protected void initChannel(Channel channel) {

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());
}
Expand All @@ -76,7 +72,10 @@ protected void initChannel(Channel channel) {
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);
Expand Down

0 comments on commit fa9b6fd

Please sign in to comment.