Search in sources :

Example 6 with ProtocolVersion

use of com.viaversion.viaversion.api.protocol.version.ProtocolVersion in project ViaVersion by ViaVersion.

the class ListSubCmd method execute.

@Override
public boolean execute(ViaCommandSender sender, String[] args) {
    Map<ProtocolVersion, Set<String>> playerVersions = new TreeMap<>((o1, o2) -> ProtocolVersion.getIndex(o2) - ProtocolVersion.getIndex(o1));
    for (ViaCommandSender p : Via.getPlatform().getOnlinePlayers()) {
        int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID());
        ProtocolVersion key = ProtocolVersion.getProtocol(playerVersion);
        playerVersions.computeIfAbsent(key, s -> new HashSet<>()).add(p.getName());
    }
    for (Map.Entry<ProtocolVersion, Set<String>> entry : playerVersions.entrySet()) {
        sendMessage(sender, "&8[&6%s&8] (&7%d&8): &b%s", entry.getKey().getName(), entry.getValue().size(), entry.getValue());
    }
    playerVersions.clear();
    return true;
}
Also used : ViaCommandSender(com.viaversion.viaversion.api.command.ViaCommandSender) HashSet(java.util.HashSet) ViaCommandSender(com.viaversion.viaversion.api.command.ViaCommandSender) ViaSubCommand(com.viaversion.viaversion.api.command.ViaSubCommand) TreeMap(java.util.TreeMap) Map(java.util.Map) Set(java.util.Set) Via(com.viaversion.viaversion.api.Via) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) HashSet(java.util.HashSet) Set(java.util.Set) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 7 with ProtocolVersion

use of com.viaversion.viaversion.api.protocol.version.ProtocolVersion in project ViaVersion by ViaVersion.

the class AbstractViaConfig method loadBlockedProtocolVersions.

private BlockedProtocolVersions loadBlockedProtocolVersions() {
    IntSet blockedProtocols = new IntOpenHashSet(getIntegerList("block-protocols"));
    int lowerBound = -1;
    int upperBound = -1;
    for (String s : getStringList("block-versions")) {
        if (s.isEmpty()) {
            continue;
        }
        char c = s.charAt(0);
        if (c == '<' || c == '>') {
            // Set lower/upper bound
            ProtocolVersion protocolVersion = protocolVersion(s.substring(1));
            if (protocolVersion == null) {
                continue;
            }
            if (c == '<') {
                if (lowerBound != -1) {
                    Via.getPlatform().getLogger().warning("Already set lower bound " + lowerBound + " overridden by " + protocolVersion.getName());
                }
                lowerBound = protocolVersion.getVersion();
            } else {
                if (upperBound != -1) {
                    Via.getPlatform().getLogger().warning("Already set upper bound " + upperBound + " overridden by " + protocolVersion.getName());
                }
                upperBound = protocolVersion.getVersion();
            }
            continue;
        }
        ProtocolVersion protocolVersion = protocolVersion(s);
        if (protocolVersion == null) {
            continue;
        }
        // Add single protocol version and check for duplication
        if (!blockedProtocols.add(protocolVersion.getVersion())) {
            Via.getPlatform().getLogger().warning("Duplicated blocked protocol version " + protocolVersion.getName() + "/" + protocolVersion.getVersion());
        }
    }
    // Check for duplicated entries
    if (lowerBound != -1 || upperBound != -1) {
        final int finalLowerBound = lowerBound;
        final int finalUpperBound = upperBound;
        blockedProtocols.removeIf((IntPredicate) version -> {
            if (finalLowerBound != -1 && version < finalLowerBound || finalUpperBound != -1 && version > finalUpperBound) {
                ProtocolVersion protocolVersion = ProtocolVersion.getProtocol(version);
                Via.getPlatform().getLogger().warning("Blocked protocol version " + protocolVersion.getName() + "/" + protocolVersion.getVersion() + " already covered by upper or lower bound");
                return true;
            }
            return false;
        });
    }
    return new BlockedProtocolVersionsImpl(blockedProtocols, lowerBound, upperBound);
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) BlockedProtocolVersionsImpl(com.viaversion.viaversion.protocol.BlockedProtocolVersionsImpl) ViaVersionConfig(com.viaversion.viaversion.api.configuration.ViaVersionConfig) BlockedProtocolVersions(com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions) HashMap(java.util.HashMap) Via(com.viaversion.viaversion.api.Via) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) IntPredicate(java.util.function.IntPredicate) File(java.io.File) JsonElement(com.google.gson.JsonElement) WorldIdentifiers(com.viaversion.viaversion.api.minecraft.WorldIdentifiers) IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) Map(java.util.Map) Config(com.viaversion.viaversion.util.Config) IntSet(it.unimi.dsi.fastutil.ints.IntSet) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BlockedProtocolVersionsImpl(com.viaversion.viaversion.protocol.BlockedProtocolVersionsImpl) IntSet(it.unimi.dsi.fastutil.ints.IntSet) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion)

Example 8 with ProtocolVersion

use of com.viaversion.viaversion.api.protocol.version.ProtocolVersion 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 9 with ProtocolVersion

use of com.viaversion.viaversion.api.protocol.version.ProtocolVersion 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 10 with ProtocolVersion

use of com.viaversion.viaversion.api.protocol.version.ProtocolVersion 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

ProtocolVersion (com.viaversion.viaversion.api.protocol.version.ProtocolVersion)21 ProtocolInfo (com.viaversion.viaversion.api.connection.ProtocolInfo)9 FabricDecodeHandler (com.viaversion.fabric.common.handler.FabricDecodeHandler)7 ChannelHandler (io.netty.channel.ChannelHandler)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 Map (java.util.Map)4 ProtocolPathEntry (com.viaversion.viaversion.api.protocol.ProtocolPathEntry)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Text (net.minecraft.text.Text)3 TranslatableText (net.minecraft.text.TranslatableText)3 Redirect (org.spongepowered.asm.mixin.injection.Redirect)3 JsonElement (com.google.gson.JsonElement)2 Via (com.viaversion.viaversion.api.Via)2 ServerProtocolVersion (com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion)2 ServerProtocolVersionSingleton (com.viaversion.viaversion.protocol.ServerProtocolVersionSingleton)2 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 AddressParser (com.viaversion.fabric.common.AddressParser)1