|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: PanSzelescik <panszelescik@gmail.com> |
| 3 | +Date: Thu, 7 Apr 2022 16:13:39 +0200 |
| 4 | +Subject: [PATCH] Add support for Proxy Protocol |
| 5 | + |
| 6 | + |
| 7 | +diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java |
| 8 | +index 1ac6cf51f2682d5eb14fe19646e79f6617d492dd..fafbebbb5e8c1a381b673f97f1fa210687b52823 100644 |
| 9 | +--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java |
| 10 | ++++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java |
| 11 | +@@ -688,4 +688,9 @@ public class PaperConfig { |
| 12 | + private static void useDimensionTypeForCustomSpawners() { |
| 13 | + useDimensionTypeForCustomSpawners = getBoolean("settings.use-dimension-type-for-custom-spawners", false); |
| 14 | + } |
| 15 | ++ |
| 16 | ++ public static boolean useProxyProtocol; |
| 17 | ++ private static void useProxyProtocol() { |
| 18 | ++ useProxyProtocol = getBoolean("settings.proxy-protocol", false); |
| 19 | ++ } |
| 20 | + } |
| 21 | +diff --git a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java |
| 22 | +index 058fb3696c7ece4a7b6971886b1760b26add733b..bd378482b82c15cba1eeaa620521ad9ed460a1da 100644 |
| 23 | +--- a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java |
| 24 | ++++ b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java |
| 25 | +@@ -109,6 +109,12 @@ public class ServerConnectionListener { |
| 26 | + ServerConnectionListener.LOGGER.info("Paper: Using " + com.velocitypowered.natives.util.Natives.cipher.getLoadedVariant() + " cipher from Velocity."); |
| 27 | + // Paper end |
| 28 | + |
| 29 | ++ // Paper start - indicate Proxy Protocol usage |
| 30 | ++ if (com.destroystokyo.paper.PaperConfig.useProxyProtocol) { |
| 31 | ++ ServerConnectionListener.LOGGER.info("Paper: Using Proxy Protocol"); |
| 32 | ++ } |
| 33 | ++ // Paper end |
| 34 | ++ |
| 35 | + this.channels.add(((ServerBootstrap) ((ServerBootstrap) (new ServerBootstrap()).channel(oclass)).childHandler(new ChannelInitializer<Channel>() { |
| 36 | + protected void initChannel(Channel channel) { |
| 37 | + try { |
| 38 | +@@ -122,6 +128,28 @@ public class ServerConnectionListener { |
| 39 | + int j = ServerConnectionListener.this.server.getRateLimitPacketsPerSecond(); |
| 40 | + Object object = j > 0 ? new RateKickingConnection(j) : new Connection(PacketFlow.SERVERBOUND); |
| 41 | + |
| 42 | ++ // Paper start - Add support for Proxy Protocol |
| 43 | ++ if (com.destroystokyo.paper.PaperConfig.useProxyProtocol) { |
| 44 | ++ channel.pipeline().addAfter("timeout", "haproxy-decoder", new io.netty.handler.codec.haproxy.HAProxyMessageDecoder()); |
| 45 | ++ channel.pipeline().addAfter("haproxy-decoder", "haproxy-handler", new ChannelInboundHandlerAdapter() { |
| 46 | ++ @Override |
| 47 | ++ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { |
| 48 | ++ if (msg instanceof io.netty.handler.codec.haproxy.HAProxyMessage message) { |
| 49 | ++ String realaddress = message.sourceAddress(); |
| 50 | ++ int realport = message.sourcePort(); |
| 51 | ++ |
| 52 | ++ SocketAddress socketaddr = new java.net.InetSocketAddress(realaddress, realport); |
| 53 | ++ |
| 54 | ++ Connection connection = (Connection) channel.pipeline().get("packet_handler"); |
| 55 | ++ connection.address = socketaddr; |
| 56 | ++ } else { |
| 57 | ++ super.channelRead(ctx, msg); |
| 58 | ++ } |
| 59 | ++ } |
| 60 | ++ }); |
| 61 | ++ } |
| 62 | ++ // Paper end |
| 63 | ++ |
| 64 | + // ServerConnectionListener.this.connections.add((Connection) object); // CraftBukkit - decompile error |
| 65 | + pending.add((Connection) object); // Paper |
| 66 | + channel.pipeline().addLast("packet_handler", (ChannelHandler) object); |
0 commit comments