Compare commits

...

3 Commits

Author SHA1 Message Date
Outfluencer
ed80c3ae89
Merge 46fddc4110 into 336333acb1 2024-04-26 15:25:45 +02:00
Outfluencer
46fddc4110
print disconnect message of InitialHandlers 2023-12-20 15:47:36 +01:00
Outfluencer
8537709045
Set disconnect BaseComponent on disconnect InitialHandler
also optimze the exception handling of InitialHandler
2023-12-20 15:40:39 +01:00
2 changed files with 23 additions and 10 deletions

View File

@ -136,6 +136,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Getter
private boolean transferred;
private UserConnection userCon;
@Getter
private BaseComponent disconnectMessage;
@Override
public boolean shouldHandle(PacketWrapper packet) throws Exception
@ -163,13 +165,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
@ -751,7 +751,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();

View File

@ -60,9 +60,22 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
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 );
}
}
}
}