mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-09-06 11:48:05 +02:00
This patch was heavily intented to fix a server side issue which is generally no longer relevant, not to mention the cost of interning only cements this patch into it's grave
124 lines
4.4 KiB
Diff
124 lines
4.4 KiB
Diff
From d332c9ff37c72dfc44b32e16f43705f900b1fafc 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..6e79675f
|
|
--- /dev/null
|
|
+++ b/api/src/main/java/io/github/waterfallmc/waterfall/event/ConnectionInitEvent.java
|
|
@@ -0,0 +1,56 @@
|
|
+package io.github.waterfallmc.waterfall.event;
|
|
+
|
|
+import net.md_5.bungee.api.Callback;
|
|
+import net.md_5.bungee.api.config.ListenerInfo;
|
|
+import net.md_5.bungee.api.event.AsyncEvent;
|
|
+import net.md_5.bungee.api.event.ClientConnectEvent;
|
|
+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 final ListenerInfo listener;
|
|
+ private boolean isCancelled = false;
|
|
+
|
|
+ public ConnectionInitEvent(SocketAddress remoteAddress, ListenerInfo listener, Callback<ConnectionInitEvent> done) {
|
|
+ super(done);
|
|
+ this.remoteAddress = remoteAddress;
|
|
+ this.listener = listener;
|
|
+ }
|
|
+
|
|
+ @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 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 @@
|
|
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;
|
|
@@ -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() )
|
|
@@ -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 );
|
|
+ } 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() ) );
|
|
@@ -84,6 +98,9 @@ public class PipelineUtils
|
|
{
|
|
ch.pipeline().addFirst( new HAProxyMessageDecoder() );
|
|
}
|
|
+ }); // Waterfall
|
|
+
|
|
+ BungeeCord.getInstance().getPluginManager().callEvent(connectionInitEvent);
|
|
}
|
|
};
|
|
public static final Base BASE = new Base();
|
|
--
|
|
2.26.1
|
|
|