1
0
mirror of https://github.com/GeyserMC/Floodgate.git synced 2025-12-28 11:09:13 +00:00

FabricProxyLite support (#80)

* FabricProxyLite support - apply workaround of changing the limit of 255 to instead the Short.MAX_VALUE int, as also done by Paper/Spigot.
This commit is contained in:
onebeastchris
2023-02-12 20:58:09 +01:00
committed by GitHub
parent a1e9ff6f9c
commit def43a4b3f
5 changed files with 72 additions and 9 deletions

View File

@@ -12,7 +12,7 @@ import net.minecraft.server.network.ServerLoginPacketListenerImpl;
import org.geysermc.floodgate.MinecraftServerHolder;
import org.geysermc.floodgate.api.logger.FloodgateLogger;
import org.geysermc.floodgate.mixin.ConnectionMixin;
import org.geysermc.floodgate.mixin.ClientIntentionPacketMixin;
import org.geysermc.floodgate.mixin.ClientIntentionPacketMixinInterface;
import org.geysermc.floodgate.mixin_interface.ServerLoginPacketListenerSetter;
import com.mojang.authlib.GameProfile;
import io.netty.channel.ChannelHandlerContext;
@@ -48,7 +48,7 @@ public final class FabricDataHandler extends CommonDataHandler {
protected Object setHostname(Object handshakePacket, String hostname) {
// While it would be ideal to simply create a new handshake packet, the packet constructor
// does not allow us to set the protocol version
((ClientIntentionPacketMixin) handshakePacket).setAddress(hostname);
((ClientIntentionPacketMixinInterface) handshakePacket).setAddress(hostname);
return handshakePacket;
}

View File

@@ -2,13 +2,13 @@ package org.geysermc.floodgate.mixin;
import net.minecraft.network.protocol.handshake.ClientIntentionPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
@Mixin(ClientIntentionPacket.class)
public interface ClientIntentionPacketMixin {
@Accessor("hostName")
@Mutable
void setAddress(String address);
public class ClientIntentionPacketMixin {
@ModifyConstant(method = "<init>(Lnet/minecraft/network/FriendlyByteBuf;)V", constant = @Constant(intValue = 255))
private int floodgate$setHandshakeLength(int defaultValue) {
return Short.MAX_VALUE;
}
}

View File

@@ -0,0 +1,14 @@
package org.geysermc.floodgate.mixin;
import net.minecraft.network.protocol.handshake.ClientIntentionPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(ClientIntentionPacket.class)
public interface ClientIntentionPacketMixinInterface {
@Accessor("hostName")
@Mutable
void setAddress(String address);
}

View File

@@ -0,0 +1,47 @@
package org.geysermc.floodgate.util;
import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import java.util.List;
import java.util.Set;
public class MixinConfigPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {
}
@Override
public String getRefMapperConfig() {
return null;
}
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (mixinClassName.equals("org/geysermc/floodgate/mixin/ClientIntentionPacketMixin")) {
//returns true if fabricproxy-lite is present, therefore loading the mixin. If not present, the mixin will not be loaded.
return FabricLoader.getInstance().isModLoaded("fabricproxy-lite");
}
return true;
}
@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
}
@Override
public List<String> getMixins() {
return null;
}
@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
}

View File

@@ -5,11 +5,13 @@
"compatibilityLevel": "JAVA_16",
"mixins": [
"ChunkMapMixin",
"ClientIntentionPacketMixinInterface",
"ClientIntentionPacketMixin",
"ConnectionMixin",
"ServerConnectionListenerMixin",
"ServerLoginPacketListenerImplMixin"
],
"plugin": "org.geysermc.floodgate.util.MixinConfigPlugin",
"injectors": {
"defaultRequire": 1
}