Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print the disconnect message of the InitialHandler #3583

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -110,6 +110,8 @@ public void sendPacket(DefinedPacket packet)
@Getter
private String extraDataInHandshake = "";
private UserConnection userCon;
@Getter
private BaseComponent disconnectMessage;

@Override
public boolean shouldHandle(PacketWrapper packet) throws Exception
Expand Down Expand Up @@ -137,13 +139,11 @@ public void connected(ChannelWrapper channel) throws Exception
@Override
public void exception(Throwable t) throws Exception
{
if ( canSendKickMessage() )
{
disconnect( ChatColor.RED + Util.exception( t ) );
} else
{
ch.close();
}
// if the connection is a login attempt, directly send a Kick with the Exception to the client
// we can't use disconnect() here as the method delays the Kick packet sending by 250ms and the HandlerBoss
// will close the channel before the packet is sent
// also we don't want to print the exception twice
ch.close( canSendKickMessage() ? new Kick( TextComponent.fromLegacy( ChatColor.RED + Util.exception( t ) ) ) : null );
}

@Override
Expand Down Expand Up @@ -666,7 +666,7 @@ public void disconnect(BaseComponent reason)
{
if ( canSendKickMessage() )
{
ch.delayedClose( new Kick( reason ) );
ch.delayedClose( new Kick( this.disconnectMessage = reason ) );
} else
{
ch.close();
Expand Down
17 changes: 15 additions & 2 deletions proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java
Expand Up @@ -60,9 +60,22 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception
channel.markClosed();
handler.disconnected( channel );

if ( !( handler instanceof InitialHandler || handler instanceof PingHandler ) )
if ( !( handler instanceof PingHandler ) )
{
ProxyServer.getInstance().getLogger().log( Level.INFO, "{0} has disconnected", handler );
if ( handler instanceof InitialHandler )
{
InitialHandler initialHandler = (InitialHandler) handler;
if ( initialHandler.getDisconnectMessage() != null )
{
ProxyServer.getInstance().getLogger().log( Level.INFO, "{0} has disconnected: {1}", new Object[]
{
handler, initialHandler.getDisconnectMessage().toPlainText()
} );
}
} else
{
ProxyServer.getInstance().getLogger().log( Level.INFO, "{0} has disconnected", handler );
}
}
}
}
Expand Down