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 e6b169ebca)
This commit is contained in:
Justsnoopy30 2022-06-04 21:06:41 +01:00 committed by modmuss50
parent 37622d24c5
commit 7fe9740985

View file

@ -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<? extends Future<? super Void>> listener) {
private void resendOnExceptionCaught(ClientConnection self, Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> 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();
}