From c67d91943ca9b87da3f31bcf6b92f462a8032990 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 24 Dec 2020 03:47:29 +0200 Subject: [PATCH] HAProxy PROXY protocol support for downstream connections (#1688) * Implement downstream PROXY protocol support * Clarify the configuration version updating procedure * Bump netty-resolver-dns to 4.1.56.Final * Update Netty to .56 * Don't increase jar size by 2MB Co-authored-by: Camotoy <20743703+Camotoy@users.noreply.github.com> --- connector/pom.xml | 20 +++++++++++++++---- .../configuration/GeyserConfiguration.java | 4 +++- .../GeyserJacksonConfiguration.java | 3 +++ .../network/session/GeyserSession.java | 5 +++++ connector/src/main/resources/config.yml | 5 +++++ 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/connector/pom.xml b/connector/pom.xml index b71fdcb6a..ad34205ef 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -124,14 +124,26 @@ 26201a4 compile - - io.netty - netty-all - net.kyori adventure-text-serializer-gson + + com.github.steveice10 + packetlib + + + + + com.github.steveice10 + PacketLib + 54f761c + compile + + + io.netty + netty-all + diff --git a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java b/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java index dfa30ae92..a8044ef32 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java +++ b/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java @@ -34,7 +34,7 @@ import java.util.Map; public interface GeyserConfiguration { - // Modify this when you update the config + // Modify this when you introduce breaking changes into the config int CURRENT_CONFIG_VERSION = 4; IBedrockConfiguration getBedrock(); @@ -117,6 +117,8 @@ public interface GeyserConfiguration { void setPort(int port); String getAuthType(); + + boolean isUseProxyProtocol(); } interface IUserAuthenticationInfo { diff --git a/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java b/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java index 67fa04492..c403bdf11 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java +++ b/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java @@ -148,6 +148,9 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration @Setter @JsonProperty("auth-type") private String authType = "online"; + + @JsonProperty("use-proxy-protocol") + private boolean useProxyProtocol = false; } @Getter diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 2e857cdd3..ec383c44c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -39,6 +39,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket; import com.github.steveice10.mc.protocol.packet.login.server.LoginSuccessPacket; +import com.github.steveice10.packetlib.BuiltinFlags; import com.github.steveice10.packetlib.Client; import com.github.steveice10.packetlib.event.session.*; import com.github.steveice10.packetlib.packet.Packet; @@ -459,6 +460,10 @@ public class GeyserSession implements CommandSender { } downstream = new Client(remoteServer.getAddress(), remoteServer.getPort(), protocol, new TcpSessionFactory()); + if (connector.getConfig().getRemote().isUseProxyProtocol()) { + downstream.getSession().setFlag(BuiltinFlags.ENABLE_CLIENT_PROXY_PROTOCOL, true); + downstream.getSession().setFlag(BuiltinFlags.CLIENT_PROXIED_ADDRESS, upstream.getAddress()); + } // Let Geyser handle sending the keep alive downstream.getSession().setFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, false); downstream.getSession().addListener(new SessionAdapter() { diff --git a/connector/src/main/resources/config.yml b/connector/src/main/resources/config.yml index bdb212160..ac9ec753d 100644 --- a/connector/src/main/resources/config.yml +++ b/connector/src/main/resources/config.yml @@ -32,6 +32,11 @@ remote: port: 25565 # Authentication type. Can be offline, online, or floodgate (see https://github.com/GeyserMC/Geyser/wiki/Floodgate). auth-type: online + # Whether to enable PROXY protocol or not while connecting to the server. + # This is useful only when: + # 1) Your server supports PROXY protocol (it probably doesn't) + # 2) You run Velocity or BungeeCord with respective option enabled. + use-proxy-protocol: false # Floodgate uses encryption to ensure use from authorised sources. # This should point to the public key generated by Floodgate (Bungee or CraftBukkit)