mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FEATURE] Блокировка консоли лаунчера
This commit is contained in:
parent
b432f8f13f
commit
02613ceef4
10 changed files with 83 additions and 12 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
},
|
||||
|
|
|
@ -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<String> 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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -21,6 +21,8 @@ public class NewLauncherSettings {
|
|||
@LauncherAPI
|
||||
public boolean autoEnter;
|
||||
@LauncherAPI
|
||||
public boolean debug;
|
||||
@LauncherAPI
|
||||
public boolean fullScreen;
|
||||
@LauncherAPI
|
||||
public boolean offline;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public static AutogenConfig getAutogenConfig() {
|
|||
public final Map<String, byte[]> 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<String, byte[]> localResources = new HashMap<>(count);
|
||||
|
@ -83,6 +85,7 @@ public LauncherConfig(String address, RSAPublicKey publicKey, Map<String, byte[]
|
|||
guardType = "no";
|
||||
isWarningMissArchJava = true;
|
||||
isNettyEnabled = false;
|
||||
environment = LauncherEnvironment.STD;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
@ -98,6 +101,7 @@ public LauncherConfig(String address, RSAPublicKey publicKey, Map<String, byte[]
|
|||
guardType = "no";
|
||||
isWarningMissArchJava = true;
|
||||
isNettyEnabled = false;
|
||||
environment = LauncherEnvironment.STD;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue