Search in sources :

Example 1 with NativeVersionProvider

use of com.viaversion.fabric.common.platform.NativeVersionProvider in project ViaFabric by ViaVersion.

the class AbstractFabricPlatform method getDump.

@Override
public JsonObject getDump() {
    JsonObject platformSpecific = new JsonObject();
    JsonArray mods = new JsonArray();
    FabricLoader.getInstance().getAllMods().stream().map((mod) -> {
        JsonObject jsonMod = new JsonObject();
        jsonMod.addProperty("id", mod.getMetadata().getId());
        jsonMod.addProperty("name", mod.getMetadata().getName());
        jsonMod.addProperty("version", mod.getMetadata().getVersion().getFriendlyString());
        JsonArray authors = new JsonArray();
        mod.getMetadata().getAuthors().stream().map(it -> {
            JsonObject info = new JsonObject();
            JsonObject contact = new JsonObject();
            it.getContact().asMap().entrySet().forEach(c -> contact.addProperty(c.getKey(), c.getValue()));
            if (contact.size() != 0) {
                info.add("contact", contact);
            }
            info.addProperty("name", it.getName());
            return info;
        }).forEach(authors::add);
        jsonMod.add("authors", authors);
        return jsonMod;
    }).forEach(mods::add);
    platformSpecific.add("mods", mods);
    NativeVersionProvider ver = Via.getManager().getProviders().get(NativeVersionProvider.class);
    if (ver != null) {
        platformSpecific.addProperty("native version", ver.getNativeServerVersion());
    }
    return platformSpecific;
}
Also used : JsonArray(com.viaversion.viaversion.libs.gson.JsonArray) FabricLoader(net.fabricmc.loader.api.FabricLoader) ConfigurationProvider(com.viaversion.viaversion.api.configuration.ConfigurationProvider) FabricViaAPI(com.viaversion.fabric.common.platform.FabricViaAPI) CompletableFuture(java.util.concurrent.CompletableFuture) NativeVersionProvider(com.viaversion.fabric.common.platform.NativeVersionProvider) ViaPlatform(com.viaversion.viaversion.api.platform.ViaPlatform) EnvType(net.fabricmc.api.EnvType) Version(net.fabricmc.loader.api.Version) ModContainer(net.fabricmc.loader.api.ModContainer) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) CancellationException(java.util.concurrent.CancellationException) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) FutureTaskId(com.viaversion.fabric.common.util.FutureTaskId) ViaVersionConfig(com.viaversion.viaversion.api.configuration.ViaVersionConfig) UUID(java.util.UUID) Via(com.viaversion.viaversion.api.Via) EventLoop(io.netty.channel.EventLoop) Logger(java.util.logging.Logger) File(java.io.File) JsonArray(com.viaversion.viaversion.libs.gson.JsonArray) TimeUnit(java.util.concurrent.TimeUnit) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) JLoggerToLog4j(com.viaversion.fabric.common.util.JLoggerToLog4j) ViaAPI(com.viaversion.viaversion.api.ViaAPI) Future(io.netty.util.concurrent.Future) LogManager(org.apache.logging.log4j.LogManager) FabricViaConfig(com.viaversion.fabric.common.platform.FabricViaConfig) NativeVersionProvider(com.viaversion.fabric.common.platform.NativeVersionProvider) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject)

Example 2 with NativeVersionProvider

use of com.viaversion.fabric.common.platform.NativeVersionProvider 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)

Aggregations

NativeVersionProvider (com.viaversion.fabric.common.platform.NativeVersionProvider)2 AddressParser (com.viaversion.fabric.common.AddressParser)1 FabricViaAPI (com.viaversion.fabric.common.platform.FabricViaAPI)1 FabricViaConfig (com.viaversion.fabric.common.platform.FabricViaConfig)1 FutureTaskId (com.viaversion.fabric.common.util.FutureTaskId)1 JLoggerToLog4j (com.viaversion.fabric.common.util.JLoggerToLog4j)1 Via (com.viaversion.viaversion.api.Via)1 ViaAPI (com.viaversion.viaversion.api.ViaAPI)1 ConfigurationProvider (com.viaversion.viaversion.api.configuration.ConfigurationProvider)1 ViaVersionConfig (com.viaversion.viaversion.api.configuration.ViaVersionConfig)1 ProtocolInfo (com.viaversion.viaversion.api.connection.ProtocolInfo)1 ViaPlatform (com.viaversion.viaversion.api.platform.ViaPlatform)1 ProtocolVersion (com.viaversion.viaversion.api.protocol.version.ProtocolVersion)1 CancelException (com.viaversion.viaversion.exception.CancelException)1 JsonArray (com.viaversion.viaversion.libs.gson.JsonArray)1 JsonObject (com.viaversion.viaversion.libs.gson.JsonObject)1 EventLoop (io.netty.channel.EventLoop)1 Future (io.netty.util.concurrent.Future)1 GenericFutureListener (io.netty.util.concurrent.GenericFutureListener)1 File (java.io.File)1