From 7fe9740985d69b2f81c048f220742f41deb59cc0 Mon Sep 17 00:00:00 2001 From: Justsnoopy30 Date: Sat, 4 Jun 2022 21:06:41 +0100 Subject: [PATCH] Fix errors not showing up in disconnect messages (#2266) * Fix errors causing disconnects during server connection not showing up in the disconnect message * Replace unnecessary inject with the throwable provided in the redirect (cherry picked from commit e6b169ebcaa648d26a542f2c038acf4ca28a7ada) --- .../fabric/mixin/networking/ClientConnectionMixin.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ClientConnectionMixin.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ClientConnectionMixin.java index 779391c20..c04686245 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ClientConnectionMixin.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/ClientConnectionMixin.java @@ -65,13 +65,14 @@ abstract class ClientConnectionMixin implements ChannelInfoHolder { // Must be fully qualified due to mixin not working in production without it @SuppressWarnings("UnnecessaryQualifiedMemberReference") @Redirect(method = "Lnet/minecraft/network/ClientConnection;exceptionCaught(Lio/netty/channel/ChannelHandlerContext;Ljava/lang/Throwable;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;send(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V")) - private void resendOnExceptionCaught(ClientConnection self, Packet packet, GenericFutureListener> listener) { + private void resendOnExceptionCaught(ClientConnection self, Packet packet, GenericFutureListener> listener, ChannelHandlerContext context, Throwable ex) { PacketListener handler = this.packetListener; + Text disconnectMessage = Text.translatable("disconnect.genericReason", "Internal Exception: " + ex); if (handler instanceof DisconnectPacketSource) { - this.send(((DisconnectPacketSource) handler).createDisconnectPacket(Text.translatable("disconnect.genericReason")), listener); + this.send(((DisconnectPacketSource) handler).createDisconnectPacket(disconnectMessage), listener); } else { - this.disconnect(Text.translatable("disconnect.genericReason")); // Don't send packet if we cannot send proper packets + this.disconnect(disconnectMessage); // Don't send packet if we cannot send proper packets } } @@ -83,7 +84,7 @@ abstract class ClientConnectionMixin implements ChannelInfoHolder { } @Inject(method = "channelInactive", at = @At("HEAD")) - private void handleDisconnect(ChannelHandlerContext channelHandlerContext, CallbackInfo ci) throws Exception { + private void handleDisconnect(ChannelHandlerContext channelHandlerContext, CallbackInfo ci) { if (packetListener instanceof NetworkHandlerExtensions) { // not the case for client/server query ((NetworkHandlerExtensions) packetListener).getAddon().handleDisconnect(); }