From 6f236dceebd2bcc8907029eb9b9428f349c19ecf Mon Sep 17 00:00:00 2001 From: Haowei Wen Date: Sat, 10 Oct 2020 19:00:48 +0800 Subject: [PATCH] show auth server name in menu screen --- README.en.md | 5 ++ README.md | 4 ++ .../authlibinjector/AuthlibInjector.java | 4 ++ .../moe/yushi/authlibinjector/Config.java | 2 + .../support/AuthServerNameInjector.java | 49 +++++++++++++++++++ 5 files changed, 64 insertions(+) create mode 100644 src/main/java/moe/yushi/authlibinjector/transform/support/AuthServerNameInjector.java diff --git a/README.en.md b/README.en.md index 95134b3..3bb0dd4 100644 --- a/README.en.md +++ b/README.en.md @@ -76,4 +76,9 @@ Configure Minecraft server with the following JVM parameter: Features (see below) depending on local HTTP server will be unavailable: - Mojang namespace - Legacy skin API polyfill + +-Dauthlibinjector.noShowServerName + Do not show authentication server name in Minecraft menu screen. + By default, authlib-injector alters --versionType parameter to display the authentication server name. + This feature can be disabled using this option. ``` diff --git a/README.md b/README.md index 89137e9..177dd43 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,10 @@ gradle 以下依赖内建 HTTP 服务器的功能将不可用: - Mojang 命名空间 - 旧式皮肤 API polyfill + +-Dauthlibinjector.noShowServerName + 不要在 Minecraft 主界面展示验证服务器名称. + 默认情况下, authlib-injector 通过更改 --versionType 参数来在 Minecraft 主界面显示验证服务器名称, 使用本选项可以禁用该功能. ``` ## 捐助 diff --git a/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java b/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java index ff7445c..70f7db9 100644 --- a/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java +++ b/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java @@ -50,6 +50,7 @@ import moe.yushi.authlibinjector.httpd.URLFilter; import moe.yushi.authlibinjector.httpd.URLProcessor; import moe.yushi.authlibinjector.transform.ClassTransformer; import moe.yushi.authlibinjector.transform.DumpClassListener; +import moe.yushi.authlibinjector.transform.support.AuthServerNameInjector; import moe.yushi.authlibinjector.transform.support.AuthlibLogInterceptor; import moe.yushi.authlibinjector.transform.support.CitizensTransformer; import moe.yushi.authlibinjector.transform.support.ConstantURLTransformUnit; @@ -94,6 +95,9 @@ public final class AuthlibInjector { ProxyParameterWorkaround.init(); MC52974Workaround.init(); MC52974_1710Workaround.init(); + if (!Config.noShowServerName) { + AuthServerNameInjector.init(apiMetadata); + } } private static Optional getPrefetchedResponse() { diff --git a/src/main/java/moe/yushi/authlibinjector/Config.java b/src/main/java/moe/yushi/authlibinjector/Config.java index eaa7675..5f812f1 100644 --- a/src/main/java/moe/yushi/authlibinjector/Config.java +++ b/src/main/java/moe/yushi/authlibinjector/Config.java @@ -59,6 +59,7 @@ public final class Config { public static Set ignoredPackages; public static FeatureOption mojangNamespace; public static FeatureOption legacySkinPolyfill; + public static boolean noShowServerName; private static void initDebugOptions() { String prop = System.getProperty("authlibinjector.debug"); @@ -202,5 +203,6 @@ public final class Config { mojangNamespace = parseFeatureOption("authlibinjector.mojangNamespace"); legacySkinPolyfill = parseFeatureOption("authlibinjector.legacySkinPolyfill"); httpdDisabled = System.getProperty("authlibinjector.disableHttpd") != null; + noShowServerName = System.getProperty("authlibinjector.noShowServerName") != null; } } diff --git a/src/main/java/moe/yushi/authlibinjector/transform/support/AuthServerNameInjector.java b/src/main/java/moe/yushi/authlibinjector/transform/support/AuthServerNameInjector.java new file mode 100644 index 0000000..289b9b1 --- /dev/null +++ b/src/main/java/moe/yushi/authlibinjector/transform/support/AuthServerNameInjector.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2020 Haowei Wen and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package moe.yushi.authlibinjector.transform.support; + +import static moe.yushi.authlibinjector.util.Logging.log; +import moe.yushi.authlibinjector.APIMetadata; +import moe.yushi.authlibinjector.util.Logging.Level; + +public final class AuthServerNameInjector { + private AuthServerNameInjector() {} + + private static String getServerName(APIMetadata meta) { + Object serverName = meta.getMeta().get("serverName"); + if (serverName instanceof String) { + return (String) serverName; + } else { + return meta.getApiRoot(); + } + } + + public static void init(APIMetadata meta) { + MainArgumentsTransformer.getArgumentsListeners().add(args -> { + for (int i = 0; i < args.length - 1; i++) { + if ("--versionType".equals(args[i])) { + String serverName = getServerName(meta); + log(Level.DEBUG, "Setting versionType to server name: " + serverName); + args[i + 1] = serverName; + break; + } + } + return args; + }); + } + +}