diff --git a/BungeeCord-Patches/0055-ConnectionInitEvent.patch b/BungeeCord-Patches/0055-ConnectionInitEvent.patch new file mode 100644 index 0000000..d60c008 --- /dev/null +++ b/BungeeCord-Patches/0055-ConnectionInitEvent.patch @@ -0,0 +1,102 @@ +From ccd977e511e6201c62e9e0da5879b55b1351f9cf Mon Sep 17 00:00:00 2001 +From: Shane Freeder +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 implements Cancellable { ++ ++ private final InetSocketAddress remoteAddress; ++ private boolean isCancelled = false; ++ ++ public ConnectionInitEvent(InetSocketAddress remoteAddress, Callback 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 +