mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
Введение LauncherEnvironment
This commit is contained in:
parent
99d9533b1c
commit
23966a3b04
6 changed files with 67 additions and 6 deletions
|
@ -32,6 +32,7 @@
|
|||
import java.util.zip.CRC32;
|
||||
|
||||
import ru.gravit.launcher.Launcher;
|
||||
import ru.gravit.launcher.LauncherConfig;
|
||||
import ru.gravit.launcher.hasher.HashedDir;
|
||||
import ru.gravit.launcher.managers.GarbageManager;
|
||||
import ru.gravit.launcher.profiles.ClientProfile;
|
||||
|
@ -48,10 +49,7 @@
|
|||
import ru.gravit.launchserver.auth.handler.AuthHandler;
|
||||
import ru.gravit.launchserver.auth.hwid.HWIDHandler;
|
||||
import ru.gravit.launchserver.auth.provider.AuthProvider;
|
||||
import ru.gravit.launchserver.binary.EXEL4JLauncherBinary;
|
||||
import ru.gravit.launchserver.binary.EXELauncherBinary;
|
||||
import ru.gravit.launchserver.binary.JARLauncherBinary;
|
||||
import ru.gravit.launchserver.binary.LauncherBinary;
|
||||
import ru.gravit.launchserver.binary.*;
|
||||
import ru.gravit.launchserver.command.handler.CommandHandler;
|
||||
import ru.gravit.launchserver.command.handler.JLineCommandHandler;
|
||||
import ru.gravit.launchserver.command.handler.StdCommandHandler;
|
||||
|
@ -114,6 +112,7 @@ public static final class Config extends ConfigObject {
|
|||
public final String binaryName;
|
||||
private final StringConfigEntry address;
|
||||
private final String bindAddress;
|
||||
public final LauncherConfig.LauncherEnvironment env;
|
||||
|
||||
private Config(BlockConfigEntry block, Path coredir, LaunchServer server) {
|
||||
super(block);
|
||||
|
@ -160,6 +159,7 @@ private Config(BlockConfigEntry block, Path coredir, LaunchServer server) {
|
|||
|
||||
isUsingWrapper = block.getEntryValue("isUsingWrapper", BooleanConfigEntry.class);
|
||||
isDownloadJava = block.getEntryValue("isDownloadJava", BooleanConfigEntry.class);
|
||||
env = LauncherConfig.LauncherEnvironment.STD;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
import javassist.CtConstructor;
|
||||
import javassist.CtMethod;
|
||||
import javassist.NotFoundException;
|
||||
import ru.gravit.launcher.LauncherConfig;
|
||||
|
||||
public class JAConfigurator implements AutoCloseable {
|
||||
public class JAConfigurator implements AutoCloseable {
|
||||
public ClassPool pool;
|
||||
public CtClass ctClass;
|
||||
public CtConstructor ctConstructor;
|
||||
|
@ -92,6 +93,28 @@ public void setPort(int port) {
|
|||
body.append(port);
|
||||
body.append(";");
|
||||
}
|
||||
public void setEnv(LauncherConfig.LauncherEnvironment env) {
|
||||
int i = 2;
|
||||
switch(env)
|
||||
{
|
||||
|
||||
case DEV:
|
||||
i = 0;
|
||||
break;
|
||||
case DEBUG:
|
||||
i = 1;
|
||||
break;
|
||||
case STD:
|
||||
i = 2;
|
||||
break;
|
||||
case PROD:
|
||||
i = 3;
|
||||
break;
|
||||
}
|
||||
body.append("this.env = ");
|
||||
body.append(i);
|
||||
body.append(";");
|
||||
}
|
||||
|
||||
public void setClientPort(int port) {
|
||||
body.append("this.clientPort = ");
|
||||
|
|
|
@ -215,6 +215,7 @@ private void stdBuild() throws IOException {
|
|||
jaConfigurator.setClientPort(32148 + SecurityHelper.newRandom().nextInt(512));
|
||||
jaConfigurator.setUsingWrapper(server.config.isUsingWrapper);
|
||||
jaConfigurator.setDownloadJava(server.config.isDownloadJava);
|
||||
jaConfigurator.setEnv(server.config.env);
|
||||
server.buildHookManager.registerAllClientModuleClass(jaConfigurator);
|
||||
try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(cleanJar))) {
|
||||
ZipEntry e = input.getNextEntry();
|
||||
|
|
|
@ -9,6 +9,11 @@ public class AutogenConfig {
|
|||
public boolean isUsingWrapper;
|
||||
public boolean isDownloadJava; //Выставление этого флага требует модификации runtime части
|
||||
public String secretKeyClient;
|
||||
public int env;
|
||||
// 0 - Dev (дебаг включен по умолчанию, все сообщения)
|
||||
// 1 - Debug (дебаг включен по умолчанию, основные сообщения)
|
||||
// 2 - Std (дебаг выключен по умолчанию, основные сообщения)
|
||||
// 3 - Production (дебаг выключен, минимальный объем сообщений, stacktrace не выводится)
|
||||
|
||||
AutogenConfig() {
|
||||
|
||||
|
|
|
@ -56,6 +56,20 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException
|
|||
secretKeyClient = config.secretKeyClient;
|
||||
isDownloadJava = config.isDownloadJava;
|
||||
isUsingWrapper = config.isUsingWrapper;
|
||||
LauncherEnvironment env;
|
||||
if(config.env == 0) env = LauncherEnvironment.DEV;
|
||||
else if(config.env == 1) env = LauncherEnvironment.DEBUG;
|
||||
else if(config.env == 2) env = LauncherEnvironment.STD;
|
||||
else if(config.env == 3) env = LauncherEnvironment.PROD;
|
||||
else env = LauncherEnvironment.STD;
|
||||
if(env == LauncherEnvironment.PROD) {
|
||||
LogHelper.setStacktraceEnabled(false);
|
||||
LogHelper.setDebugEnabled(false);
|
||||
}
|
||||
if(env == LauncherEnvironment.DEV || env == LauncherEnvironment.DEBUG)
|
||||
{
|
||||
LogHelper.setDebugEnabled(true);
|
||||
}
|
||||
// Read signed runtime
|
||||
int count = input.readLength(0);
|
||||
Map<String, byte[]> localResources = new HashMap<>(count);
|
||||
|
@ -108,4 +122,9 @@ public void write(HOutput output) throws IOException {
|
|||
output.writeByteArray(entry.getValue(), SecurityHelper.CRYPTO_MAX_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
public enum LauncherEnvironment
|
||||
{
|
||||
DEV,DEBUG,STD,PROD
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ public final class LogHelper {
|
|||
@LauncherAPI
|
||||
public static final String DEBUG_PROPERTY = "launcher.debug";
|
||||
@LauncherAPI
|
||||
public static final String STACKTRACE_PROPERTY = "launcher.stacktrace";
|
||||
@LauncherAPI
|
||||
public static final String NO_JANSI_PROPERTY = "launcher.noJAnsi";
|
||||
@LauncherAPI
|
||||
public static final boolean JANSI;
|
||||
|
@ -34,6 +36,7 @@ public final class LogHelper {
|
|||
// Output settings
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss", Locale.US);
|
||||
private static final AtomicBoolean DEBUG_ENABLED = new AtomicBoolean(Boolean.getBoolean(DEBUG_PROPERTY));
|
||||
private static final AtomicBoolean STACKTRACE_ENABLED = new AtomicBoolean(Boolean.getBoolean(STACKTRACE_PROPERTY));
|
||||
private static final Set<Output> OUTPUTS = Collections.newSetFromMap(new ConcurrentHashMap<>(2));
|
||||
private static final Output STD_OUTPUT;
|
||||
|
||||
|
@ -73,7 +76,7 @@ public static void debug(String format, Object... args) {
|
|||
|
||||
@LauncherAPI
|
||||
public static void error(Throwable exc) {
|
||||
error(isDebugEnabled() ? toString(exc) : exc.toString());
|
||||
error(isStacktraceEnabled() ? toString(exc) : exc.toString());
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
@ -106,6 +109,16 @@ public static void setDebugEnabled(boolean debugEnabled) {
|
|||
DEBUG_ENABLED.set(debugEnabled);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static boolean isStacktraceEnabled() {
|
||||
return STACKTRACE_ENABLED.get();
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static void setStacktraceEnabled(boolean stacktraceEnabled) {
|
||||
STACKTRACE_ENABLED.set(stacktraceEnabled);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public static void log(Level level, String message, boolean sub) {
|
||||
String dateTime = DATE_TIME_FORMATTER.format(LocalDateTime.now());
|
||||
|
|
Loading…
Reference in a new issue