Detect client/server side (#16)

This commit is contained in:
yushijinhun 2018-10-05 19:14:08 +08:00
parent 0b81d69ff8
commit 390220b973
No known key found for this signature in database
GPG key ID: 5BC167F73EA558E4
2 changed files with 38 additions and 0 deletions

View file

@ -61,6 +61,12 @@ public final class AuthlibInjector {
*/
public static final String PROP_DUMP_CLASS = "authlibinjector.dumpClass";
/**
* The side that authlib-injector runs on.
* Possible values: client, server.
*/
public static final String PROP_SIDE = "authlibinjector.side";
// ====
private AuthlibInjector() {}
@ -99,6 +105,10 @@ public final class AuthlibInjector {
String apiRoot = System.getProperty(PROP_API_ROOT);
if (apiRoot == null) return empty();
// for further use
ExecutionEnvironment side = detectSide();
Logging.LAUNCH.fine("Detected side: " + side);
apiRoot = appendSuffixSlash(apiRoot);
Logging.CONFIG.info("API root: " + apiRoot);
warnIfHttp(apiRoot);
@ -155,6 +165,29 @@ public final class AuthlibInjector {
}
}
private static ExecutionEnvironment detectSide() {
String specifiedSide = System.getProperty(PROP_SIDE);
if (specifiedSide != null) {
switch (specifiedSide) {
case "client":
return ExecutionEnvironment.CLIENT;
case "server":
return ExecutionEnvironment.SERVER;
default:
Logging.LAUNCH.warning("Invalid value [" + specifiedSide + "] for parameter " + PROP_SIDE + ", ignoring.");
break;
}
}
// fallback
if (System.getProperty(PROP_PREFETCHED_DATA) != null || System.getProperty(PROP_PREFETCHED_DATA_OLD) != null) {
Logging.LAUNCH.warning("Prefetched configuration must be used along with parameter " + PROP_SIDE);
return ExecutionEnvironment.CLIENT;
} else {
return ExecutionEnvironment.SERVER;
}
}
private static ClassTransformer createTransformer(YggdrasilConfiguration config) {
ClassTransformer transformer = new ClassTransformer();
transformer.debugSaveClass = "true".equals(System.getProperty(PROP_DUMP_CLASS));

View file

@ -0,0 +1,5 @@
package moe.yushi.authlibinjector;
public enum ExecutionEnvironment {
CLIENT, SERVER;
}