Введение LauncherEnvironment

This commit is contained in:
Gravit 2018-12-19 18:24:50 +07:00
parent 99d9533b1c
commit 23966a3b04
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
6 changed files with 67 additions and 6 deletions

View file

@ -32,6 +32,7 @@
import java.util.zip.CRC32; import java.util.zip.CRC32;
import ru.gravit.launcher.Launcher; import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.launcher.managers.GarbageManager; import ru.gravit.launcher.managers.GarbageManager;
import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile;
@ -48,10 +49,7 @@
import ru.gravit.launchserver.auth.handler.AuthHandler; import ru.gravit.launchserver.auth.handler.AuthHandler;
import ru.gravit.launchserver.auth.hwid.HWIDHandler; import ru.gravit.launchserver.auth.hwid.HWIDHandler;
import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.AuthProvider;
import ru.gravit.launchserver.binary.EXEL4JLauncherBinary; import ru.gravit.launchserver.binary.*;
import ru.gravit.launchserver.binary.EXELauncherBinary;
import ru.gravit.launchserver.binary.JARLauncherBinary;
import ru.gravit.launchserver.binary.LauncherBinary;
import ru.gravit.launchserver.command.handler.CommandHandler; import ru.gravit.launchserver.command.handler.CommandHandler;
import ru.gravit.launchserver.command.handler.JLineCommandHandler; import ru.gravit.launchserver.command.handler.JLineCommandHandler;
import ru.gravit.launchserver.command.handler.StdCommandHandler; import ru.gravit.launchserver.command.handler.StdCommandHandler;
@ -114,6 +112,7 @@ public static final class Config extends ConfigObject {
public final String binaryName; public final String binaryName;
private final StringConfigEntry address; private final StringConfigEntry address;
private final String bindAddress; private final String bindAddress;
public final LauncherConfig.LauncherEnvironment env;
private Config(BlockConfigEntry block, Path coredir, LaunchServer server) { private Config(BlockConfigEntry block, Path coredir, LaunchServer server) {
super(block); super(block);
@ -160,6 +159,7 @@ private Config(BlockConfigEntry block, Path coredir, LaunchServer server) {
isUsingWrapper = block.getEntryValue("isUsingWrapper", BooleanConfigEntry.class); isUsingWrapper = block.getEntryValue("isUsingWrapper", BooleanConfigEntry.class);
isDownloadJava = block.getEntryValue("isDownloadJava", BooleanConfigEntry.class); isDownloadJava = block.getEntryValue("isDownloadJava", BooleanConfigEntry.class);
env = LauncherConfig.LauncherEnvironment.STD;
} }

View file

@ -8,6 +8,7 @@
import javassist.CtConstructor; import javassist.CtConstructor;
import javassist.CtMethod; import javassist.CtMethod;
import javassist.NotFoundException; import javassist.NotFoundException;
import ru.gravit.launcher.LauncherConfig;
public class JAConfigurator implements AutoCloseable { public class JAConfigurator implements AutoCloseable {
public ClassPool pool; public ClassPool pool;
@ -92,6 +93,28 @@ public void setPort(int port) {
body.append(port); body.append(port);
body.append(";"); 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) { public void setClientPort(int port) {
body.append("this.clientPort = "); body.append("this.clientPort = ");

View file

@ -215,6 +215,7 @@ private void stdBuild() throws IOException {
jaConfigurator.setClientPort(32148 + SecurityHelper.newRandom().nextInt(512)); jaConfigurator.setClientPort(32148 + SecurityHelper.newRandom().nextInt(512));
jaConfigurator.setUsingWrapper(server.config.isUsingWrapper); jaConfigurator.setUsingWrapper(server.config.isUsingWrapper);
jaConfigurator.setDownloadJava(server.config.isDownloadJava); jaConfigurator.setDownloadJava(server.config.isDownloadJava);
jaConfigurator.setEnv(server.config.env);
server.buildHookManager.registerAllClientModuleClass(jaConfigurator); server.buildHookManager.registerAllClientModuleClass(jaConfigurator);
try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(cleanJar))) { try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(cleanJar))) {
ZipEntry e = input.getNextEntry(); ZipEntry e = input.getNextEntry();

View file

@ -9,6 +9,11 @@ public class AutogenConfig {
public boolean isUsingWrapper; public boolean isUsingWrapper;
public boolean isDownloadJava; //Выставление этого флага требует модификации runtime части public boolean isDownloadJava; //Выставление этого флага требует модификации runtime части
public String secretKeyClient; public String secretKeyClient;
public int env;
// 0 - Dev (дебаг включен по умолчанию, все сообщения)
// 1 - Debug (дебаг включен по умолчанию, основные сообщения)
// 2 - Std (дебаг выключен по умолчанию, основные сообщения)
// 3 - Production (дебаг выключен, минимальный объем сообщений, stacktrace не выводится)
AutogenConfig() { AutogenConfig() {

View file

@ -56,6 +56,20 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException
secretKeyClient = config.secretKeyClient; secretKeyClient = config.secretKeyClient;
isDownloadJava = config.isDownloadJava; isDownloadJava = config.isDownloadJava;
isUsingWrapper = config.isUsingWrapper; 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 // Read signed runtime
int count = input.readLength(0); int count = input.readLength(0);
Map<String, byte[]> localResources = new HashMap<>(count); 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); output.writeByteArray(entry.getValue(), SecurityHelper.CRYPTO_MAX_LENGTH);
} }
} }
public enum LauncherEnvironment
{
DEV,DEBUG,STD,PROD
}
} }

View file

@ -27,6 +27,8 @@ public final class LogHelper {
@LauncherAPI @LauncherAPI
public static final String DEBUG_PROPERTY = "launcher.debug"; public static final String DEBUG_PROPERTY = "launcher.debug";
@LauncherAPI @LauncherAPI
public static final String STACKTRACE_PROPERTY = "launcher.stacktrace";
@LauncherAPI
public static final String NO_JANSI_PROPERTY = "launcher.noJAnsi"; public static final String NO_JANSI_PROPERTY = "launcher.noJAnsi";
@LauncherAPI @LauncherAPI
public static final boolean JANSI; public static final boolean JANSI;
@ -34,6 +36,7 @@ public final class LogHelper {
// Output settings // Output settings
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss", Locale.US); 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 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 Set<Output> OUTPUTS = Collections.newSetFromMap(new ConcurrentHashMap<>(2));
private static final Output STD_OUTPUT; private static final Output STD_OUTPUT;
@ -73,7 +76,7 @@ public static void debug(String format, Object... args) {
@LauncherAPI @LauncherAPI
public static void error(Throwable exc) { public static void error(Throwable exc) {
error(isDebugEnabled() ? toString(exc) : exc.toString()); error(isStacktraceEnabled() ? toString(exc) : exc.toString());
} }
@LauncherAPI @LauncherAPI
@ -106,6 +109,16 @@ public static void setDebugEnabled(boolean debugEnabled) {
DEBUG_ENABLED.set(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 @LauncherAPI
public static void log(Level level, String message, boolean sub) { public static void log(Level level, String message, boolean sub) {
String dateTime = DATE_TIME_FORMATTER.format(LocalDateTime.now()); String dateTime = DATE_TIME_FORMATTER.format(LocalDateTime.now());