mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-12-21 16:17:37 +01:00
parent
00aed06518
commit
bac7e86217
@ -30,7 +30,6 @@ import com.github.creeper123123321.viafabric.service.ProtocolAutoDetector;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import us.myles.ViaVersion.api.Pair;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@ -59,8 +58,6 @@ public class ProtocolDetectionHandler extends ChannelDuplexHandler {
|
||||
}, 10, TimeUnit.SECONDS);
|
||||
ProtocolAutoDetector.SERVER_VER.get(((InetSocketAddress) ctx.channel().remoteAddress()))
|
||||
.whenComplete((obj, ex) -> {
|
||||
hold = false;
|
||||
drainQueue(ctx);
|
||||
ctx.pipeline().remove(this);
|
||||
timeoutRun.cancel(false);
|
||||
});
|
||||
@ -91,6 +88,12 @@ public class ProtocolDetectionHandler extends ChannelDuplexHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
drainQueue(ctx);
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
private void drainQueue(ChannelHandlerContext ctx) {
|
||||
queuedMessages.forEach(it -> ctx.write(it.getKey(), it.getValue()));
|
||||
queuedMessages.clear();
|
||||
@ -100,8 +103,7 @@ public class ProtocolDetectionHandler extends ChannelDuplexHandler {
|
||||
|
||||
@Override
|
||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||
queuedMessages.forEach(ReferenceCountUtil::release);
|
||||
queuedMessages.clear();
|
||||
drainQueue(ctx);
|
||||
super.handlerRemoved(ctx);
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ import net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket;
|
||||
import net.minecraft.network.packet.c2s.query.QueryRequestC2SPacket;
|
||||
import net.minecraft.network.packet.s2c.query.QueryPongS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.query.QueryResponseS2CPacket;
|
||||
import net.minecraft.server.ServerMetadata;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
@ -92,10 +93,15 @@ public class ProtocolAutoDetector {
|
||||
clientConnection.setPacketListener(new ClientQueryPacketListener() {
|
||||
@Override
|
||||
public void onResponse(QueryResponseS2CPacket packet) {
|
||||
ProtocolVersion ver = ProtocolVersion.getProtocol(packet.getServerMetadata().getVersion()
|
||||
.getProtocolVersion());
|
||||
ServerMetadata meta = packet.getServerMetadata();
|
||||
ServerMetadata.Version version;
|
||||
if (meta != null && (version = meta.getVersion()) != null) {
|
||||
ProtocolVersion ver = ProtocolVersion.getProtocol(version.getProtocolVersion());
|
||||
future.complete(ver);
|
||||
ViaFabric.JLOGGER.info("Auto-detected " + ver + " for " + address);
|
||||
} else {
|
||||
future.completeExceptionally(new IllegalArgumentException("Null version in query response"));
|
||||
}
|
||||
clientConnection.disconnect(LiteralText.EMPTY);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user