3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Add Geyser listener into listeners set in BungeeCord

Will fix ViaVersion compatibility when https://github.com/ViaVersion/ViaVersion/pull/2698 gets merged.
Dieser Commit ist enthalten in:
Camotoy 2021-10-02 08:53:36 -04:00
Ursprung b58cbd00bc
Commit f1098a9207
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F

Datei anzeigen

@ -39,7 +39,9 @@ import net.md_5.bungee.netty.PipelineUtils;
import org.geysermc.connector.bootstrap.GeyserBootstrap; import org.geysermc.connector.bootstrap.GeyserBootstrap;
import org.geysermc.connector.common.GeyserInjector; import org.geysermc.connector.common.GeyserInjector;
import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Set;
public class GeyserBungeeInjector extends GeyserInjector { public class GeyserBungeeInjector extends GeyserInjector {
private final ProxyServer proxy; private final ProxyServer proxy;
@ -47,12 +49,14 @@ public class GeyserBungeeInjector extends GeyserInjector {
* Set as a variable so it is only set after the proxy has finished initializing * Set as a variable so it is only set after the proxy has finished initializing
*/ */
private ChannelInitializer<Channel> channelInitializer = null; private ChannelInitializer<Channel> channelInitializer = null;
private Set<Channel> bungeeChannels = null;
public GeyserBungeeInjector(ProxyServer proxy) { public GeyserBungeeInjector(ProxyServer proxy) {
this.proxy = proxy; this.proxy = proxy;
} }
@Override @Override
@SuppressWarnings("unchecked")
protected void initializeLocalChannel0(GeyserBootstrap bootstrap) throws Exception { protected void initializeLocalChannel0(GeyserBootstrap bootstrap) throws Exception {
// TODO - allow Geyser to specify its own listener info properties // TODO - allow Geyser to specify its own listener info properties
if (proxy.getConfig().getListeners().size() != 1) { if (proxy.getConfig().getListeners().size() != 1) {
@ -97,6 +101,13 @@ public class GeyserBungeeInjector extends GeyserInjector {
bootstrap.getGeyserConfig().getRemote().isUseProxyProtocol() // If Geyser is expecting HAProxy, so should the Bungee end bootstrap.getGeyserConfig().getRemote().isUseProxyProtocol() // If Geyser is expecting HAProxy, so should the Bungee end
); );
// The field that stores all listeners in BungeeCord
// As of https://github.com/ViaVersion/ViaVersion/pull/2698 ViaVersion adds a wrapper to this field to
// add its connections
Field listenerField = proxyClass.getDeclaredField("listeners");
listenerField.setAccessible(true);
bungeeChannels = (Set<Channel>) listenerField.get(proxy);
// This method is what initializes the connection in Java Edition, after Netty is all set. // This method is what initializes the connection in Java Edition, after Netty is all set.
Method initChannel = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class); Method initChannel = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class);
initChannel.setAccessible(true); initChannel.setAccessible(true);
@ -116,7 +127,7 @@ public class GeyserBungeeInjector extends GeyserInjector {
if (channelInitializer == null) { if (channelInitializer == null) {
// Proxy has finished initializing; we can safely grab this variable without fear of plugins modifying it // Proxy has finished initializing; we can safely grab this variable without fear of plugins modifying it
// (ViaVersion replaces this to inject) // (Older versions of ViaVersion replace this to inject)
channelInitializer = PipelineUtils.SERVER_CHILD; channelInitializer = PipelineUtils.SERVER_CHILD;
} }
initChannel.invoke(channelInitializer, ch); initChannel.invoke(channelInitializer, ch);
@ -129,6 +140,16 @@ public class GeyserBungeeInjector extends GeyserInjector {
.syncUninterruptibly(); .syncUninterruptibly();
this.localChannel = channelFuture; this.localChannel = channelFuture;
this.bungeeChannels.add(this.localChannel.channel());
this.serverSocketAddress = channelFuture.channel().localAddress(); this.serverSocketAddress = channelFuture.channel().localAddress();
} }
@Override
public void shutdown() {
if (this.localChannel != null && this.bungeeChannels != null) {
this.bungeeChannels.remove(this.localChannel.channel());
this.bungeeChannels = null;
}
super.shutdown();
}
} }