From e93323ddbc8f22f1efa0647e2fc03adc66c7c488 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 12 May 2018 08:24:06 +1000 Subject: [PATCH] #2420: Disable forge support by default --- .../main/java/net/md_5/bungee/BungeeCord.java | 11 +++- .../java/net/md_5/bungee/ServerConnector.java | 60 ++++++++++--------- .../net/md_5/bungee/conf/Configuration.java | 2 + .../bungee/connection/UpstreamBridge.java | 36 ++++++----- 4 files changed, 61 insertions(+), 48 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 5405a537..77873239 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -268,9 +268,14 @@ public class BungeeCord extends ProxyServer pluginManager.loadPlugins(); config.load(); - registerChannel( ForgeConstants.FML_TAG ); - registerChannel( ForgeConstants.FML_HANDSHAKE_TAG ); - registerChannel( ForgeConstants.FORGE_REGISTER ); + if ( config.isForgeSupport() ) + { + registerChannel( ForgeConstants.FML_TAG ); + registerChannel( ForgeConstants.FML_HANDSHAKE_TAG ); + registerChannel( ForgeConstants.FORGE_REGISTER ); + + getLogger().warning( "MinecraftForge support is currently unmaintained and may have unresolved issues. Please use at your own risk." ); + } isRunning = true; diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index b2eef8e6..b34247ce 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -311,47 +311,49 @@ public class ServerConnector extends PacketHandler @Override public void handle(PluginMessage pluginMessage) throws Exception { - if ( pluginMessage.getTag().equals( ForgeConstants.FML_REGISTER ) ) + if ( BungeeCord.getInstance().config.isForgeSupport() ) { - Set channels = ForgeUtils.readRegisteredChannels( pluginMessage ); - boolean isForgeServer = false; - for ( String channel : channels ) + if ( pluginMessage.getTag().equals( ForgeConstants.FML_REGISTER ) ) { - if ( channel.equals( ForgeConstants.FML_HANDSHAKE_TAG ) ) + Set channels = ForgeUtils.readRegisteredChannels( pluginMessage ); + boolean isForgeServer = false; + for ( String channel : channels ) { - // If we have a completed handshake and we have been asked to register a FML|HS - // packet, let's send the reset packet now. Then, we can continue the message sending. - // The handshake will not be complete if we reset this earlier. - if ( user.getServer() != null && user.getForgeClientHandler().isHandshakeComplete() ) + if ( channel.equals( ForgeConstants.FML_HANDSHAKE_TAG ) ) { - user.getForgeClientHandler().resetHandshake(); - } + // If we have a completed handshake and we have been asked to register a FML|HS + // packet, let's send the reset packet now. Then, we can continue the message sending. + // The handshake will not be complete if we reset this earlier. + if ( user.getServer() != null && user.getForgeClientHandler().isHandshakeComplete() ) + { + user.getForgeClientHandler().resetHandshake(); + } - isForgeServer = true; - break; + isForgeServer = true; + break; + } + } + + if ( isForgeServer && !this.handshakeHandler.isServerForge() ) + { + // We now set the server-side handshake handler for the client to this. + handshakeHandler.setServerAsForgeServer(); + user.setForgeServerHandler( handshakeHandler ); } } - if ( isForgeServer && !this.handshakeHandler.isServerForge() ) + if ( pluginMessage.getTag().equals( ForgeConstants.FML_HANDSHAKE_TAG ) || pluginMessage.getTag().equals( ForgeConstants.FORGE_REGISTER ) ) { - // We now set the server-side handshake handler for the client to this. - handshakeHandler.setServerAsForgeServer(); - user.setForgeServerHandler( handshakeHandler ); + this.handshakeHandler.handle( pluginMessage ); + + // We send the message as part of the handler, so don't send it here. + throw CancelSendSignal.INSTANCE; } } - if ( pluginMessage.getTag().equals( ForgeConstants.FML_HANDSHAKE_TAG ) || pluginMessage.getTag().equals( ForgeConstants.FORGE_REGISTER ) ) - { - this.handshakeHandler.handle( pluginMessage ); - - // We send the message as part of the handler, so don't send it here. - throw CancelSendSignal.INSTANCE; - } else - { - // We have to forward these to the user, especially with Forge as stuff might break - // This includes any REGISTER messages we intercepted earlier. - user.unsafe().sendPacket( pluginMessage ); - } + // We have to forward these to the user, especially with Forge as stuff might break + // This includes any REGISTER messages we intercepted earlier. + user.unsafe().sendPacket( pluginMessage ); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java index 907246a9..1ee82eec 100644 --- a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java +++ b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java @@ -58,6 +58,7 @@ public class Configuration implements ProxyConfig private Favicon favicon; private int compressionThreshold = 256; private boolean preventProxyConnections; + private boolean forgeSupport; public void load() { @@ -86,6 +87,7 @@ public class Configuration implements ProxyConfig ipForward = adapter.getBoolean( "ip_forward", ipForward ); compressionThreshold = adapter.getInt( "network_compression_threshold", compressionThreshold ); preventProxyConnections = adapter.getBoolean( "prevent_proxy_connections", preventProxyConnections ); + forgeSupport = adapter.getBoolean( "forge_support", forgeSupport ); disabledCommands = new CaseInsensitiveSet( (Collection) adapter.getList( "disabled_commands", Arrays.asList( "disabledcommandhere" ) ) ); diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 19a52458..92d22502 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -188,25 +188,29 @@ public class UpstreamBridge extends PacketHandler { throw CancelSendSignal.INSTANCE; } - // Hack around Forge race conditions - if ( pluginMessage.getTag().equals( "FML" ) && pluginMessage.getStream().readUnsignedByte() == 1 ) - { - throw CancelSendSignal.INSTANCE; - } - // We handle forge handshake messages if forge support is enabled. - if ( pluginMessage.getTag().equals( ForgeConstants.FML_HANDSHAKE_TAG ) ) + if ( BungeeCord.getInstance().config.isForgeSupport() ) { - // Let our forge client handler deal with this packet. - con.getForgeClientHandler().handle( pluginMessage ); - throw CancelSendSignal.INSTANCE; - } + // Hack around Forge race conditions + if ( pluginMessage.getTag().equals( "FML" ) && pluginMessage.getStream().readUnsignedByte() == 1 ) + { + throw CancelSendSignal.INSTANCE; + } - if ( con.getServer() != null && !con.getServer().isForgeServer() && pluginMessage.getData().length > Short.MAX_VALUE ) - { - // Drop the packet if the server is not a Forge server and the message was > 32kiB (as suggested by @jk-5) - // Do this AFTER the mod list, so we get that even if the intial server isn't modded. - throw CancelSendSignal.INSTANCE; + // We handle forge handshake messages if forge support is enabled. + if ( pluginMessage.getTag().equals( ForgeConstants.FML_HANDSHAKE_TAG ) ) + { + // Let our forge client handler deal with this packet. + con.getForgeClientHandler().handle( pluginMessage ); + throw CancelSendSignal.INSTANCE; + } + + if ( con.getServer() != null && !con.getServer().isForgeServer() && pluginMessage.getData().length > Short.MAX_VALUE ) + { + // Drop the packet if the server is not a Forge server and the message was > 32kiB (as suggested by @jk-5) + // Do this AFTER the mod list, so we get that even if the intial server isn't modded. + throw CancelSendSignal.INSTANCE; + } } PluginMessageEvent event = new PluginMessageEvent( con, con.getServer(), pluginMessage.getTag(), pluginMessage.getData().clone() );