2023-09-21 12:33:23 +02:00
|
|
|
From 888d05f5fba61d8aa230eebe869bce7e5c19fe82 Mon Sep 17 00:00:00 2001
|
2019-12-02 12:36:13 +01:00
|
|
|
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
|
2020-02-22 15:22:27 +01:00
|
|
|
index 00000000..6e79675f
|
2019-12-02 12:36:13 +01:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/api/src/main/java/io/github/waterfallmc/waterfall/event/ConnectionInitEvent.java
|
2020-02-10 23:39:19 +01:00
|
|
|
@@ -0,0 +1,56 @@
|
2019-12-02 12:36:13 +01:00
|
|
|
+package io.github.waterfallmc.waterfall.event;
|
|
|
|
+
|
|
|
|
+import net.md_5.bungee.api.Callback;
|
2020-02-10 23:39:19 +01:00
|
|
|
+import net.md_5.bungee.api.config.ListenerInfo;
|
2019-12-02 12:36:13 +01:00
|
|
|
+import net.md_5.bungee.api.event.AsyncEvent;
|
2020-02-10 23:39:19 +01:00
|
|
|
+import net.md_5.bungee.api.event.ClientConnectEvent;
|
2019-12-02 12:36:13 +01:00
|
|
|
+import net.md_5.bungee.api.plugin.Cancellable;
|
|
|
|
+
|
|
|
|
+import java.net.InetSocketAddress;
|
2020-01-21 18:36:22 +01:00
|
|
|
+import java.net.SocketAddress;
|
2019-12-02 12:36:13 +01:00
|
|
|
+
|
|
|
|
+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
|
2020-02-22 15:22:27 +01:00
|
|
|
+public class ConnectionInitEvent extends AsyncEvent<ConnectionInitEvent> implements Cancellable {
|
2019-12-02 12:36:13 +01:00
|
|
|
+
|
2020-01-21 18:36:22 +01:00
|
|
|
+ private final SocketAddress remoteAddress;
|
2020-02-22 12:22:29 +01:00
|
|
|
+ private final ListenerInfo listener;
|
2019-12-02 12:36:13 +01:00
|
|
|
+ private boolean isCancelled = false;
|
|
|
|
+
|
2020-02-22 15:22:27 +01:00
|
|
|
+ public ConnectionInitEvent(SocketAddress remoteAddress, ListenerInfo listener, Callback<ConnectionInitEvent> done) {
|
2020-02-22 12:22:29 +01:00
|
|
|
+ super(done);
|
2019-12-02 12:36:13 +01:00
|
|
|
+ this.remoteAddress = remoteAddress;
|
2020-02-22 12:22:29 +01:00
|
|
|
+ this.listener = listener;
|
2019-12-02 12:36:13 +01:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean isCancelled() {
|
|
|
|
+ return this.isCancelled;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setCancelled(boolean cancel) {
|
|
|
|
+ this.isCancelled = cancel;
|
|
|
|
+ }
|
2019-12-18 00:15:12 +01:00
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return the INetSocketAddress of the connection being opened
|
2020-01-21 18:36:22 +01:00
|
|
|
+ * @deprecated BungeeCord can accept connections via Unix domain sockets
|
2019-12-18 00:15:12 +01:00
|
|
|
+ */
|
2020-01-21 18:36:22 +01:00
|
|
|
+ @Deprecated
|
2019-12-18 00:15:12 +01:00
|
|
|
+ public InetSocketAddress getRemoteAddress() {
|
2020-01-21 18:36:22 +01:00
|
|
|
+ return (InetSocketAddress) remoteAddress;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return the SocketAddress of the connection being opened
|
|
|
|
+ */
|
|
|
|
+ public SocketAddress getRemoteSocketAddress() {
|
2019-12-18 00:15:12 +01:00
|
|
|
+ return remoteAddress;
|
|
|
|
+ }
|
2019-12-02 12:36:13 +01:00
|
|
|
+}
|
|
|
|
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
|
2023-03-25 19:36:07 +01:00
|
|
|
index 3f30da0c..af65e192 100644
|
2019-12-02 12:36:13 +01:00
|
|
|
--- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
|
|
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
|
2020-01-21 18:36:22 +01:00
|
|
|
@@ -1,6 +1,7 @@
|
2019-12-02 12:36:13 +01:00
|
|
|
package net.md_5.bungee.netty;
|
|
|
|
|
2020-01-21 18:36:22 +01:00
|
|
|
import com.google.common.base.Preconditions;
|
2019-12-02 12:36:13 +01:00
|
|
|
+import io.github.waterfallmc.waterfall.event.ConnectionInitEvent;
|
|
|
|
import io.netty.buffer.PooledByteBufAllocator;
|
|
|
|
import io.netty.channel.Channel;
|
|
|
|
import io.netty.channel.ChannelException;
|
2023-03-25 19:36:07 +01:00
|
|
|
@@ -63,7 +64,6 @@ public class PipelineUtils
|
2020-02-10 23:39:19 +01:00
|
|
|
ch.close();
|
2019-12-02 12:36:13 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-02-10 23:39:19 +01:00
|
|
|
-
|
|
|
|
ListenerInfo listener = ch.attr( LISTENER ).get();
|
2019-12-02 12:36:13 +01:00
|
|
|
|
2020-02-22 12:22:29 +01:00
|
|
|
if ( BungeeCord.getInstance().getPluginManager().callEvent( new ClientConnectEvent( remoteAddress, listener ) ).isCancelled() )
|
2023-03-25 19:36:07 +01:00
|
|
|
@@ -72,7 +72,21 @@ public class PipelineUtils
|
2020-02-10 23:39:19 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-12-02 12:36:13 +01:00
|
|
|
|
2020-02-22 12:22:29 +01:00
|
|
|
+ ConnectionInitEvent connectionInitEvent = new ConnectionInitEvent(ch.remoteAddress(), listener, (result, throwable) -> { // Waterfall
|
|
|
|
+
|
|
|
|
+ if (result.isCancelled()) {
|
|
|
|
+ ch.close();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
2020-02-10 23:39:19 +01:00
|
|
|
+
|
2019-12-02 12:36:13 +01:00
|
|
|
+ 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() ) );
|
2023-03-25 19:36:07 +01:00
|
|
|
@@ -83,6 +97,9 @@ public class PipelineUtils
|
2019-12-02 12:36:13 +01:00
|
|
|
{
|
|
|
|
ch.pipeline().addFirst( new HAProxyMessageDecoder() );
|
|
|
|
}
|
|
|
|
+ }); // Waterfall
|
|
|
|
+
|
|
|
|
+ BungeeCord.getInstance().getPluginManager().callEvent(connectionInitEvent);
|
|
|
|
}
|
|
|
|
};
|
2023-03-25 19:36:07 +01:00
|
|
|
public static final Base BASE = new Base( false );
|
2019-12-02 12:36:13 +01:00
|
|
|
--
|
2023-09-21 12:33:23 +02:00
|
|
|
2.42.0
|
2019-12-02 12:36:13 +01:00
|
|
|
|