#2761: Add ClientConnectEvent
This commit is contained in:
parent
a3ab2bf58e
commit
b4b998b2e5
@ -0,0 +1,35 @@
|
|||||||
|
package net.md_5.bungee.api.event;
|
||||||
|
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import net.md_5.bungee.api.config.ListenerInfo;
|
||||||
|
import net.md_5.bungee.api.plugin.Cancellable;
|
||||||
|
import net.md_5.bungee.api.plugin.Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event called to represent an initial client connection.
|
||||||
|
* <br>
|
||||||
|
* 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
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancelled state.
|
||||||
|
*/
|
||||||
|
private boolean cancelled;
|
||||||
|
/**
|
||||||
|
* Remote address of connection.
|
||||||
|
*/
|
||||||
|
private final SocketAddress socketAddress;
|
||||||
|
/**
|
||||||
|
* Listener that accepted the connection.
|
||||||
|
*/
|
||||||
|
private final ListenerInfo listener;
|
||||||
|
}
|
@ -36,6 +36,7 @@ import net.md_5.bungee.UserConnection;
|
|||||||
import net.md_5.bungee.Util;
|
import net.md_5.bungee.Util;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.config.ListenerInfo;
|
import net.md_5.bungee.api.config.ListenerInfo;
|
||||||
|
import net.md_5.bungee.api.event.ClientConnectEvent;
|
||||||
import net.md_5.bungee.connection.InitialHandler;
|
import net.md_5.bungee.connection.InitialHandler;
|
||||||
import net.md_5.bungee.protocol.KickStringWriter;
|
import net.md_5.bungee.protocol.KickStringWriter;
|
||||||
import net.md_5.bungee.protocol.LegacyDecoder;
|
import net.md_5.bungee.protocol.LegacyDecoder;
|
||||||
@ -56,7 +57,9 @@ public class PipelineUtils
|
|||||||
@Override
|
@Override
|
||||||
protected void initChannel(Channel ch) throws Exception
|
protected void initChannel(Channel ch) throws Exception
|
||||||
{
|
{
|
||||||
if ( BungeeCord.getInstance().getConnectionThrottle() != null && BungeeCord.getInstance().getConnectionThrottle().throttle( ch.remoteAddress() ) )
|
SocketAddress remoteAddress = ( ch.remoteAddress() == null ) ? ch.parent().localAddress() : ch.remoteAddress();
|
||||||
|
|
||||||
|
if ( BungeeCord.getInstance().getConnectionThrottle() != null && BungeeCord.getInstance().getConnectionThrottle().throttle( remoteAddress ) )
|
||||||
{
|
{
|
||||||
ch.close();
|
ch.close();
|
||||||
return;
|
return;
|
||||||
@ -64,6 +67,12 @@ public class PipelineUtils
|
|||||||
|
|
||||||
ListenerInfo listener = ch.attr( LISTENER ).get();
|
ListenerInfo listener = ch.attr( LISTENER ).get();
|
||||||
|
|
||||||
|
if ( BungeeCord.getInstance().getPluginManager().callEvent( new ClientConnectEvent( remoteAddress, listener ) ).isCancelled() )
|
||||||
|
{
|
||||||
|
ch.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BASE.initChannel( ch );
|
BASE.initChannel( ch );
|
||||||
ch.pipeline().addBefore( FRAME_DECODER, LEGACY_DECODER, new LegacyDecoder() );
|
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_DECODER, PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, true, ProxyServer.getInstance().getProtocolVersion() ) );
|
||||||
|
Loading…
Reference in New Issue
Block a user