mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] Опция отключения файл-сервера + автокопирование binaries (тоже опция). (#236)
* [FIX] Убраны лишние классы из libLauncher. * [FIX] Получение RAM. * [FIX] Ещё фиксы такового с RAM. * [REFACTOR] Удалён лишний код. * [FEATURE] Теперь прикрутить sentry можно просто добавив библиотеку в libraries и дописав 3 строчки в runtime. * [FIX] Ошибка в паттернах ServerWrapper, порождает java.util.IllegalFormatConversionException * [FEATURE] Чистка конфига. * [FIX] Убрал лишние варнинги. * [FIX] Мои ошибки.
This commit is contained in:
parent
10a441b2ae
commit
c6c86afce1
8 changed files with 33 additions and 30 deletions
|
@ -80,6 +80,8 @@ public static final class Config {
|
||||||
|
|
||||||
public String binaryName;
|
public String binaryName;
|
||||||
|
|
||||||
|
public boolean copyBinaries = true;
|
||||||
|
|
||||||
public LauncherConfig.LauncherEnvironment env;
|
public LauncherConfig.LauncherEnvironment env;
|
||||||
|
|
||||||
// Handlers & Providers
|
// Handlers & Providers
|
||||||
|
@ -269,7 +271,7 @@ public class LauncherConf
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NettyConfig {
|
public class NettyConfig {
|
||||||
public boolean clientEnabled;
|
public boolean fileServerEnabled;
|
||||||
public boolean sendExceptionEnabled;
|
public boolean sendExceptionEnabled;
|
||||||
public String launcherURL;
|
public String launcherURL;
|
||||||
public String downloadURL;
|
public String downloadURL;
|
||||||
|
@ -704,11 +706,7 @@ private void generateConfigIfNotExists(boolean testEnv) throws IOException {
|
||||||
newConfig.whitelistRejectString = "Вас нет в белом списке";
|
newConfig.whitelistRejectString = "Вас нет в белом списке";
|
||||||
|
|
||||||
newConfig.netty = new NettyConfig();
|
newConfig.netty = new NettyConfig();
|
||||||
newConfig.netty.address = "ws://localhost:9274/api";
|
newConfig.netty.fileServerEnabled = true;
|
||||||
newConfig.netty.downloadURL = "http://localhost:9274/%dirname%/";
|
|
||||||
newConfig.netty.launcherURL = "http://localhost:9274/Launcher.jar";
|
|
||||||
newConfig.netty.launcherEXEURL = "http://localhost:9274/Launcher.exe";
|
|
||||||
newConfig.netty.clientEnabled = false;
|
|
||||||
newConfig.netty.binds = new NettyBindAddress[]{ new NettyBindAddress("0.0.0.0", 9274) };
|
newConfig.netty.binds = new NettyBindAddress[]{ new NettyBindAddress("0.0.0.0", 9274) };
|
||||||
newConfig.netty.performance = new NettyPerformanceConfig();
|
newConfig.netty.performance = new NettyPerformanceConfig();
|
||||||
newConfig.netty.performance.bossThread = 2;
|
newConfig.netty.performance.bossThread = 2;
|
||||||
|
@ -734,19 +732,20 @@ private void generateConfigIfNotExists(boolean testEnv) throws IOException {
|
||||||
newConfig.components.put("authLimiter", authLimiterComponent);
|
newConfig.components.put("authLimiter", authLimiterComponent);
|
||||||
|
|
||||||
// Set server address
|
// Set server address
|
||||||
|
String address;
|
||||||
if (testEnv) {
|
if (testEnv) {
|
||||||
newConfig.setLegacyAddress("localhost");
|
address = "localhost";
|
||||||
newConfig.setProjectName("test");
|
newConfig.setProjectName("test");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("LaunchServer legacy address(default: localhost): ");
|
System.out.println("LaunchServer address(default: localhost): ");
|
||||||
newConfig.setLegacyAddress(commandHandler.readLine());
|
address = commandHandler.readLine();
|
||||||
System.out.println("LaunchServer projectName: ");
|
System.out.println("LaunchServer projectName: ");
|
||||||
newConfig.setProjectName(commandHandler.readLine());
|
newConfig.setProjectName(commandHandler.readLine());
|
||||||
}
|
}
|
||||||
if(newConfig.legacyAddress == null)
|
if(address == null)
|
||||||
{
|
{
|
||||||
LogHelper.error("Legacy address null. Using localhost");
|
LogHelper.error("Address null. Using localhost");
|
||||||
newConfig.legacyAddress = "localhost";
|
address = "localhost";
|
||||||
}
|
}
|
||||||
if(newConfig.projectName == null)
|
if(newConfig.projectName == null)
|
||||||
{
|
{
|
||||||
|
@ -754,6 +753,13 @@ private void generateConfigIfNotExists(boolean testEnv) throws IOException {
|
||||||
newConfig.projectName = "MineCraft";
|
newConfig.projectName = "MineCraft";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newConfig.legacyAddress = address;
|
||||||
|
newConfig.netty.address = "ws://" + address + ":9274/api";
|
||||||
|
newConfig.netty.downloadURL = "http://" + address + ":9274/%dirname%/";
|
||||||
|
newConfig.netty.launcherURL = "http://" + address + ":9274/internal/Launcher.jar";
|
||||||
|
newConfig.netty.launcherEXEURL = "http://" + address + ":9274/internal/Launcher.exe";
|
||||||
|
newConfig.netty.sendExceptionEnabled = true;
|
||||||
|
|
||||||
// Write LaunchServer config
|
// Write LaunchServer config
|
||||||
LogHelper.info("Writing LaunchServer config file");
|
LogHelper.info("Writing LaunchServer config file");
|
||||||
try (BufferedWriter writer = IOHelper.newWriter(configFile)) {
|
try (BufferedWriter writer = IOHelper.newWriter(configFile)) {
|
||||||
|
@ -836,14 +842,14 @@ public void syncUpdatesDir(Collection<String> dirs) throws IOException {
|
||||||
LogHelper.info("Syncing updates dir");
|
LogHelper.info("Syncing updates dir");
|
||||||
Map<String, SignedObjectHolder<HashedDir>> newUpdatesDirMap = new HashMap<>(16);
|
Map<String, SignedObjectHolder<HashedDir>> newUpdatesDirMap = new HashMap<>(16);
|
||||||
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(updatesDir)) {
|
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(updatesDir)) {
|
||||||
for (Path updateDir : dirStream) {
|
for (final Path updateDir : dirStream) {
|
||||||
if (Files.isHidden(updateDir))
|
if (Files.isHidden(updateDir))
|
||||||
continue; // Skip hidden
|
continue; // Skip hidden
|
||||||
|
|
||||||
// Resolve name and verify is dir
|
// Resolve name and verify is dir
|
||||||
String name = IOHelper.getFileName(updateDir);
|
String name = IOHelper.getFileName(updateDir);
|
||||||
if (!IOHelper.isDir(updateDir)) {
|
if (!IOHelper.isDir(updateDir)) {
|
||||||
LogHelper.warning("Not update dir: '%s'", name);
|
if (!IOHelper.isFile(updateDir) && Arrays.asList(".jar", ".exe", ".hash").stream().noneMatch(e -> updateDir.toString().endsWith(e))) LogHelper.warning("Not update dir: '%s'", name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ public void clear() {
|
||||||
|
|
||||||
|
|
||||||
public EXEL4JLauncherBinary(LaunchServer server) {
|
public EXEL4JLauncherBinary(LaunchServer server) {
|
||||||
super(server, server.dir.resolve(server.config.binaryName + ".exe"));
|
super(server, LauncherBinary.resolve(server, ".exe"));
|
||||||
faviconFile = server.dir.resolve("favicon.ico");
|
faviconFile = server.dir.resolve("favicon.ico");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
public class EXELauncherBinary extends LauncherBinary {
|
public class EXELauncherBinary extends LauncherBinary {
|
||||||
|
|
||||||
public EXELauncherBinary(LaunchServer server) {
|
public EXELauncherBinary(LaunchServer server) {
|
||||||
super(server, server.dir.resolve(server.config.binaryName + ".exe"));
|
super(server, LauncherBinary.resolve(server, ".exe"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,9 +24,8 @@ public final class JARLauncherBinary extends LauncherBinary {
|
||||||
public List<Path> addonLibs;
|
public List<Path> addonLibs;
|
||||||
|
|
||||||
public JARLauncherBinary(LaunchServer server) throws IOException {
|
public JARLauncherBinary(LaunchServer server) throws IOException {
|
||||||
super(server);
|
super(server, LauncherBinary.resolve(server, ".jar"));
|
||||||
count = new AtomicLong(0);
|
count = new AtomicLong(0);
|
||||||
syncBinaryFile = server.dir.resolve(server.config.binaryName + ".jar");
|
|
||||||
runtimeDir = server.dir.resolve(Launcher.RUNTIME_DIR);
|
runtimeDir = server.dir.resolve(Launcher.RUNTIME_DIR);
|
||||||
guardDir = server.dir.resolve(Launcher.GUARD_DIR);
|
guardDir = server.dir.resolve(Launcher.GUARD_DIR);
|
||||||
buildDir = server.dir.resolve("build");
|
buildDir = server.dir.resolve("build");
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
public abstract class LauncherBinary {
|
public abstract class LauncherBinary {
|
||||||
public final LaunchServer server;
|
public final LaunchServer server;
|
||||||
public Path syncBinaryFile;
|
public final Path syncBinaryFile;
|
||||||
private volatile DigestBytesHolder binary;
|
private volatile DigestBytesHolder binary;
|
||||||
private volatile byte[] sign;
|
private volatile byte[] sign;
|
||||||
|
|
||||||
|
@ -19,10 +19,6 @@ protected LauncherBinary(LaunchServer server, Path binaryFile) {
|
||||||
syncBinaryFile = binaryFile;
|
syncBinaryFile = binaryFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected LauncherBinary(LaunchServer server) {
|
|
||||||
this.server = server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void build() throws IOException;
|
public abstract void build() throws IOException;
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,4 +45,8 @@ public final boolean sync() throws IOException {
|
||||||
|
|
||||||
return exists;
|
return exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final Path resolve(LaunchServer server, String ext) {
|
||||||
|
return server.config.copyBinaries ? server.updatesDir.resolve(server.config.binaryName + ext) : server.dir.resolve(server.config.binaryName + ext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public void initChannel(NioSocketChannel ch) {
|
||||||
pipeline.addLast(new HttpObjectAggregator(65536));
|
pipeline.addLast(new HttpObjectAggregator(65536));
|
||||||
pipeline.addLast(new WebSocketServerCompressionHandler());
|
pipeline.addLast(new WebSocketServerCompressionHandler());
|
||||||
pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
|
pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
|
||||||
pipeline.addLast(new FileServerHandler(LaunchServer.server.updatesDir, true));
|
if (LaunchServer.server.config.netty.fileServerEnabled) pipeline.addLast(new FileServerHandler(LaunchServer.server.updatesDir, true));
|
||||||
pipeline.addLast(new WebSocketFrameHandler());
|
pipeline.addLast(new WebSocketFrameHandler());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -56,9 +56,9 @@ public static HWID getHWID() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static long getTotalMemory() {
|
public static int getTotalMemory() {
|
||||||
if (cachedMemorySize > 0) return cachedMemorySize;
|
if (cachedMemorySize > 0) return (int)cachedMemorySize;
|
||||||
return cachedMemorySize = hwidProvider.getTotalMemory() >> 20;
|
return (int)(cachedMemorySize = hwidProvider.getTotalMemory() >> 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -67,7 +67,7 @@ public static int getClientJVMBits() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static long getJVMTotalMemory() {
|
public static int getJVMTotalMemory() {
|
||||||
if (getClientJVMBits() == 32) {
|
if (getClientJVMBits() == 32) {
|
||||||
return Math.min(getTotalMemory(), 1536);
|
return Math.min(getTotalMemory(), 1536);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
public class LauncherSSLContext {
|
public class LauncherSSLContext {
|
||||||
public SSLServerSocketFactory ssf;
|
public SSLServerSocketFactory ssf;
|
||||||
public SSLSocketFactory sf;
|
public SSLSocketFactory sf;
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private SSLContext sc;
|
|
||||||
|
|
||||||
public LauncherSSLContext(KeyStore ks, String keypassword) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException {
|
public LauncherSSLContext(KeyStore ks, String keypassword) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException {
|
||||||
TrustManager[] trustAllCerts = new TrustManager[]{
|
TrustManager[] trustAllCerts = new TrustManager[]{
|
||||||
|
|
Loading…
Reference in a new issue