2022-05-24 06:56:58 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: PanSzelescik <panszelescik@gmail.com>
|
|
|
|
Date: Thu, 7 Apr 2022 16:13:39 +0200
|
|
|
|
Subject: [PATCH] Add support for Proxy Protocol
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
|
|
@@ -0,0 +0,0 @@ public class PaperConfig {
|
|
|
|
private static void useDimensionTypeForCustomSpawners() {
|
|
|
|
useDimensionTypeForCustomSpawners = getBoolean("settings.use-dimension-type-for-custom-spawners", false);
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ public static boolean useProxyProtocol;
|
|
|
|
+ private static void useProxyProtocol() {
|
|
|
|
+ useProxyProtocol = getBoolean("settings.proxy-protocol", false);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
|
|
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
|
|
|
|
@@ -0,0 +0,0 @@ public class ServerConnectionListener {
|
|
|
|
ServerConnectionListener.LOGGER.info("Paper: Using " + com.velocitypowered.natives.util.Natives.cipher.getLoadedVariant() + " cipher from Velocity.");
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
+ // Paper start - indicate Proxy Protocol usage
|
|
|
|
+ if (com.destroystokyo.paper.PaperConfig.useProxyProtocol) {
|
|
|
|
+ ServerConnectionListener.LOGGER.info("Paper: Using Proxy Protocol");
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
this.channels.add(((ServerBootstrap) ((ServerBootstrap) (new ServerBootstrap()).channel(oclass)).childHandler(new ChannelInitializer<Channel>() {
|
|
|
|
protected void initChannel(Channel channel) {
|
|
|
|
try {
|
|
|
|
@@ -0,0 +0,0 @@ public class ServerConnectionListener {
|
|
|
|
int j = ServerConnectionListener.this.server.getRateLimitPacketsPerSecond();
|
|
|
|
Object object = j > 0 ? new RateKickingConnection(j) : new Connection(PacketFlow.SERVERBOUND);
|
|
|
|
|
|
|
|
+ // Paper start - Add support for Proxy Protocol
|
|
|
|
+ if (com.destroystokyo.paper.PaperConfig.useProxyProtocol) {
|
|
|
|
+ channel.pipeline().addAfter("timeout", "haproxy-decoder", new io.netty.handler.codec.haproxy.HAProxyMessageDecoder());
|
|
|
|
+ channel.pipeline().addAfter("haproxy-decoder", "haproxy-handler", new ChannelInboundHandlerAdapter() {
|
|
|
|
+ @Override
|
|
|
|
+ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
|
|
|
+ if (msg instanceof io.netty.handler.codec.haproxy.HAProxyMessage message) {
|
2022-06-01 23:58:22 +02:00
|
|
|
+ if (message.command() == io.netty.handler.codec.haproxy.HAProxyCommand.PROXY) {
|
|
|
|
+ String realaddress = message.sourceAddress();
|
|
|
|
+ int realport = message.sourcePort();
|
2022-05-24 06:56:58 +02:00
|
|
|
+
|
2022-06-01 23:58:22 +02:00
|
|
|
+ SocketAddress socketaddr = new java.net.InetSocketAddress(realaddress, realport);
|
2022-05-24 06:56:58 +02:00
|
|
|
+
|
2022-06-01 23:58:22 +02:00
|
|
|
+ Connection connection = (Connection) channel.pipeline().get("packet_handler");
|
|
|
|
+ connection.address = socketaddr;
|
|
|
|
+ }
|
2022-05-24 06:56:58 +02:00
|
|
|
+ } else {
|
|
|
|
+ super.channelRead(ctx, msg);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
// ServerConnectionListener.this.connections.add((Connection) object); // CraftBukkit - decompile error
|
|
|
|
pending.add((Connection) object); // Paper
|
|
|
|
channel.pipeline().addLast("packet_handler", (ChannelHandler) object);
|