Skip to content

Commit

Permalink
Set disconnect BaseComponent on disconnect InitialHandler
Browse files Browse the repository at this point in the history
also optimze the exception handling of InitialHandler
  • Loading branch information
Outfluencer authored Dec 20, 2023
1 parent b711e40 commit 8537709
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
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

0 comments on commit 8537709

Please sign in to comment.