mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-11-04 17:49:44 +01:00
103 lines
3.8 KiB
Diff
103 lines
3.8 KiB
Diff
|
From ccd977e511e6201c62e9e0da5879b55b1351f9cf 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..381c8deb
|
||
|
--- /dev/null
|
||
|
+++ b/api/src/main/java/io/github/waterfallmc/waterfall/event/ConnectionInitEvent.java
|
||
|
@@ -0,0 +1,35 @@
|
||
|
+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 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 InetSocketAddress remoteAddress;
|
||
|
+ private boolean isCancelled = false;
|
||
|
+
|
||
|
+ public ConnectionInitEvent(InetSocketAddress 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;
|
||
|
+ }
|
||
|
+}
|
||
|
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 23241d68..31de5a6f 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,5 +1,6 @@
|
||
|
package net.md_5.bungee.netty;
|
||
|
|
||
|
+import io.github.waterfallmc.waterfall.event.ConnectionInitEvent;
|
||
|
import io.netty.buffer.PooledByteBufAllocator;
|
||
|
import io.netty.channel.Channel;
|
||
|
import io.netty.channel.ChannelException;
|
||
|
@@ -31,6 +32,7 @@ import net.md_5.bungee.UserConnection;
|
||
|
import net.md_5.bungee.Util;
|
||
|
import net.md_5.bungee.api.ProxyServer;
|
||
|
import net.md_5.bungee.api.config.ListenerInfo;
|
||
|
+import net.md_5.bungee.api.connection.Connection;
|
||
|
import net.md_5.bungee.connection.InitialHandler;
|
||
|
import net.md_5.bungee.protocol.KickStringWriter;
|
||
|
import net.md_5.bungee.protocol.LegacyDecoder;
|
||
|
@@ -57,9 +59,22 @@ public class PipelineUtils
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
+ ConnectionInitEvent connectionInitEvent = new ConnectionInitEvent((InetSocketAddress) 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() ) );
|
||
|
@@ -70,6 +85,9 @@ public class PipelineUtils
|
||
|
{
|
||
|
ch.pipeline().addFirst( new HAProxyMessageDecoder() );
|
||
|
}
|
||
|
+ }); // Waterfall
|
||
|
+
|
||
|
+ BungeeCord.getInstance().getPluginManager().callEvent(connectionInitEvent);
|
||
|
}
|
||
|
};
|
||
|
public static final Base BASE = new Base();
|
||
|
--
|
||
|
2.24.0
|
||
|
|