From 23966a3b043c6e4d3d2e68141eabe67130d6caae Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 19 Dec 2018 18:24:50 +0700 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20LauncherEnvironment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launchserver/LaunchServer.java | 8 +++--- .../launchserver/binary/JAConfigurator.java | 25 ++++++++++++++++++- .../binary/JARLauncherBinary.java | 1 + .../ru/gravit/launcher/AutogenConfig.java | 5 ++++ .../ru/gravit/launcher/LauncherConfig.java | 19 ++++++++++++++ .../ru/gravit/utils/helper/LogHelper.java | 15 ++++++++++- 6 files changed, 67 insertions(+), 6 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 1247f512..a619f2dd 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -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; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java index b6d6182c..e0bf0464 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java @@ -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 = "); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java index 8aef49b1..68ffa9e2 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java @@ -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(); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java index 4434bb6b..371ab370 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java @@ -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() { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java index 6d220f64..abe997e7 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java @@ -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 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 + } } diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java index 46cfa1a3..23125e63 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/LogHelper.java @@ -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 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());