Set disconnect BaseComponent on disconnect InitialHandler

also optimze the exception handling of InitialHandler
This commit is contained in:
Outfluencer 2023-12-20 15:40:39 +01:00 committed by GitHub
parent b711e4033f
commit 8537709045
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -110,6 +110,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Getter
private String extraDataInHandshake = "";
private UserConnection userCon;
@Getter
private BaseComponent disconnectMessage;
@Override
public boolean shouldHandle(PacketWrapper packet) throws Exception
@ -137,13 +139,11 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@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
@ -666,7 +666,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{
if ( canSendKickMessage() )
{
ch.delayedClose( new Kick( reason ) );
ch.delayedClose( new Kick( this.disconnectMessage = reason ) );
} else
{
ch.close();