From b246d5b4d1e31488451e1c7fe4ec4945e02495fe Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Tue, 28 Dec 2021 15:36:45 -0500 Subject: [PATCH] Spigot: Temporarily work around issue where channel handlers don't see the connection This 'fixes' issues where Floodgate may not work when the first player joins. --- .../platform/spigot/GeyserSpigotInjector.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotInjector.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotInjector.java index 7f390f9d8..1e87e9332 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotInjector.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotInjector.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.platform.spigot; +import com.github.steveice10.mc.protocol.MinecraftProtocol; import com.viaversion.viaversion.bukkit.handlers.BukkitChannelInitializer; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.*; @@ -34,10 +35,12 @@ import org.bukkit.Bukkit; import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.network.netty.GeyserInjector; import org.geysermc.geyser.network.netty.LocalServerChannelWrapper; +import org.geysermc.geyser.network.netty.LocalSession; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; +import java.net.InetAddress; import java.util.List; public class GeyserSpigotInjector extends GeyserInjector { @@ -128,6 +131,8 @@ public class GeyserSpigotInjector extends GeyserInjector { allServerChannels.add(channelFuture); this.localChannel = channelFuture; this.serverSocketAddress = channelFuture.channel().localAddress(); + + workAroundWeirdBug(bootstrap); } @SuppressWarnings("unchecked") @@ -158,6 +163,18 @@ public class GeyserSpigotInjector extends GeyserInjector { return childHandler; } + /** + * Work around an odd bug where the first connection might not initialize all channel handlers on the main pipeline - + * send a dummy status request down that acts as the first connection, then. + * For the future, if someone wants to properly fix this - as of December 28, 2021, it happens on 1.16.5/1.17.1/1.18.1 EXCEPT Spigot 1.16.5 + */ + private void workAroundWeirdBug(GeyserBootstrap bootstrap) { + LocalSession session = new LocalSession(bootstrap.getGeyserConfig().getRemote().getAddress(), + bootstrap.getGeyserConfig().getRemote().getPort(), this.serverSocketAddress, + InetAddress.getLoopbackAddress().getHostAddress(), new MinecraftProtocol()); + session.connect(); + } + @Override public void shutdown() { if (this.allServerChannels != null) {