2023-11-07 12:47:27 +01:00
From c8ca8bce23ed4223c0830d5ab3b2bed51c755e3d Mon Sep 17 00:00:00 2001
2016-05-28 18:34:39 +02:00
From: Daniel Naylor <git@drnaylor.co.uk>
2016-10-25 18:57:11 +02:00
Date: Tue, 25 Oct 2016 12:23:07 -0400
2016-05-28 18:34:39 +02:00
Subject: [PATCH] Add support for FML with IP Forwarding enabled
FML adds a \00FML\00 marker to the host field, so Forge can determine whether or not to start a Forge handshake, making way to allow vanilla clients to connect to Forge servers that don't need a client modification. However, Bungee also uses the field, and the two implementations collide when using Spigot.
The original fix was to not send the FML information at the same time as the IP forwarding, you could have one or the other, but not both. This was OK, as no FML servers supported IP forwarding as of time of the patch. This was implemented in commit 4809f1f80ace9ae87b91453c8887c70f5e098bd0.
However, there is now at least one Forge coremod that intends to support IP forwarding. To be able to support Forge with IP forwarding, a way to be able to support the FML token (and any other host data) is needed. This adds a property to the user Game Profile to forward on whether the user is a FML client, along with whether there is any extra data.
No breaking changes occur due to this patch.
diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
2023-11-07 12:47:27 +01:00
index 137d93cb..ce925db2 100644
2016-05-28 18:34:39 +02:00
--- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
+++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
2021-11-12 20:47:23 +01:00
@@ -7,6 +7,7 @@ import io.netty.buffer.ByteBufAllocator;
2020-01-21 18:36:22 +01:00
import java.net.InetSocketAddress;
2021-11-12 20:47:23 +01:00
import java.nio.charset.StandardCharsets;
2018-11-04 21:27:05 +01:00
import java.util.Locale;
+import java.util.Arrays; // Waterfall
2016-05-28 18:34:39 +02:00
import java.util.Queue;
import java.util.Set;
import java.util.UUID;
2023-11-07 12:47:27 +01:00
@@ -111,15 +112,39 @@ public class ServerConnector extends PacketHandler
2021-05-26 22:18:14 +02:00
String newHost = copiedHandshake.getHost() + "\00" + AddressUtil.sanitizeAddress( user.getAddress() ) + "\00" + user.getUUID();
2016-05-28 18:34:39 +02:00
LoginResult profile = user.getPendingConnection().getLoginProfile();
+
+ // Handle properties.
2022-06-07 19:12:20 +02:00
+ net.md_5.bungee.protocol.Property[] properties = new net.md_5.bungee.protocol.Property[0];
2016-05-28 18:34:39 +02:00
+
if ( profile != null && profile.getProperties() != null && profile.getProperties().length > 0 )
{
- newHost += "\00" + BungeeCord.getInstance().gson.toJson( profile.getProperties() );
+ properties = profile.getProperties();
}
+
+ if ( user.getForgeClientHandler().isFmlTokenInHandshake() )
+ {
+ // Get the current properties and copy them into a slightly bigger array.
2022-06-07 19:12:20 +02:00
+ net.md_5.bungee.protocol.Property[] newp = Arrays.copyOf( properties, properties.length + 2 );
2016-05-28 18:34:39 +02:00
+
+ // Add a new profile property that specifies that this user is a Forge user.
2022-06-07 19:12:20 +02:00
+ newp[newp.length - 2] = new net.md_5.bungee.protocol.Property( ForgeConstants.FML_LOGIN_PROFILE, "true", null );
2016-05-28 18:34:39 +02:00
+
+ // If we do not perform the replacement, then the IP Forwarding code in Spigot et. al. will try to split on this prematurely.
2022-06-07 19:12:20 +02:00
+ newp[newp.length - 1] = new net.md_5.bungee.protocol.Property( ForgeConstants.EXTRA_DATA, user.getExtraDataInHandshake().replaceAll( "\0", "\1"), "" );
2016-05-28 18:34:39 +02:00
+
+ // All done.
+ properties = newp;
+ }
+
+ // If we touched any properties, then append them
+ if (properties.length > 0) {
+ newHost += "\00" + BungeeCord.getInstance().gson.toJson(properties);
+ }
+
copiedHandshake.setHost( newHost );
} else if ( !user.getExtraDataInHandshake().isEmpty() )
{
2018-04-02 11:21:24 +02:00
- // Only restore the extra data if IP forwarding is off.
2016-05-28 18:34:39 +02:00
- // TODO: Add support for this data with IP forwarding.
+ // Restore the extra data
copiedHandshake.setHost( copiedHandshake.getHost() + user.getExtraDataInHandshake() );
}
diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
2023-11-04 02:12:26 +01:00
index 04143a46..12bd18ed 100644
2016-05-28 18:34:39 +02:00
--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java
+++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
2023-11-04 02:12:26 +01:00
@@ -170,9 +170,12 @@ public final class UserConnection implements ProxiedPlayer
2016-05-28 18:34:39 +02:00
forgeClientHandler = new ForgeClientHandler( this );
+ // No-config FML handshake marker.
// Set whether the connection has a 1.8 FML marker in the handshake.
- forgeClientHandler.setFmlTokenInHandshake( this.getPendingConnection().getExtraDataInHandshake().contains( ForgeConstants.FML_HANDSHAKE_TOKEN ) );
2023-11-04 02:12:26 +01:00
-
2016-10-25 18:57:11 +02:00
+ if (this.getPendingConnection().getExtraDataInHandshake().contains( ForgeConstants.FML_HANDSHAKE_TOKEN ))
2016-05-28 18:34:39 +02:00
+ {
+ forgeClientHandler.setFmlTokenInHandshake( true );
+ }
2023-11-04 02:12:26 +01:00
return BungeeCord.getInstance().addConnection( this );
2016-05-28 18:34:39 +02:00
}
diff --git a/proxy/src/main/java/net/md_5/bungee/forge/ForgeConstants.java b/proxy/src/main/java/net/md_5/bungee/forge/ForgeConstants.java
2017-08-04 15:57:11 +02:00
index 6dca2048..f5253b89 100644
2016-05-28 18:34:39 +02:00
--- a/proxy/src/main/java/net/md_5/bungee/forge/ForgeConstants.java
+++ b/proxy/src/main/java/net/md_5/bungee/forge/ForgeConstants.java
@@ -14,6 +14,10 @@ public class ForgeConstants
public static final String FML_HANDSHAKE_TAG = "FML|HS";
public static final String FML_REGISTER = "REGISTER";
+ // Game profile key
+ public static final String FML_LOGIN_PROFILE = "forgeClient";
+ public static final String EXTRA_DATA = "extraData";
+
/**
* The FML 1.8 handshake token.
*/
--
2023-11-04 02:12:26 +01:00
2.42.1
2016-05-28 18:34:39 +02:00