Waterfall/BungeeCord-Patches/0055-ConnectionInitEvent.patch
Shane Freeder 56fd936664
Updated Upstream (BungeeCord)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

BungeeCord Changes:
4bb0fb67 Fix Javadoc in ServerInfo.getSocketAddress
68cc325a #2755: Add ClickEvent.COPY_TO_CLIPBOARD
3d3a5aef Remove unused .travis.yml
2c6a21d5 Remove stray import breaking build
b7e7274b #2750: Don't special case TextComponent constructor with a single extra
b70cb014 Add beta support for binding bungee to unix socket addresses
701391f2 Update Netty to 4.1.45.Final
2020-01-21 17:36:22 +00:00

122 lines
4.3 KiB
Diff

From 3fff0a06f93a7b1882fa1a6563889697270cec0a Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Mon, 2 Dec 2019 11:35:17 +0000
Subject: [PATCH] ConnectionInitEvent
diff --git a/api/src/main/java/io/github/waterfallmc/waterfall/event/ConnectionInitEvent.java b/api/src/main/java/io/github/waterfallmc/waterfall/event/ConnectionInitEvent.java
new file mode 100644
index 00000000..e884eac8
--- /dev/null
+++ b/api/src/main/java/io/github/waterfallmc/waterfall/event/ConnectionInitEvent.java
@@ -0,0 +1,52 @@
+package io.github.waterfallmc.waterfall.event;
+
+import net.md_5.bungee.api.Callback;
+import net.md_5.bungee.api.event.AsyncEvent;
+import net.md_5.bungee.api.plugin.Cancellable;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+
+import lombok.ToString;
+
+/**
+ * Represents a brand new connection made to the proxy, allowing for plugins to
+ * efficiently close a connection, useful for connection throttlers, etc
+ */
+@ToString
+public class ConnectionInitEvent extends AsyncEvent<ConnectionInitEvent> implements Cancellable {
+
+ private final SocketAddress remoteAddress;
+ private boolean isCancelled = false;
+
+ public ConnectionInitEvent(SocketAddress remoteAddress, Callback<ConnectionInitEvent> done) {
+ super(done);
+ this.remoteAddress = remoteAddress;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return this.isCancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.isCancelled = cancel;
+ }
+
+ /**
+ * @return the INetSocketAddress of the connection being opened
+ * @deprecated BungeeCord can accept connections via Unix domain sockets
+ */
+ @Deprecated
+ public InetSocketAddress getRemoteAddress() {
+ return (InetSocketAddress) remoteAddress;
+ }
+
+ /**
+ * @return the SocketAddress of the connection being opened
+ */
+ public SocketAddress getRemoteSocketAddress() {
+ return remoteAddress;
+ }
+}
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
index 0c91f7ed..e89f3669 100644
--- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
@@ -1,6 +1,7 @@
package net.md_5.bungee.netty;
import com.google.common.base.Preconditions;
+import io.github.waterfallmc.waterfall.event.ConnectionInitEvent;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.Channel;
import io.netty.channel.ChannelException;
@@ -26,6 +27,8 @@ import io.netty.handler.codec.haproxy.HAProxyMessageDecoder;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.util.AttributeKey;
import io.netty.util.internal.PlatformDependent;
+
+import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
@@ -62,9 +65,22 @@ public class PipelineUtils
return;
}
+ ConnectionInitEvent connectionInitEvent = new ConnectionInitEvent(ch.remoteAddress(), (result, throwable) -> { // Waterfall
+
+ if (result.isCancelled()) {
+ ch.close();
+ return;
+ }
+
ListenerInfo listener = ch.attr( LISTENER ).get();
+ try {
BASE.initChannel( ch );
+ } catch (Exception e) {
+ e.printStackTrace();
+ ch.close();
+ return;
+ }
ch.pipeline().addBefore( FRAME_DECODER, LEGACY_DECODER, new LegacyDecoder() );
ch.pipeline().addAfter( FRAME_DECODER, PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, true, ProxyServer.getInstance().getProtocolVersion() ) );
ch.pipeline().addAfter( FRAME_PREPENDER, PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, true, ProxyServer.getInstance().getProtocolVersion() ) );
@@ -75,6 +91,9 @@ public class PipelineUtils
{
ch.pipeline().addFirst( new HAProxyMessageDecoder() );
}
+ }); // Waterfall
+
+ BungeeCord.getInstance().getPluginManager().callEvent(connectionInitEvent);
}
};
public static final Base BASE = new Base();
--
2.25.0