Call Bungees ClientConnectEvent (Fixes #458)

totally forgot about bungees lack of hierchy when it comes to events...
This commit is contained in:
Shane Freeder 2020-02-22 11:22:29 +00:00
parent e9ad343d5e
commit e19ea6c087
No known key found for this signature in database
GPG Key ID: A3F61EA5A085289C

View File

@ -1,4 +1,4 @@
From 9d1697f260c3f6b4ae801401e7ed2d1c99d7127f Mon Sep 17 00:00:00 2001
From e7304c8179fc7985a420337d51d441f1000794e2 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
@ -6,7 +6,7 @@ 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..6f6c6226
index 00000000..77ff8740
--- /dev/null
+++ b/api/src/main/java/io/github/waterfallmc/waterfall/event/ConnectionInitEvent.java
@@ -0,0 +1,56 @@
@ -26,18 +26,18 @@ index 00000000..6f6c6226
+/**
+ * Represents a brand new connection made to the proxy, allowing for plugins to
+ * efficiently close a connection, useful for connection throttlers, etc
+ * @deprecated spigot added a variant of this event upstream, this class may be removed in the future
+ */
+@ToString
+@Deprecated
+public class ConnectionInitEvent extends ClientConnectEvent implements Cancellable {
+public class ConnectionInitEvent extends AsyncEvent<ClientConnectEvent> implements Cancellable {
+
+ private final SocketAddress remoteAddress;
+ private final ListenerInfo listener;
+ private boolean isCancelled = false;
+
+ public ConnectionInitEvent(SocketAddress remoteAddress, ListenerInfo listener, Callback<ClientConnectEvent> done) {
+ super(remoteAddress, listener, done);
+ super(done);
+ this.remoteAddress = remoteAddress;
+ this.listener = listener;
+ }
+
+ @Override
@ -66,63 +66,8 @@ index 00000000..6f6c6226
+ return remoteAddress;
+ }
+}
diff --git a/api/src/main/java/net/md_5/bungee/api/event/ClientConnectEvent.java b/api/src/main/java/net/md_5/bungee/api/event/ClientConnectEvent.java
index 50ce034c..df5ffda7 100644
--- a/api/src/main/java/net/md_5/bungee/api/event/ClientConnectEvent.java
+++ b/api/src/main/java/net/md_5/bungee/api/event/ClientConnectEvent.java
@@ -1,12 +1,17 @@
package net.md_5.bungee.api.event;
import java.net.SocketAddress;
+
+import io.github.waterfallmc.waterfall.event.ConnectionInitEvent;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
+
+import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.plugin.Cancellable;
import net.md_5.bungee.api.plugin.Event;
+import net.md_5.bungee.api.plugin.Listener;
/**
* Event called to represent an initial client connection.
@@ -14,10 +19,9 @@ import net.md_5.bungee.api.plugin.Event;
* Note: This event is called at an early stage of every connection, handling
* should be <b>fast</b>.
*/
-@Data
@ToString(callSuper = false)
@EqualsAndHashCode(callSuper = false)
-public class ClientConnectEvent extends Event implements Cancellable
+public class ClientConnectEvent extends AsyncEvent<ClientConnectEvent> implements Cancellable// Waterfall
{
/**
@@ -32,4 +36,20 @@ public class ClientConnectEvent extends Event implements Cancellable
* Listener that accepted the connection.
*/
private final ListenerInfo listener;
+
+ public ClientConnectEvent(SocketAddress remoteAddress, ListenerInfo listener, Callback<ClientConnectEvent> done) {
+ super(done);
+ socketAddress = remoteAddress;
+ this.listener = listener;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
}
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 8969a5ed..4ad17d1a 100644
index 8969a5ed..9a39f69e 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 @@
@ -133,22 +78,25 @@ index 8969a5ed..4ad17d1a 100644
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.Channel;
import io.netty.channel.ChannelException;
@@ -64,16 +65,23 @@ public class PipelineUtils
@@ -64,7 +65,6 @@ public class PipelineUtils
ch.close();
return;
}
-
ListenerInfo listener = ch.attr( LISTENER ).get();
- if ( BungeeCord.getInstance().getPluginManager().callEvent( new ClientConnectEvent( remoteAddress, listener ) ).isCancelled() )
- {
+ ConnectionInitEvent connectionInitEvent = new ConnectionInitEvent(ch.remoteAddress(), listener, (result, throwable) -> { // Waterfall
+
+ if (result.isCancelled()) {
ch.close();
if ( BungeeCord.getInstance().getPluginManager().callEvent( new ClientConnectEvent( remoteAddress, listener ) ).isCancelled() )
@@ -73,7 +73,21 @@ public class PipelineUtils
return;
}
+ ConnectionInitEvent connectionInitEvent = new ConnectionInitEvent(ch.remoteAddress(), listener, (result, throwable) -> { // Waterfall
+
+ if (result.isCancelled()) {
+ ch.close();
+ return;
+ }
+
+
+ try {
BASE.initChannel( ch );
@ -160,7 +108,7 @@ index 8969a5ed..4ad17d1a 100644
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() ) );
@@ -84,6 +92,9 @@ public class PipelineUtils
@@ -84,6 +98,9 @@ public class PipelineUtils
{
ch.pipeline().addFirst( new HAProxyMessageDecoder() );
}