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 524bc08f3b
commit 29587ae5d1
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.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.util.ReferenceCountUtil;
import us.myles.ViaVersion.api.Pair;
import java.net.InetSocketAddress;
@ -53,11 +54,13 @@ public class ProtocolDetectionHandler extends ChannelDuplexHandler {
ViaFabric.JLOGGER.warning("Timeout for protocol auto-detection in "
+ ctx.channel().remoteAddress() + " server");
hold = false;
drainQueue(ctx);
ctx.pipeline().remove(this);
}, 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);
});
@ -97,7 +100,8 @@ public class ProtocolDetectionHandler extends ChannelDuplexHandler {
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
drainQueue(ctx);
queuedMessages.forEach(ReferenceCountUtil::release);
queuedMessages.clear();
super.handlerRemoved(ctx);
}
}

View File

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