Search in sources :

Example 1 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 2 with ProtocolVersion

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

the class MixinServerEntry method addServerVer.

@Redirect(method = "render", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/client/gui/screen/multiplayer/MultiplayerScreen;setTooltip(Ljava/util/List;)V"))
private void addServerVer(MultiplayerScreen multiplayerScreen, List<Text> tooltipText) {
    ProtocolVersion proto = ProtocolVersion.getProtocol(((ViaServerInfo) this.server).getViaServerVer());
    List<Text> lines = new ArrayList<>(tooltipText);
    lines.add(new TranslatableText("gui.ping_version.translated", proto.getName()));
    multiplayerScreen.setTooltip(lines);
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) ArrayList(java.util.ArrayList) TranslatableText(net.minecraft.text.TranslatableText) Text(net.minecraft.text.Text) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 3 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 4 with ProtocolVersion

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

the class ProtocolManagerImpl method refreshVersions.

public void refreshVersions() {
    supportedVersions.clear();
    supportedVersions.add(serverProtocolVersion.lowestSupportedVersion());
    for (ProtocolVersion version : ProtocolVersion.getProtocols()) {
        List<ProtocolPathEntry> protocolPath = getProtocolPath(version.getVersion(), serverProtocolVersion.lowestSupportedVersion());
        if (protocolPath == null)
            continue;
        supportedVersions.add(version.getVersion());
        for (ProtocolPathEntry pathEntry : protocolPath) {
            supportedVersions.add(pathEntry.outputProtocolVersion());
        }
    }
}
Also used : ProtocolPathEntry(com.viaversion.viaversion.api.protocol.ProtocolPathEntry) ServerProtocolVersion(com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion)

Example 5 with ProtocolVersion

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

the class BaseProtocol1_7 method registerPackets.

@Override
protected void registerPackets() {
    /* Outgoing Packets */
    // Status Response Packet
    registerClientbound(ClientboundStatusPackets.STATUS_RESPONSE, new // Status Response Packet
    PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.STRING);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ProtocolInfo info = wrapper.user().getProtocolInfo();
                    String originalStatus = wrapper.get(Type.STRING, 0);
                    try {
                        JsonElement json = GsonUtil.getGson().fromJson(originalStatus, JsonElement.class);
                        JsonObject version;
                        // Unknown!
                        int protocolVersion = 0;
                        if (json.isJsonObject()) {
                            if (json.getAsJsonObject().has("version")) {
                                version = json.getAsJsonObject().get("version").getAsJsonObject();
                                if (version.has("protocol")) {
                                    protocolVersion = ((Long) version.get("protocol").getAsLong()).intValue();
                                }
                            } else {
                                json.getAsJsonObject().add("version", version = new JsonObject());
                            }
                        } else {
                            // Format properly
                            json = new JsonObject();
                            json.getAsJsonObject().add("version", version = new JsonObject());
                        }
                        if (Via.getConfig().isSendSupportedVersions()) {
                            // Send supported versions
                            version.add("supportedVersions", GsonUtil.getGson().toJsonTree(Via.getAPI().getSupportedVersions()));
                        }
                        if (!Via.getAPI().getServerVersion().isKnown()) {
                            // Set the Server protocol if the detection on startup failed
                            ProtocolManagerImpl protocolManager = (ProtocolManagerImpl) Via.getManager().getProtocolManager();
                            protocolManager.setServerProtocol(new ServerProtocolVersionSingleton(ProtocolVersion.getProtocol(protocolVersion).getVersion()));
                        }
                        // Ensure the server has a version provider
                        VersionProvider versionProvider = Via.getManager().getProviders().get(VersionProvider.class);
                        if (versionProvider == null) {
                            wrapper.user().setActive(false);
                            return;
                        }
                        int closestServerProtocol = versionProvider.getClosestServerProtocol(wrapper.user());
                        List<ProtocolPathEntry> protocols = null;
                        if (info.getProtocolVersion() >= closestServerProtocol || Via.getPlatform().isOldClientsAllowed()) {
                            protocols = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), closestServerProtocol);
                        }
                        if (protocols != null) {
                            if (protocolVersion == closestServerProtocol || protocolVersion == 0) {
                                // Fix ServerListPlus
                                ProtocolVersion prot = ProtocolVersion.getProtocol(info.getProtocolVersion());
                                version.addProperty("protocol", prot.getOriginalVersion());
                            }
                        } else {
                            // not compatible :(, *plays very sad violin*
                            wrapper.user().setActive(false);
                        }
                        if (Via.getConfig().blockedProtocolVersions().contains(info.getProtocolVersion())) {
                            // Show blocked versions as outdated
                            version.addProperty("protocol", -1);
                        }
                        // Update value
                        wrapper.set(Type.STRING, 0, GsonUtil.getGson().toJson(json));
                    } catch (JsonParseException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    });
    // Login Success Packet
    registerClientbound(ClientboundLoginPackets.GAME_PROFILE, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    ProtocolInfo info = wrapper.user().getProtocolInfo();
                    info.setState(State.PLAY);
                    UUID uuid = passthroughLoginUUID(wrapper);
                    info.setUuid(uuid);
                    String username = wrapper.passthrough(Type.STRING);
                    info.setUsername(username);
                    // Add to ported clients
                    Via.getManager().getConnectionManager().onLoginSuccess(wrapper.user());
                    if (!info.getPipeline().hasNonBaseProtocols()) {
                        // Only base protocol
                        wrapper.user().setActive(false);
                    }
                    if (Via.getManager().isDebug()) {
                        // Print out the route to console
                        Via.getPlatform().getLogger().log(Level.INFO, "{0} logged in with protocol {1}, Route: {2}", new Object[] { username, info.getProtocolVersion(), Joiner.on(", ").join(info.getPipeline().pipes(), ", ") });
                    }
                }
            });
        }
    });
    /* Incoming Packets */
    // Login Start Packet
    registerServerbound(ServerboundLoginPackets.HELLO, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(new PacketHandler() {

                @Override
                public void handle(final PacketWrapper wrapper) throws Exception {
                    int protocol = wrapper.user().getProtocolInfo().getProtocolVersion();
                    if (Via.getConfig().blockedProtocolVersions().contains(protocol)) {
                        if (!wrapper.user().getChannel().isOpen())
                            return;
                        if (!wrapper.user().shouldApplyBlockProtocol())
                            return;
                        // Disconnect Packet
                        PacketWrapper disconnectPacket = PacketWrapper.create(ClientboundLoginPackets.LOGIN_DISCONNECT, wrapper.user());
                        Protocol1_9To1_8.FIX_JSON.write(disconnectPacket, ChatColorUtil.translateAlternateColorCodes(Via.getConfig().getBlockedDisconnectMsg()));
                        // cancel current
                        wrapper.cancel();
                        // Send and close
                        ChannelFuture future = disconnectPacket.sendFuture(BaseProtocol.class);
                        future.addListener(f -> wrapper.user().getChannel().close());
                    }
                }
            });
        }
    });
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ProtocolPathEntry(com.viaversion.viaversion.api.protocol.ProtocolPathEntry) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) JsonObject(com.google.gson.JsonObject) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) JsonParseException(com.google.gson.JsonParseException) VersionProvider(com.viaversion.viaversion.api.protocol.version.VersionProvider) ProtocolManagerImpl(com.viaversion.viaversion.protocol.ProtocolManagerImpl) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) JsonElement(com.google.gson.JsonElement) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) UUID(java.util.UUID) ServerProtocolVersionSingleton(com.viaversion.viaversion.protocol.ServerProtocolVersionSingleton)

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