Fixed version auto detector .write() warn, fixed multiconnect integration behaviour: now checks if suggested version will be supported by ViaFabric

This commit is contained in:
creeper123123321 2020-10-18 11:41:59 -03:00
parent bec45c4dbd
commit c25b09355c
2 changed files with 8 additions and 4 deletions

View File

@ -30,6 +30,7 @@ import com.github.creeper123123321.viafabric.service.ProtocolAutoDetector;
import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.util.ReferenceCountUtil;
import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Pair;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -53,11 +54,13 @@ public class ProtocolDetectionHandler extends ChannelDuplexHandler {
ViaFabric.JLOGGER.warning("Timeout for protocol auto-detection in " ViaFabric.JLOGGER.warning("Timeout for protocol auto-detection in "
+ ctx.channel().remoteAddress() + " server"); + ctx.channel().remoteAddress() + " server");
hold = false; hold = false;
drainQueue(ctx);
ctx.pipeline().remove(this); ctx.pipeline().remove(this);
}, 10, TimeUnit.SECONDS); }, 10, TimeUnit.SECONDS);
ProtocolAutoDetector.SERVER_VER.get(((InetSocketAddress) ctx.channel().remoteAddress())) ProtocolAutoDetector.SERVER_VER.get(((InetSocketAddress) ctx.channel().remoteAddress()))
.whenComplete((obj, ex) -> { .whenComplete((obj, ex) -> {
hold = false; hold = false;
drainQueue(ctx);
ctx.pipeline().remove(this); ctx.pipeline().remove(this);
timeoutRun.cancel(false); timeoutRun.cancel(false);
}); });
@ -97,7 +100,8 @@ public class ProtocolDetectionHandler extends ChannelDuplexHandler {
@Override @Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
drainQueue(ctx); queuedMessages.forEach(ReferenceCountUtil::release);
queuedMessages.clear();
super.handlerRemoved(ctx); super.handlerRemoved(ctx);
} }
} }

View File

@ -136,9 +136,9 @@ public class VRVersionProvider extends VersionProvider {
if (info.getState() == State.STATUS if (info.getState() == State.STATUS
&& info.getProtocolVersion() == -1 && info.getProtocolVersion() == -1
&& connection.getChannel().pipeline().get(ClientConnection.class).getPacketListener() && connection.getChannel().pipeline().get(ClientConnection.class).getPacketListener()
.getClass().getName().startsWith("net.earthcomputer.multiconnect")) { // Intercept the connection .getClass().getName().startsWith("net.earthcomputer.multiconnect")
int multiconnectSuggestion = getVersionForMulticonnect(serverVer); && (blocked || ProtocolUtils.isSupported(serverVer, getVersionForMulticonnect(serverVer)))) { // Intercept the connection
if (blocked) multiconnectSuggestion = -1; int multiconnectSuggestion = blocked ? -1 : getVersionForMulticonnect(serverVer);
ViaFabric.JLOGGER.info("Sending " + ProtocolVersion.getProtocol(multiconnectSuggestion) + " for multiconnect version detector"); ViaFabric.JLOGGER.info("Sending " + ProtocolVersion.getProtocol(multiconnectSuggestion) + " for multiconnect version detector");
PacketWrapper newAnswer = new PacketWrapper(0x00, null, connection); PacketWrapper newAnswer = new PacketWrapper(0x00, null, connection);
newAnswer.write(Type.STRING, "{\"version\":{\"name\":\"viafabric integration\",\"protocol\":" + multiconnectSuggestion + "}}"); newAnswer.write(Type.STRING, "{\"version\":{\"name\":\"viafabric integration\",\"protocol\":" + multiconnectSuggestion + "}}");