Search in sources :

Example 11 with ProtocolInfo

use of com.viaversion.viaversion.api.connection.ProtocolInfo in project ViaFabric by ViaVersion.

the class AbstractFabricVersionProvider method getClosestServerProtocol.

@Override
public int getClosestServerProtocol(UserConnection connection) throws Exception {
    if (connection.isClientSide()) {
        ProtocolInfo info = Objects.requireNonNull(connection.getProtocolInfo());
        if (!getConfig().isClientSideEnabled())
            return info.getProtocolVersion();
        int serverVer = getConfig().getClientSideVersion();
        SocketAddress addr = connection.getChannel().remoteAddress();
        if (addr instanceof InetSocketAddress) {
            AddressParser parser = new AddressParser();
            Integer addrVersion = parser.parse(((InetSocketAddress) addr).getHostName()).protocol;
            if (addrVersion != null) {
                serverVer = addrVersion;
            }
            try {
                if (serverVer == -2) {
                    // Hope protocol was autodetected
                    ProtocolVersion autoVer = detectVersion((InetSocketAddress) addr).getNow(null);
                    if (autoVer != null) {
                        serverVer = autoVer.getVersion();
                    }
                }
            } catch (Exception e) {
                getLogger().warning("Couldn't auto detect: " + e);
            }
        }
        boolean blocked = checkAddressBlocked(addr);
        boolean supported = ProtocolUtils.isSupported(serverVer, info.getProtocolVersion());
        handleMulticonnectPing(connection, info, blocked, serverVer);
        if (blocked || !supported)
            serverVer = info.getProtocolVersion();
        return serverVer;
    }
    NativeVersionProvider natProvider = Via.getManager().getProviders().get(NativeVersionProvider.class);
    if (natProvider != null) {
        return ProtocolVersion.getProtocol(natProvider.getNativeServerVersion()).getVersion();
    }
    return super.getClosestServerProtocol(connection);
}
Also used : AddressParser(com.viaversion.fabric.common.AddressParser) NativeVersionProvider(com.viaversion.fabric.common.platform.NativeVersionProvider) InetSocketAddress(java.net.InetSocketAddress) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) CancelException(com.viaversion.viaversion.exception.CancelException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 12 with ProtocolInfo

use of com.viaversion.viaversion.api.connection.ProtocolInfo in project ViaFabric by ViaVersion.

the class MixinDebugHud method getLeftText.

@Inject(at = @At("RETURN"), method = "getLeftText")
protected void getLeftText(CallbackInfoReturnable<List<String>> info) {
    String line = "[ViaFabric] I: " + Via.getManager().getConnectionManager().getConnections().size() + " (F: " + Via.getManager().getConnectionManager().getConnectedClients().size() + ")";
    @SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler().getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
    if (viaDecoder instanceof FabricDecodeHandler) {
        ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
        if (protocol != null) {
            ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
            ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
            line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
        }
    }
    info.getReturnValue().add(line);
}
Also used : FabricDecodeHandler(com.viaversion.fabric.common.handler.FabricDecodeHandler) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) ChannelHandler(io.netty.channel.ChannelHandler) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 13 with ProtocolInfo

use of com.viaversion.viaversion.api.connection.ProtocolInfo in project ViaFabric by ViaVersion.

the class MixinDebugHud method getLeftText.

@Inject(at = @At("RETURN"), method = "getLeftText")
protected void getLeftText(CallbackInfoReturnable<List<String>> info) {
    String line = "[ViaFabric] I: " + Via.getManager().getConnectionManager().getConnections().size() + " (F: " + Via.getManager().getConnectionManager().getConnectedClients().size() + ")";
    @SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler().getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
    if (viaDecoder instanceof FabricDecodeHandler) {
        ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
        if (protocol != null) {
            ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
            ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
            line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
        }
    }
    info.getReturnValue().add(line);
}
Also used : FabricDecodeHandler(com.viaversion.fabric.common.handler.FabricDecodeHandler) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) ChannelHandler(io.netty.channel.ChannelHandler) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 14 with ProtocolInfo

use of com.viaversion.viaversion.api.connection.ProtocolInfo in project ViaFabric by ViaVersion.

the class MixinDebugHud method getLeftText.

@Inject(at = @At("RETURN"), method = "getLeftText")
protected void getLeftText(CallbackInfoReturnable<List<String>> info) {
    String line = "[ViaFabric] I: " + Via.getManager().getConnectionManager().getConnections().size() + " (F: " + Via.getManager().getConnectionManager().getConnectedClients().size() + ")";
    ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler().getClientConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
    if (viaDecoder instanceof FabricDecodeHandler) {
        ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
        if (protocol != null) {
            ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
            ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
            line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
        }
    }
    info.getReturnValue().add(line);
}
Also used : FabricDecodeHandler(com.viaversion.fabric.common.handler.FabricDecodeHandler) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) ChannelHandler(io.netty.channel.ChannelHandler) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 15 with ProtocolInfo

use of com.viaversion.viaversion.api.connection.ProtocolInfo in project ViaFabric by ViaVersion.

the class MixinDebugHud method getLeftText.

@Inject(at = @At("RETURN"), method = "getLeftText")
protected void getLeftText(CallbackInfoReturnable<List<String>> info) {
    String line = "[ViaFabric] I: " + Via.getManager().getConnectionManager().getConnections().size() + " (F: " + Via.getManager().getConnectionManager().getConnectedClients().size() + ")";
    @SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler().getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
    if (viaDecoder instanceof FabricDecodeHandler) {
        ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
        if (protocol != null) {
            ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
            ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
            line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
        }
    }
    info.getReturnValue().add(line);
}
Also used : FabricDecodeHandler(com.viaversion.fabric.common.handler.FabricDecodeHandler) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) ChannelHandler(io.netty.channel.ChannelHandler) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ProtocolInfo (com.viaversion.viaversion.api.connection.ProtocolInfo)17 ProtocolVersion (com.viaversion.viaversion.api.protocol.version.ProtocolVersion)9 FabricDecodeHandler (com.viaversion.fabric.common.handler.FabricDecodeHandler)7 ChannelHandler (io.netty.channel.ChannelHandler)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)3 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)3 ProtocolPathEntry (com.viaversion.viaversion.api.protocol.ProtocolPathEntry)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 UUID (java.util.UUID)2 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)2 ProtocolStorage (com.github.dirtpowered.dirtmv.data.user.ProtocolStorage)1 UserData (com.github.dirtpowered.dirtmv.data.user.UserData)1 PlayerMovementTracker (com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.PlayerMovementTracker)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 AddressParser (com.viaversion.fabric.common.AddressParser)1 NativeVersionProvider (com.viaversion.fabric.common.platform.NativeVersionProvider)1 StorableObject (com.viaversion.viaversion.api.connection.StorableObject)1