mirror of
https://github.com/yushijinhun/authlib-injector.git
synced 2024-11-15 06:11:09 +01:00
Drop main arguments --proxyHost, --proxyPort, --proxyUser, --proxyPass
This commit is contained in:
parent
c4a769271a
commit
6d3e5856c2
3 changed files with 57 additions and 1 deletions
|
@ -56,6 +56,7 @@ import moe.yushi.authlibinjector.transform.support.ConstantURLTransformUnit;
|
||||||
import moe.yushi.authlibinjector.transform.support.MC52974Workaround;
|
import moe.yushi.authlibinjector.transform.support.MC52974Workaround;
|
||||||
import moe.yushi.authlibinjector.transform.support.MC52974_1710Workaround;
|
import moe.yushi.authlibinjector.transform.support.MC52974_1710Workaround;
|
||||||
import moe.yushi.authlibinjector.transform.support.MainArgumentsTransformer;
|
import moe.yushi.authlibinjector.transform.support.MainArgumentsTransformer;
|
||||||
|
import moe.yushi.authlibinjector.transform.support.ProxyParameterWorkaround;
|
||||||
import moe.yushi.authlibinjector.transform.support.SkinWhitelistTransformUnit;
|
import moe.yushi.authlibinjector.transform.support.SkinWhitelistTransformUnit;
|
||||||
import moe.yushi.authlibinjector.transform.support.YggdrasilKeyTransformUnit;
|
import moe.yushi.authlibinjector.transform.support.YggdrasilKeyTransformUnit;
|
||||||
import moe.yushi.authlibinjector.yggdrasil.CustomYggdrasilAPIProvider;
|
import moe.yushi.authlibinjector.yggdrasil.CustomYggdrasilAPIProvider;
|
||||||
|
@ -90,6 +91,7 @@ public final class AuthlibInjector {
|
||||||
classTransformer = createTransformer(apiMetadata);
|
classTransformer = createTransformer(apiMetadata);
|
||||||
instrumentation.addTransformer(classTransformer, retransformSupported);
|
instrumentation.addTransformer(classTransformer, retransformSupported);
|
||||||
|
|
||||||
|
ProxyParameterWorkaround.init();
|
||||||
MC52974Workaround.init();
|
MC52974Workaround.init();
|
||||||
MC52974_1710Workaround.init();
|
MC52974_1710Workaround.init();
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,12 +75,13 @@ public class MainArgumentsTransformer implements TransformUnit {
|
||||||
|
|
||||||
@CallbackMethod
|
@CallbackMethod
|
||||||
public static String[] processMainArguments(String[] args) {
|
public static String[] processMainArguments(String[] args) {
|
||||||
log(DEBUG, "Main arguments: " + Stream.of(args).collect(joining(" ")));
|
log(DEBUG, "Original main arguments: " + Stream.of(args).collect(joining(" ")));
|
||||||
|
|
||||||
String[] result = args;
|
String[] result = args;
|
||||||
for (Function<String[], String[]> listener : ARGUMENTS_LISTENERS) {
|
for (Function<String[], String[]> listener : ARGUMENTS_LISTENERS) {
|
||||||
result = listener.apply(result);
|
result = listener.apply(result);
|
||||||
}
|
}
|
||||||
|
log(DEBUG, "Transformed main arguments: " + Stream.of(result).collect(joining(" ")));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Haowei Wen <yushijinhun@gmail.com> 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package moe.yushi.authlibinjector.transform.support;
|
||||||
|
|
||||||
|
import static moe.yushi.authlibinjector.util.Logging.log;
|
||||||
|
import static moe.yushi.authlibinjector.util.Logging.Level.WARNING;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public final class ProxyParameterWorkaround {
|
||||||
|
private ProxyParameterWorkaround() {}
|
||||||
|
|
||||||
|
private static final Set<String> PROXY_PARAMETERS = new HashSet<>(Arrays.asList(
|
||||||
|
"--proxyHost", "--proxyPort", "--proxyUser", "--proxyPass"
|
||||||
|
));
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
MainArgumentsTransformer.getArgumentsListeners().add(args -> {
|
||||||
|
boolean proxyDetected = false;
|
||||||
|
List<String> filtered = new ArrayList<>();
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
if (i + 1 < args.length && PROXY_PARAMETERS.contains(args[i])) {
|
||||||
|
proxyDetected = true;
|
||||||
|
log(WARNING, "Dropping main argument " + args[i] + " " + args[i + 1]);
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
filtered.add(args[i]);
|
||||||
|
}
|
||||||
|
if (proxyDetected) {
|
||||||
|
log(WARNING, "--proxyHost parameter conflicts with authlib-injector, therefore proxy is disabled.");
|
||||||
|
}
|
||||||
|
return filtered.toArray(new String[filtered.size()]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue