diff --git a/Launcher/runtime/dialog/dialog.js b/Launcher/runtime/dialog/dialog.js index b6c6dbcb..c594965b 100644 --- a/Launcher/runtime/dialog/dialog.js +++ b/Launcher/runtime/dialog/dialog.js @@ -303,7 +303,7 @@ function doLaunchClient(assetDir, assetHDir, clientDir, clientHDir, profile, pp, } function doDebugClient(process) { - if (!LogHelper.isDebugEnabled()) { + if (!settings.debug) { javafx.application.Platform.exit(); return; } diff --git a/Launcher/runtime/dialog/overlay/processing/processing.js b/Launcher/runtime/dialog/overlay/processing/processing.js index d6c0216d..0e4d2bb8 100644 --- a/Launcher/runtime/dialog/overlay/processing/processing.js +++ b/Launcher/runtime/dialog/overlay/processing/processing.js @@ -134,7 +134,7 @@ function makeAuthRequest(login, rsaPassword, callback) { function launchClient(assetHDir, clientHDir, profile, params, callback) { var task = newTask(function() ClientLauncher.launch(assetHDir, clientHDir, - profile, params, LogHelper.isDebugEnabled())); + profile, params, settings.debug)); processing.setTaskProperties(task, callback, null, true); task.updateMessage("Запуск выбранного клиента"); startTask(task); diff --git a/Launcher/runtime/dialog/overlay/settings/settings.js b/Launcher/runtime/dialog/overlay/settings/settings.js index fcedc189..8429fd46 100644 --- a/Launcher/runtime/dialog/overlay/settings/settings.js +++ b/Launcher/runtime/dialog/overlay/settings/settings.js @@ -79,9 +79,9 @@ var settingsOverlay = { }); var debugBox = settingsOverlay.overlay.lookup("#debug"); - debugBox.setSelected(LogHelper.isDebugEnabled()); + debugBox.setSelected(settings.debug); debugBox.selectedProperty()["addListener(javafx.beans.value.ChangeListener)"]( - function(o, ov, nv) LogHelper.setDebugEnabled(nv)); + function(o, ov, nv) settings.debug = nv); holder.lookup("#apply").setOnAction(function(event) overlay.hide(0, null)); }, diff --git a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java index f8c6c03d..b1398d7b 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java @@ -16,25 +16,45 @@ public class ClientLauncherWrapper { public static final String MAGIC_ARG = "-Djdk.attach.allowAttachSelf"; + public static final String WAIT_PROCESS_PROPERTY = "launcher.waitProcess"; + public static boolean waitProcess = Boolean.getBoolean(WAIT_PROCESS_PROPERTY); public static void main(String[] arguments) throws IOException, InterruptedException { LogHelper.printVersion("Launcher"); LogHelper.printLicense("Launcher"); - LogHelper.info("Restart Launcher with JavaAgent..."); - LogHelper.info("If need debug output use -Dlauncher.debug=true"); - LogHelper.info("If need stacktrace output use -Dlauncher.stacktrace=true"); JVMHelper.checkStackTrace(ClientLauncherWrapper.class); JVMHelper.verifySystemProperties(Launcher.class, true); EnvHelper.checkDangerousParams(); - LogHelper.debug("Restart Launcher"); + LauncherConfig config = Launcher.getConfig(); + LogHelper.info("Launcher for project %s", config.projectname); + if(config.environment.equals(LauncherConfig.LauncherEnvironment.PROD)) + { + if(System.getProperty(LogHelper.DEBUG_PROPERTY) != null) + { + LogHelper.warning("Found -Dlauncher.debug=true"); + } + if(System.getProperty(LogHelper.STACKTRACE_PROPERTY) != null) + { + LogHelper.warning("Found -Dlauncher.stacktrace=true"); + } + LogHelper.info("Debug mode disabled (found env PRODUCTION)"); + } + else + { + LogHelper.info("If need debug output use -Dlauncher.debug=true"); + LogHelper.info("If need stacktrace output use -Dlauncher.stacktrace=true"); + if(LogHelper.isDebugEnabled()) waitProcess = true; + } + LogHelper.info("Restart Launcher with JavaAgent..."); ProcessBuilder processBuilder = new ProcessBuilder(); - if (LogHelper.isDebugEnabled()) processBuilder.inheritIO(); + if(waitProcess) processBuilder.inheritIO(); Path javaBin = IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))); List args = new LinkedList<>(); args.add(javaBin.toString()); String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled()))); + args.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, Boolean.toString(LogHelper.isDevEnabled()))); JVMHelper.addSystemPropertyToArgs(args, DirBridge.CUSTOMDIR_PROPERTY); JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_CUSTOMDIR_PROPERTY); JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_OPTDIR_PROPERTY); @@ -48,7 +68,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep LogHelper.debug("Commandline: " + args); processBuilder.command(args); Process process = processBuilder.start(); - if (!LogHelper.isDebugEnabled()) { + if (!waitProcess) { Thread.sleep(3000); if (!process.isAlive()) { int errorcode = process.exitValue(); diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index fec9b5b3..85f82be1 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -31,7 +31,11 @@ public static void main(String... args) throws Throwable { // Start Launcher initGson(); ConsoleManager.initConsole(); - LogHelper.setStacktraceEnabled(true); + LauncherConfig config = Launcher.getConfig(); + if(config.environment.equals(LauncherConfig.LauncherEnvironment.PROD)) + { + if(!LauncherAgent.isStarted()) throw new SecurityException("LauncherAgent must started"); + } long startTime = System.currentTimeMillis(); try { new LauncherEngine().start(args); diff --git a/Launcher/src/main/java/ru/gravit/launcher/NewLauncherSettings.java b/Launcher/src/main/java/ru/gravit/launcher/NewLauncherSettings.java index fa5ccc40..dacf9ed6 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/NewLauncherSettings.java +++ b/Launcher/src/main/java/ru/gravit/launcher/NewLauncherSettings.java @@ -21,6 +21,8 @@ public class NewLauncherSettings { @LauncherAPI public boolean autoEnter; @LauncherAPI + public boolean debug; + @LauncherAPI public boolean fullScreen; @LauncherAPI public boolean offline; diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index a1b9d968..eff70e03 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -375,7 +375,7 @@ public static Process launch( } // Let's rock! process = builder.start(); - if (!LogHelper.isDebugEnabled()) { + if (!pipeOutput) { for (int i = 0; i < 50; ++i) { if (!process.isAlive()) { int exitCode = process.exitValue(); diff --git a/Launcher/src/main/java/ru/gravit/launcher/console/UnlockCommand.java b/Launcher/src/main/java/ru/gravit/launcher/console/UnlockCommand.java new file mode 100644 index 00000000..e2cc5134 --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/console/UnlockCommand.java @@ -0,0 +1,31 @@ +package ru.gravit.launcher.console; + +import ru.gravit.launcher.managers.ConsoleManager; +import ru.gravit.utils.command.Command; +import ru.gravit.utils.helper.LogHelper; + +public class UnlockCommand extends Command { + @Override + public String getArgsDescription() { + return "[key]"; + } + + @Override + public String getUsageDescription() { + return "Unlock other commands"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 1); + if(ConsoleManager.checkUnlockKey(args[0])) + { + LogHelper.info("Unlock successful"); + ConsoleManager.unlock(); + } + else + { + LogHelper.error("Unlock key incorrect"); + } + } +} diff --git a/Launcher/src/main/java/ru/gravit/launcher/managers/ConsoleManager.java b/Launcher/src/main/java/ru/gravit/launcher/managers/ConsoleManager.java index 2e9c3e58..916e595b 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/managers/ConsoleManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/managers/ConsoleManager.java @@ -1,5 +1,6 @@ package ru.gravit.launcher.managers; +import ru.gravit.launcher.console.UnlockCommand; import ru.gravit.utils.command.CommandHandler; import ru.gravit.utils.command.JLineCommandHandler; import ru.gravit.utils.command.StdCommandHandler; @@ -33,5 +34,14 @@ public static void initConsole() throws IOException public static void registerCommands() { handler.registerCommand("help", new HelpCommand(handler)); + handler.registerCommand("unlock", new UnlockCommand()); + } + public static boolean checkUnlockKey(String key) + { + return true; + } + public static void unlock() + { + } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java index b5429d84..2f7a3b4a 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java @@ -32,6 +32,7 @@ public static AutogenConfig getAutogenConfig() { public final Map runtime; public final boolean isWarningMissArchJava; public boolean isNettyEnabled; + public LauncherEnvironment environment; public final String guardLicenseName; public final String guardLicenseKey; @@ -58,6 +59,7 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException else if (config.env == 3) env = LauncherEnvironment.PROD; else env = LauncherEnvironment.STD; Launcher.applyLauncherEnv(env); + environment = env; // Read signed runtime int count = input.readLength(0); Map localResources = new HashMap<>(count); @@ -83,6 +85,7 @@ public LauncherConfig(String address, RSAPublicKey publicKey, Map