This commit is contained in:
creeper123123321 2021-05-15 09:10:16 -03:00
parent 108268e8a6
commit 199296b2a6
4 changed files with 31 additions and 3 deletions

View File

@ -14,8 +14,9 @@ import com.viaversion.viaversion.exception.CancelException;
import com.viaversion.viaversion.protocols.base.BaseProtocol1_16;
import com.viaversion.viaversion.protocols.base.BaseProtocol1_7;
import com.viaversion.viaversion.protocols.base.BaseVersionProvider;
import io.netty.channel.ChannelPipeline;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.network.ClientConnection;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
@ -109,8 +110,7 @@ public abstract class VFVersionProvider extends BaseVersionProvider {
private void handleMulticonnectPing(UserConnection connection, ProtocolInfo info, boolean blocked, int serverVer) throws Exception {
if (info.getState() == State.STATUS
&& info.getProtocolVersion() == -1
&& connection.getChannel().pipeline().get(ClientConnection.class).getPacketListener()
.getClass().getName().startsWith("net.earthcomputer.multiconnect")
&& isMulticonnectHandler(connection.getChannel().pipeline())
&& (blocked || ProtocolUtils.isSupported(serverVer, getVersionForMulticonnect(serverVer)))) { // Intercept the connection
int multiconnectSuggestion = blocked ? -1 : getVersionForMulticonnect(serverVer);
getLogger().info("Sending " + ProtocolVersion.getProtocol(multiconnectSuggestion) + " for multiconnect version detector");
@ -121,6 +121,10 @@ public abstract class VFVersionProvider extends BaseVersionProvider {
}
}
protected boolean isMulticonnectHandler(ChannelPipeline pipe) {
return false;
}
private int getVersionForMulticonnect(int clientSideVersion) {
// https://github.com/ViaVersion/ViaVersion/blob/master/velocity/src/main/java/us/myles/ViaVersion/velocity/providers/VelocityVersionProvider.java
int[] compatibleProtocols = multiconnectSupportedVersions;

View File

@ -5,6 +5,8 @@ import com.viaversion.fabric.common.provider.VFVersionProvider;
import com.viaversion.fabric.mc115.ViaFabric;
import com.viaversion.fabric.mc115.service.ProtocolAutoDetector;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.ChannelPipeline;
import net.minecraft.network.ClientConnection;
import java.net.InetSocketAddress;
import java.util.concurrent.CompletableFuture;
@ -26,4 +28,10 @@ public class VRVersionProvider extends VFVersionProvider {
protected CompletableFuture<ProtocolVersion> detectVersion(InetSocketAddress address) {
return ProtocolAutoDetector.detectVersion(address);
}
@Override
protected boolean isMulticonnectHandler(ChannelPipeline pipe) {
return pipe.get(ClientConnection.class).getPacketListener()
.getClass().getName().startsWith("net.earthcomputer.multiconnect");
}
}

View File

@ -5,6 +5,8 @@ import com.viaversion.fabric.common.provider.VFVersionProvider;
import com.viaversion.fabric.mc116.ViaFabric;
import com.viaversion.fabric.mc116.service.ProtocolAutoDetector;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.ChannelPipeline;
import net.minecraft.network.ClientConnection;
import java.net.InetSocketAddress;
import java.util.concurrent.CompletableFuture;
@ -26,4 +28,10 @@ public class VRVersionProvider extends VFVersionProvider {
protected CompletableFuture<ProtocolVersion> detectVersion(InetSocketAddress address) {
return ProtocolAutoDetector.detectVersion(address);
}
@Override
protected boolean isMulticonnectHandler(ChannelPipeline pipe) {
return pipe.get(ClientConnection.class).getPacketListener()
.getClass().getName().startsWith("net.earthcomputer.multiconnect");
}
}

View File

@ -5,6 +5,8 @@ import com.viaversion.fabric.common.provider.VFVersionProvider;
import com.viaversion.fabric.mc117.ViaFabric;
import com.viaversion.fabric.mc117.service.ProtocolAutoDetector;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.ChannelPipeline;
import net.minecraft.network.ClientConnection;
import java.net.InetSocketAddress;
import java.util.concurrent.CompletableFuture;
@ -25,4 +27,10 @@ public class VRVersionProvider extends VFVersionProvider {
protected CompletableFuture<ProtocolVersion> detectVersion(InetSocketAddress address) {
return ProtocolAutoDetector.detectVersion(address);
}
@Override
protected boolean isMulticonnectHandler(ChannelPipeline pipe) {
return pipe.get(ClientConnection.class).getPacketListener()
.getClass().getName().startsWith("net.earthcomputer.multiconnect");
}
}