Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复与 --proxyHost 冲突 #86

Merged
merged 1 commit into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import moe.yushi.authlibinjector.transform.support.MC52974Workaround;
import moe.yushi.authlibinjector.transform.support.MC52974_1710Workaround;
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.YggdrasilKeyTransformUnit;
import moe.yushi.authlibinjector.yggdrasil.CustomYggdrasilAPIProvider;
Expand Down Expand Up @@ -90,6 +91,7 @@ public static synchronized void bootstrap(Instrumentation instrumentation, Strin
classTransformer = createTransformer(apiMetadata);
instrumentation.addTransformer(classTransformer, retransformSupported);

ProxyParameterWorkaround.init();
MC52974Workaround.init();
MC52974_1710Workaround.init();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ public String toString() {

@CallbackMethod
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;
for (Function<String[], String[]> listener : ARGUMENTS_LISTENERS) {
result = listener.apply(result);
}
log(DEBUG, "Transformed main arguments: " + Stream.of(result).collect(joining(" ")));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2020 Haowei Wen <[email protected]> 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()]);
});
}
}