Skip to content

Commit

Permalink
Trigger full disconnect client disconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
ramidzkh committed Aug 18, 2023
1 parent dd0b8e7 commit 6e1b181
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/me/ramidzkh/qc/mixin/ConnectionMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.ramidzkh.qc.mixin;

import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.incubator.codec.quic.QuicStreamChannel;
import me.ramidzkh.qc.client.QuicConnection;
import me.ramidzkh.qc.client.QuicSocketAddress;
import me.ramidzkh.qc.client.QuicTier;
Expand All @@ -9,6 +11,7 @@
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

Expand All @@ -18,6 +21,9 @@
@Mixin(Connection.class)
public class ConnectionMixin {

@Shadow
private Channel channel;

@Shadow
private boolean encrypted;

Expand All @@ -33,6 +39,15 @@ private static void onConnect(InetSocketAddress address, boolean useNativeTransp
}
}

@Redirect(method = "disconnect", at = @At(value = "FIELD", target = "Lnet/minecraft/network/Connection;channel:Lio/netty/channel/Channel;"))
private Channel getChannelForDisconnect(Connection self) {
if (channel instanceof QuicStreamChannel quic) {
return quic.parent();
} else {
return channel;
}
}

@Inject(method = "setEncryptionKey", at = @At("HEAD"), cancellable = true)
private void onSetEncryptionKey(CallbackInfo callbackInfo) {
if (encrypted) {
Expand Down

0 comments on commit 6e1b181

Please sign in to comment.