Show server side messages in F3 on disconnect

This commit is contained in:
s809
2024-02-24 22:48:24 +05:00
parent d966697ecb
commit 1fd85f2249
2 changed files with 16 additions and 14 deletions
@@ -103,7 +103,9 @@ public class NetworkClient extends NetworkEventSource implements IConnection, Au
{
this.registerHandler(CloseReasonMessage.class, closeReasonMessage ->
{
LOGGER.warn("Received disconnect reason: " + closeReasonMessage.reason);
String fullCloseText = "[Server] " + closeReasonMessage.reason;
LOGGER.warn(fullCloseText);
this.closeReason = new Exception(fullCloseText);
this.connectionState.set(EConnectionState.GOT_CLOSE_REASON);
});
@@ -40,16 +40,16 @@ public class MessageHandler extends SimpleChannelInboundHandler<NetworkMessage>
private final BiConsumer<ChannelHandlerContext, NetworkMessage> messageConsumer;
private final Consumer<ChannelHandlerContext> channelActiveConsumer;
private final BiConsumer<ChannelHandlerContext, Throwable> closeReasonConsumer;
private final BiConsumer<ChannelHandlerContext, Throwable> exceptionConsumer;
public MessageHandler(
BiConsumer<ChannelHandlerContext, NetworkMessage> messageConsumer,
Consumer<ChannelHandlerContext> channelActiveConsumer,
BiConsumer<ChannelHandlerContext, Throwable> closeReasonConsumer)
BiConsumer<ChannelHandlerContext, Throwable> exceptionConsumer)
{
this.messageConsumer = messageConsumer;
this.channelActiveConsumer = channelActiveConsumer;
this.closeReasonConsumer = closeReasonConsumer;
this.exceptionConsumer = exceptionConsumer;
}
@Override
@@ -66,19 +66,9 @@ public class MessageHandler extends SimpleChannelInboundHandler<NetworkMessage>
this.channelActiveConsumer.accept(ctx);
}
@Override
public void channelInactive(@NotNull ChannelHandlerContext channelContext) throws Exception
{
super.channelInactive(channelContext);
this.channelRead0(channelContext, new CloseEvent());
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
{
this.closeReasonConsumer.accept(ctx, cause);
ctx.close();
if (cause instanceof SocketException)
{
LOGGER.info("Exception caught in channel: [" + ctx.name() + "]: " + cause.getMessage());
@@ -86,7 +76,17 @@ public class MessageHandler extends SimpleChannelInboundHandler<NetworkMessage>
else
{
LOGGER.error("Exception caught in channel: [" + ctx.name() + "].", cause);
this.exceptionConsumer.accept(ctx, cause);
}
ctx.close();
}
@Override
public void channelInactive(@NotNull ChannelHandlerContext channelContext) throws Exception
{
super.channelInactive(channelContext);
this.channelRead0(channelContext, new CloseEvent());
}
}