From e6b169ebcaa648d26a542f2c038acf4ca28a7ada Mon Sep 17 00:00:00 2001 From: Justsnoopy30 Date: Sat, 4 Jun 2022 15:06:41 -0500 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 --- .../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 02928dda8..c6e838092 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 @@ -66,13 +66,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 = new TranslatableText("disconnect.genericReason", "Internal Exception: " + ex); if (handler instanceof DisconnectPacketSource) { - this.send(((DisconnectPacketSource) handler).createDisconnectPacket(new TranslatableText("disconnect.genericReason")), listener); + this.send(((DisconnectPacketSource) handler).createDisconnectPacket(disconnectMessage), listener); } else { - this.disconnect(new TranslatableText("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 } } @@ -84,7 +85,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(); }