From 3d8225330852f8727de44af73032d629f7cfe6a2 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 28 Mar 2019 11:21:51 +0700 Subject: [PATCH 001/128] [ANY] 4.5.1 dev --- libLauncher/src/main/java/ru/gravit/launcher/Launcher.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index e54d5414..22512557 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -60,9 +60,9 @@ public final class Launcher { private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL); public static final int MAJOR = 4; public static final int MINOR = 5; - public static final int PATCH = 0; + public static final int PATCH = 1; public static final int BUILD = 1; - public static final Version.Type RELEASE = Version.Type.STABLE; + public static final Version.Type RELEASE = Version.Type.DEV; public static GsonBuilder gsonBuilder; public static Gson gson; From fee94ff368f9fa4928feeeafd93b89526cc88c11 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 28 Mar 2019 12:07:54 +0700 Subject: [PATCH 002/128] =?UTF-8?q?[FEATURE]=20=D0=9A=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D0=BD=D0=B4=D1=8B,=20Reload/Reconfigurable=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B2=D0=B8=D1=81=D1=8F=D1=82=20=D0=BE=D1=82=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/manangers/ReconfigurableManager.java | 6 +++--- .../ru/gravit/launchserver/manangers/ReloadManager.java | 6 +++--- .../main/java/ru/gravit/utils/command/CommandHandler.java | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java index 56ab43f0..c3133a96 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java @@ -11,16 +11,16 @@ public class ReconfigurableManager { private final HashMap RECONFIGURABLE = new HashMap<>(); public void registerReconfigurable(String name, Reconfigurable reconfigurable) { - VerifyHelper.putIfAbsent(RECONFIGURABLE, name, Objects.requireNonNull(reconfigurable, "adapter"), + VerifyHelper.putIfAbsent(RECONFIGURABLE, name.toLowerCase(), Objects.requireNonNull(reconfigurable, "adapter"), String.format("Reloadable has been already registered: '%s'", name)); } public void printHelp(String name) { - RECONFIGURABLE.get(name).printConfigHelp(); + RECONFIGURABLE.get(name.toLowerCase()).printConfigHelp(); } public void call(String name, String action, String[] args) { - RECONFIGURABLE.get(name).reconfig(action, args); + RECONFIGURABLE.get(name.toLowerCase()).reconfig(action.toLowerCase(), args); } public void printReconfigurables() { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReloadManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReloadManager.java index 33eb7872..95a06e6e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReloadManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReloadManager.java @@ -11,8 +11,8 @@ public class ReloadManager { private final HashMap RELOADABLES = new HashMap<>(); public void registerReloadable(String name, Reloadable reloadable) { - VerifyHelper.putIfAbsent(RELOADABLES, name, Objects.requireNonNull(reloadable, "adapter"), - String.format("Reloadable has been already registered: '%s'", name)); + VerifyHelper.putIfAbsent(RELOADABLES, name.toLowerCase(), Objects.requireNonNull(reloadable, "adapter"), + String.format("Reloadable has been already registered: '%s'", name.toLowerCase())); } public void reloadAll() { @@ -26,7 +26,7 @@ public void reloadAll() { } public void reload(String name) throws Exception { - RELOADABLES.get(name).reload(); + RELOADABLES.get(name.toLowerCase()).reload(); } public void printReloadables() { diff --git a/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java b/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java index 4076888f..8739cd42 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java +++ b/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java @@ -21,6 +21,7 @@ public void eval(String line, boolean bell) { String[] args; try { args = CommonHelper.parseCommand(line); + if(args.length > 0) args[0] = args[0].toLowerCase(); } catch (Exception e) { LogHelper.error(e); return; @@ -72,8 +73,8 @@ private void readLoop() throws IOException { public void registerCommand(String name, Command command) { VerifyHelper.verifyIDName(name); - VerifyHelper.putIfAbsent(commands, name, Objects.requireNonNull(command, "command"), - String.format("Command has been already registered: '%s'", name)); + VerifyHelper.putIfAbsent(commands, name.toLowerCase(), Objects.requireNonNull(command, "command"), + String.format("Command has been already registered: '%s'", name.toLowerCase())); } @Override From 0194ab7a5b7bf2808f1b0ad287b57407a75a810f Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 28 Mar 2019 12:39:22 +0700 Subject: [PATCH 003/128] =?UTF-8?q?[FEATURE]=20=D0=9C=D0=BE=D0=B4=D1=83?= =?UTF-8?q?=D0=BB=D1=8C=20ServerScriptEngine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 043b9ac4..be22f5b7 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 043b9ac4ffbca9a7378f22d7feeb4829e630a6c3 +Subproject commit be22f5b74912bda8df26ce888af994f330cc8934 From 695758aa187df8f4872d49411a4742ad96c2ae27 Mon Sep 17 00:00:00 2001 From: Zaxar163 <35835496+Zaxar163@users.noreply.github.com> Date: Thu, 28 Mar 2019 11:54:18 +0300 Subject: [PATCH 004/128] =?UTF-8?q?[FIX]=20=D0=92=D0=BB=D0=B5=D0=B7=D0=B0?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=B2=20=D0=BB=D0=B0=D1=83=D0=BD=D1=87=D0=B5?= =?UTF-8?q?=D1=80=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20agent.=20(#202)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [FIX] Правки градла. * [FEATURE] Скрипт для скачивания. * [DOCS] Правки readme. * [FIX][DOCS] Удален неактуальная папка docs. * [DOCS] Готов readme. * [FIX] Launcher sign. * [FEATURE] Модули по новому. * [FIX] Способ влезть в лаунчер через agent. * [ANY] Обновлены модули (там фикс JarSigner). * [FEATURE] ListDownloader. --- LaunchServer/build.gradle | 2 + .../launcher/ClientLauncherWrapper.java | 4 ++ .../launcher/client/ClientLauncher.java | 12 ++--- LauncherAPI/build.gradle | 1 + .../launcher/downloader/ListDownloader.java | 52 +++++++++++++++++++ README.md | 7 ++- docs/EN-changes.md | 19 ------- docs/RU-changes.md | 19 ------- get_it.sh | 4 ++ module.gradle | 7 +++ modules | 2 +- 11 files changed, 81 insertions(+), 48 deletions(-) create mode 100644 LauncherAPI/src/main/java/ru/gravit/launcher/downloader/ListDownloader.java delete mode 100644 docs/EN-changes.md delete mode 100644 docs/RU-changes.md create mode 100755 get_it.sh create mode 100644 module.gradle diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index 228ffe3c..090eb514 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -1,6 +1,8 @@ def mainClassName = "ru.gravit.launchserver.LaunchServer" def mainAgentName = "ru.gravit.launchserver.StarterAgent" +evaluationDependsOn(':Launcher') + repositories { maven { url "https://oss.sonatype.org/content/repositories/snapshots" diff --git a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java index eb0f6aa9..36af51a6 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java @@ -15,6 +15,8 @@ import java.util.List; public class ClientLauncherWrapper { + public static final String MAGIC_ARG = "-Djdk.attach.allowAttachSelf"; + public static void main(String[] arguments) throws IOException, InterruptedException { LogHelper.printVersion("Launcher"); LogHelper.printLicense("Launcher"); @@ -36,6 +38,8 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep JVMHelper.addSystemPropertyToArgs(args, DirBridge.CUSTOMDIR_PROPERTY); JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_CUSTOMDIR_PROPERTY); JVMHelper.addSystemPropertyToArgs(args, DirBridge.USE_OPTDIR_PROPERTY); + Collections.addAll(args, MAGIC_ARG); + Collections.addAll(args, "-XX:+DisableAttachMechanism"); Collections.addAll(args, "-javaagent:".concat(pathLauncher)); Collections.addAll(args, "-cp"); Collections.addAll(args, pathLauncher); 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 f684ec33..354ed894 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -11,6 +11,7 @@ import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.request.Request; +import ru.gravit.launcher.request.update.LegacyLauncherRequest; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.stream.StreamObject; @@ -34,8 +35,6 @@ import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.PosixFilePermission; import java.util.*; -import java.util.Timer; -import java.util.concurrent.TimeUnit; public final class ClientLauncher { private static Gson gson = new Gson(); @@ -301,7 +300,6 @@ private static void launch(ClientProfile profile, Params params) throws Throwabl public static Process launch( HashedDir assetHDir, HashedDir clientHDir, ClientProfile profile, Params params, boolean pipeOutput) throws Throwable { - // Write params file (instead of CLI; Mustdie32 API can't handle command line > 32767 chars) LogHelper.debug("Writing ClientLauncher params"); ClientLauncherContext context = new ClientLauncherContext(); clientStarted = false; @@ -368,6 +366,7 @@ public static Process launch( // Add classpath and main class String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); context.pathLauncher = pathLauncher; + Collections.addAll(context.args, ClientLauncherWrapper.MAGIC_ARG); Collections.addAll(context.args, profile.getJvmArgs()); profile.pushOptionalJvmArgs(context.args); Collections.addAll(context.args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path @@ -434,7 +433,6 @@ public static void main(String... args) throws Throwable { engine.runtimeProvider.init(true); engine.runtimeProvider.preLoad(); LauncherGuardManager.initGuard(true); - // Read and delete params file LogHelper.debug("Reading ClientLauncher params"); Params params; ClientProfile profile; @@ -445,8 +443,6 @@ public static void main(String... args) throws Throwable { try (HInput input = new HInput(socket.getInputStream())) { params = new Params(input); profile = gson.fromJson(input.readString(0), ClientProfile.class); - - // Read hdirs assetHDir = new HashedDir(input); clientHDir = new HashedDir(input); } @@ -462,8 +458,8 @@ public static void main(String... args) throws Throwable { Launcher.modulesManager.initModules(); // Verify ClientLauncher sign and classpath LogHelper.debug("Verifying ClientLauncher sign and classpath"); - //TODO: GO TO DIGEST - //SecurityHelper.verifySign(LegacyLauncherRequest.BINARY_PATH, params.launcherDigest, publicKey); + //Warning - experimental. + SecurityHelper.verifySign(LegacyLauncherRequest.BINARY_PATH, params.launcherDigest, Launcher.getConfig().publicKey); LinkedList classPath = resolveClassPathList(params.clientDir, profile.getClassPath()); for (Path classpathURL : classPath) { LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); diff --git a/LauncherAPI/build.gradle b/LauncherAPI/build.gradle index 1a9366f9..95d23990 100644 --- a/LauncherAPI/build.gradle +++ b/LauncherAPI/build.gradle @@ -4,6 +4,7 @@ dependencies { compile project(':libLauncher') compile 'org.java-websocket:Java-WebSocket:1.3.9' + compile 'org.apache.httpcomponents:httpclient:4.5.7' compileOnly 'com.google.guava:guava:26.0-jre' compile files('../compat/authlib/authlib-clean.jar') } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/downloader/ListDownloader.java b/LauncherAPI/src/main/java/ru/gravit/launcher/downloader/ListDownloader.java new file mode 100644 index 00000000..b1a54412 --- /dev/null +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/downloader/ListDownloader.java @@ -0,0 +1,52 @@ +package ru.gravit.launcher.downloader; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Path; +import java.util.List; + +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.client.LaxRedirectStrategy; + +import ru.gravit.utils.helper.IOHelper; + +public class ListDownloader { + public void download(String base, List applies, Path dstDirFile) throws IOException, URISyntaxException { + try(CloseableHttpClient httpclient = HttpClients.custom() + .setRedirectStrategy(new LaxRedirectStrategy()) + .build()) { + + HttpGet get = null; + for (String apply : applies) { + URI u = new URL(base.concat(apply)).toURI(); + if (get == null) get = new HttpGet(u); + else { + get.reset(); + get.setURI(u); + } + httpclient.execute(get, new FileDownloadResponseHandler(dstDirFile.resolve(apply))); + } + } + } + + static class FileDownloadResponseHandler implements ResponseHandler { + private final Path target; + public FileDownloadResponseHandler(Path target) { + this.target = target; + } + @Override + public Path handleResponse(HttpResponse response) throws ClientProtocolException, IOException { + InputStream source = response.getEntity().getContent(); + IOHelper.transfer(source, this.target); + return this.target; + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index e786a5d3..051f38c6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ # Modification of the launcher sashok724's v3 from Gravit [![Build Status](https://travis-ci.com/GravitLauncher/Launcher.svg?branch=master)](https://travis-ci.com/GravitLauncher/Launcher) * Discord channel: https://discord.gg/aJK6nMN * [See license](LICENSE) -* Changes: [ru-ru](docs/RU-changes.md#Изменения) [en-us](docs/EN-changes.md#changes) +* [See code of conduct](CODE_OF_CONDUCT.md) +* [WIKI](https://launcher.gravit.pro) +* Get it (requires cURL): +```sh +curl -s https://raw.githubusercontent.com/GravitLauncher/Launcher/master/get_it.sh | sh +``` diff --git a/docs/EN-changes.md b/docs/EN-changes.md deleted file mode 100644 index e82d12df..00000000 --- a/docs/EN-changes.md +++ /dev/null @@ -1,19 +0,0 @@ -# Changes -* Build with Gradle -* The code is free of many dirty "hacks" that depend on the implementation and undocumented features of a particular JVM -* Removed JVM installation -* Brute-force attack protection -* Launcher compiles and runs with JDK 10 -* Patched launchwrapper with Java 10 support -* ClassPath is not visible in the start line -* Symlinks are fully allowed without restrictions -* Removed an undocumented feature which allowed to use JavaScript plugins on server side -* Various improvements and bugfixes -* Split into 5 modules instead of two -* The old bypasses don't work -* Partially modified structure of the classes -* Bug fixes in the main branch of the launcher -* Ability to install different skins on different servers -* Send HWID -* Flexible exe settings when building -* And much more! diff --git a/docs/RU-changes.md b/docs/RU-changes.md deleted file mode 100644 index 617f628e..00000000 --- a/docs/RU-changes.md +++ /dev/null @@ -1,19 +0,0 @@ -# -* Gradle -* "", JVM -* JVM -* -* JDK 10 -* launchwrapper Java 10 -* ClassPath -* -* JavaScript -* -* 5 -* -* -* -* -* HWID -* exe -* ! \ No newline at end of file diff --git a/get_it.sh b/get_it.sh new file mode 100755 index 00000000..f37055af --- /dev/null +++ b/get_it.sh @@ -0,0 +1,4 @@ +#!/bin/sh +git clone https://github.com/GravitLauncher/Launcher.git +sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules +git submodule update --init --recursive diff --git a/module.gradle b/module.gradle new file mode 100644 index 00000000..a5690396 --- /dev/null +++ b/module.gradle @@ -0,0 +1,7 @@ +dependencies { + compileOnly project(':LaunchServer') +} +jar { + from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } } +} + diff --git a/modules b/modules index be22f5b7..8df678be 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit be22f5b74912bda8df26ce888af994f330cc8934 +Subproject commit 8df678bed74b671ba0f0866f8f215fd42e467c03 From 24aefd47f113f93641d9c90bc23915ee98e74185 Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 28 Mar 2019 17:13:27 +0700 Subject: [PATCH 005/128] [FEATURE] MemoryHWIDHandler/JsonFileHWIDHandler --- .../ru/gravit/launchserver/LaunchServer.java | 4 + .../auth/hwid/AcceptHWIDHandler.java | 5 + .../launchserver/auth/hwid/HWIDHandler.java | 3 + .../auth/hwid/JsonFileHWIDHandler.java | 118 ++++++++++++++++++ .../auth/hwid/JsonHWIDHandler.java | 5 + .../auth/hwid/MemoryHWIDHandler.java | 93 ++++++++++++++ .../auth/hwid/MysqlHWIDHandler.java | 5 + .../permissions/ConfigPermissionsHandler.java | 5 + .../DefaultPermissionsHandler.java | 5 + .../JsonFilePermissionsHandler.java | 15 ++- .../JsonLongFilePermissionsHandler.java | 15 ++- .../auth/permissions/PermissionsHandler.java | 2 + .../java/ru/gravit/launcher/OshiHWID.java | 31 +++++ .../gravit/utils/command/CommandHandler.java | 4 + 14 files changed, 300 insertions(+), 10 deletions(-) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index f5ca38f7..f3299a08 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -68,6 +68,8 @@ public void reload() throws Exception { for (AuthProviderPair auth : config.auth) { auth.init(); } + config.permissionsHandler.init(); + config.hwidHandler.init(); } public static final class Config { @@ -460,6 +462,8 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE for (AuthProviderPair provider : config.auth) { provider.init(); } + config.permissionsHandler.init(); + config.hwidHandler.init(); if(config.protectHandler != null) { config.protectHandler.checkLaunchServerLicense(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java index ee657875..06f29c91 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java @@ -22,6 +22,11 @@ public void close() { //SKIP } + @Override + public void init() { + + } + @Override public List getHwid(String username) { return new ArrayList<>(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java index 2e816879..e72f7ef2 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java @@ -24,6 +24,7 @@ public static void registerHandlers() { registerHandler("accept", AcceptHWIDHandler.class); registerHandler("mysql", MysqlHWIDHandler.class); registerHandler("json", JsonHWIDHandler.class); + registerHandler("memory", MemoryHWIDHandler.class); registredHandl = true; } } @@ -40,6 +41,8 @@ public void check(HWID hwid, String username) throws HWIDException { @Override public abstract void close() throws Exception; + public abstract void init(); + public abstract List getHwid(String username) throws HWIDException; public abstract void unban(List hwid) throws HWIDException; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java new file mode 100644 index 00000000..d8b6c6a8 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java @@ -0,0 +1,118 @@ +package ru.gravit.launchserver.auth.hwid; + +import com.google.gson.reflect.TypeToken; +import ru.gravit.launcher.ClientPermissions; +import ru.gravit.launcher.HWID; +import ru.gravit.launcher.Launcher; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.LogHelper; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.lang.reflect.Type; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class JsonFileHWIDHandler extends HWIDHandler { + public class Entry + { + public HWID hwid; + public String username; + public boolean isBanned = false; + + public Entry(HWID hwid) { + this.hwid = hwid; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Entry entry = (Entry) o; + return Objects.equals(hwid, entry.hwid); + } + + @Override + public int hashCode() { + return Objects.hash(hwid); + } + } + public String filename = "hwids.json"; + public transient LinkedList list = new LinkedList<>(); + public String banMessage = "You banned"; + @Override + public void ban(List hwid) throws HWIDException { + for(Entry e : list) + { + for(HWID banHWID : hwid) + { + if(e.hwid.equals(banHWID)) e.isBanned = true; + } + } + } + @Override + public void init() + { + Path path = Paths.get(filename); + Type type = new TypeToken>() { + }.getType(); + try (Reader reader = IOHelper.newReader(path)) { + list = Launcher.gson.fromJson(reader, type); + } catch (IOException e) { + LogHelper.error(e); + } + } + + @Override + public void check0(HWID hwid, String username) throws HWIDException { + boolean isOne = false; + for(Entry e : list) + { + if(e.hwid.equals(hwid)) + { + isOne = true; + if(e.isBanned) throw new HWIDException(banMessage); + } + } + if(!isOne) + { + list.add(new Entry(hwid)); + } + } + + @Override + public void close() throws Exception { + Path path = Paths.get(filename); + try(Writer writer = IOHelper.newWriter(path)) + { + LaunchServer.gson.toJson(list, writer); + } + } + + @Override + public List getHwid(String username) throws HWIDException { + LinkedList hwids = new LinkedList<>(); + for(Entry e : list) + { + if(e.username.equals(username)) hwids.add(e.hwid); + } + return hwids; + } + + @Override + public void unban(List hwid) throws HWIDException { + for(Entry e : list) + { + for(HWID banHWID : hwid) + { + if(e.hwid.equals(banHWID)) e.isBanned = false; + } + } + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java index 0b222231..de0d1536 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java @@ -111,6 +111,11 @@ public void close() { // pass } + @Override + public void init() { + + } + @Override public List getHwid(String username) throws HWIDException { ArrayList hwids = new ArrayList<>(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java new file mode 100644 index 00000000..07c7de02 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java @@ -0,0 +1,93 @@ +package ru.gravit.launchserver.auth.hwid; + +import ru.gravit.launcher.HWID; + +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; + +public class MemoryHWIDHandler extends HWIDHandler { + public class Entry + { + public HWID hwid; + public String username; + public boolean isBanned = false; + + public Entry(HWID hwid) { + this.hwid = hwid; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Entry entry = (Entry) o; + return Objects.equals(hwid, entry.hwid); + } + + @Override + public int hashCode() { + return Objects.hash(hwid); + } + } + public transient LinkedList list = new LinkedList<>(); + public String banMessage = "You banned"; + @Override + public void ban(List hwid) throws HWIDException { + for(Entry e : list) + { + for(HWID banHWID : hwid) + { + if(e.hwid.equals(banHWID)) e.isBanned = true; + } + } + } + + @Override + public void check0(HWID hwid, String username) throws HWIDException { + boolean isOne = false; + for(Entry e : list) + { + if(e.hwid.equals(hwid)) + { + isOne = true; + if(e.isBanned) throw new HWIDException(banMessage); + } + } + if(!isOne) + { + list.add(new Entry(hwid)); + } + } + + @Override + public void close() throws Exception { + + } + + @Override + public void init() { + + } + + @Override + public List getHwid(String username) throws HWIDException { + LinkedList hwids = new LinkedList<>(); + for(Entry e : list) + { + if(e.username.equals(username)) hwids.add(e.hwid); + } + return hwids; + } + + @Override + public void unban(List hwid) throws HWIDException { + for(Entry e : list) + { + for(HWID banHWID : hwid) + { + if(e.hwid.equals(banHWID)) e.isBanned = false; + } + } + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java index 1201815b..a7dbd40f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java @@ -250,4 +250,9 @@ public List getHwid(String username) { public void close() { mySQLHolder.close(); } + + @Override + public void init() { + + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java index 4ffe4a74..44f12eff 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java @@ -6,6 +6,11 @@ public class ConfigPermissionsHandler extends PermissionsHandler { public boolean isAdmin = false; public boolean isServer = false; + @Override + public void init() { + + } + @Override public ClientPermissions getPermissions(String username) { ClientPermissions permissions = new ClientPermissions(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java index b434bb5e..4b14873b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java @@ -3,6 +3,11 @@ import ru.gravit.launcher.ClientPermissions; public class DefaultPermissionsHandler extends PermissionsHandler { + @Override + public void init() { + + } + @Override public ClientPermissions getPermissions(String username) { return ClientPermissions.DEFAULT; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java index c46c1857..bd3903f2 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java @@ -44,11 +44,7 @@ public static class Enity { } @Override - public ClientPermissions getPermissions(String username) { - return map.getOrDefault(username, ClientPermissions.DEFAULT); - } - - public JsonFilePermissionsHandler() { + public void init() { Type type = new TypeToken>() { }.getType(); Path path = Paths.get(filename); @@ -66,4 +62,13 @@ public JsonFilePermissionsHandler() { LogHelper.error(e); } } + + @Override + public ClientPermissions getPermissions(String username) { + return map.getOrDefault(username, ClientPermissions.DEFAULT); + } + + public JsonFilePermissionsHandler() { + + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java index d7d98402..ada99916 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java @@ -45,11 +45,7 @@ public static class Enity { } @Override - public ClientPermissions getPermissions(String username) { - return new ClientPermissions(map.getOrDefault(username, defaultPerms)); - } - - public JsonLongFilePermissionsHandler() { + public void init() { Type type = new TypeToken>() { }.getType(); Path path = Paths.get(filename); @@ -67,4 +63,13 @@ public JsonLongFilePermissionsHandler() { LogHelper.error(e); } } + + @Override + public ClientPermissions getPermissions(String username) { + return new ClientPermissions(map.getOrDefault(username, defaultPerms)); + } + + public JsonLongFilePermissionsHandler() { + + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java index d7058b71..d3898138 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java @@ -38,5 +38,7 @@ public static void registerHandlers() { } } + public abstract void init(); + public abstract ClientPermissions getPermissions(String username); } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java b/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java index 5d52e491..dabdacea 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java @@ -2,6 +2,9 @@ import com.google.gson.Gson; +import java.util.Objects; +import java.util.StringJoiner; + public class OshiHWID implements HWID { public static Gson gson = new Gson(); @LauncherAPI @@ -53,4 +56,32 @@ public int compare(HWID hwid) { public boolean isNull() { return getLevel() < 15; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + OshiHWID oshiHWID = (OshiHWID) o; + return totalMemory == oshiHWID.totalMemory && + Objects.equals(serialNumber, oshiHWID.serialNumber) && + Objects.equals(HWDiskSerial, oshiHWID.HWDiskSerial) && + Objects.equals(processorID, oshiHWID.processorID) && + Objects.equals(macAddr, oshiHWID.macAddr); + } + + @Override + public int hashCode() { + return Objects.hash(totalMemory, serialNumber, HWDiskSerial, processorID, macAddr); + } + + @Override + public String toString() { + return new StringJoiner(", ", OshiHWID.class.getSimpleName() + "[", "]") + .add("totalMemory=" + totalMemory) + .add("serialNumber='" + serialNumber + "'") + .add("HWDiskSerial='" + HWDiskSerial + "'") + .add("processorID='" + processorID + "'") + .add("macAddr='" + macAddr + "'") + .toString(); + } } diff --git a/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java b/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java index 8739cd42..0e2c5a0d 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java +++ b/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java @@ -76,6 +76,10 @@ public void registerCommand(String name, Command command) { VerifyHelper.putIfAbsent(commands, name.toLowerCase(), Objects.requireNonNull(command, "command"), String.format("Command has been already registered: '%s'", name.toLowerCase())); } + public void unregisterCommand(String name) + { + commands.remove(name); + } @Override public void run() { From 1ed588e1c0271e239ed120c8ca502178ab878e5f Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 28 Mar 2019 17:26:47 +0700 Subject: [PATCH 006/128] [FEATURE] CommandRemover --- .../components/CommandRemoverComponent.java | 39 +++++++++++++++++++ .../launchserver/components/Component.java | 1 + .../gravit/utils/command/CommandHandler.java | 4 +- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/components/CommandRemoverComponent.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/components/CommandRemoverComponent.java b/LaunchServer/src/main/java/ru/gravit/launchserver/components/CommandRemoverComponent.java new file mode 100644 index 00000000..a6078dbd --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/components/CommandRemoverComponent.java @@ -0,0 +1,39 @@ +package ru.gravit.launchserver.components; + +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.utils.command.Command; + +import java.util.HashMap; +import java.util.Map; + +public class CommandRemoverComponent extends Component implements AutoCloseable { + public String[] removeList = new String[]{}; + public transient Map commandsList = new HashMap<>(); + @Override + public void preInit(LaunchServer launchServer) { + + } + + @Override + public void init(LaunchServer launchServer) { + + } + + @Override + public void postInit(LaunchServer launchServer) { + for(String cmd : removeList) + { + Command removedCmd = launchServer.commandHandler.unregisterCommand(cmd); + if(removedCmd != null) + commandsList.put(cmd, removedCmd); + } + } + + @Override + public void close() throws Exception { + for(Map.Entry e : commandsList.entrySet()) + { + LaunchServer.server.commandHandler.registerCommand(e.getKey(), e.getValue()); + } + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java b/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java index 4cd718ac..b0ebcd57 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java @@ -31,6 +31,7 @@ public static String getComponentName(Class clazz) { public static void registerComponents() { if (!registredComp) { registerComponent("authLimiter", AuthLimiterComponent.class); + registerComponent("commandRemover", CommandRemoverComponent.class); registredComp = true; } } diff --git a/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java b/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java index 0e2c5a0d..8d2b2944 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java +++ b/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java @@ -76,9 +76,9 @@ public void registerCommand(String name, Command command) { VerifyHelper.putIfAbsent(commands, name.toLowerCase(), Objects.requireNonNull(command, "command"), String.format("Command has been already registered: '%s'", name.toLowerCase())); } - public void unregisterCommand(String name) + public Command unregisterCommand(String name) { - commands.remove(name); + return commands.remove(name); } @Override From 6a934ec2aece33ebdffbcd6ff4c25dd0e41f3408 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Fri, 29 Mar 2019 13:18:34 +0300 Subject: [PATCH 007/128] =?UTF-8?q?[FIX]=20=D0=9B=D0=B8=D1=88=D0=BD=D1=8F?= =?UTF-8?q?=D1=8F=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B2=20launcher-libraries.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Launcher/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/Launcher/build.gradle b/Launcher/build.gradle index d2a57901..0007a5fe 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -28,7 +28,6 @@ dependencies { pack project(':LauncherAPI') // Not error on obf. bundle 'com.github.oshi:oshi-core:3.13.0' - bundle 'commons-codec:commons-codec:1.11' } task genRuntimeJS(type: Zip) { From f1e6830a721420080c6ee49606a1d03144da9278 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Sat, 30 Mar 2019 12:35:32 +0300 Subject: [PATCH 008/128] =?UTF-8?q?[FEATURE]=20=D0=A1=D1=82=D1=80=D1=83?= =?UTF-8?q?=D1=82=D1=80=D1=83=D0=BA=D0=B0=20gradle=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LauncherTest/build.gradle | 6 ++++++ LauncherTest/src/main/java/Empty.java | 0 LauncherTest/src/test/java/Empty.java | 0 module.gradle | 3 ++- test_support.gradle | 11 +++++++++++ 5 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 LauncherTest/build.gradle create mode 100644 LauncherTest/src/main/java/Empty.java create mode 100644 LauncherTest/src/test/java/Empty.java create mode 100644 test_support.gradle diff --git a/LauncherTest/build.gradle b/LauncherTest/build.gradle new file mode 100644 index 00000000..28530075 --- /dev/null +++ b/LauncherTest/build.gradle @@ -0,0 +1,6 @@ +apply from: '../test_support.gradle' + +dependencies { + compile project(':LaunchServer') +} + diff --git a/LauncherTest/src/main/java/Empty.java b/LauncherTest/src/main/java/Empty.java new file mode 100644 index 00000000..e69de29b diff --git a/LauncherTest/src/test/java/Empty.java b/LauncherTest/src/test/java/Empty.java new file mode 100644 index 00000000..e69de29b diff --git a/module.gradle b/module.gradle index a5690396..95cf1915 100644 --- a/module.gradle +++ b/module.gradle @@ -1,7 +1,8 @@ dependencies { compileOnly project(':LaunchServer') } + jar { - from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } } + from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } } } diff --git a/test_support.gradle b/test_support.gradle new file mode 100644 index 00000000..5cfb0a46 --- /dev/null +++ b/test_support.gradle @@ -0,0 +1,11 @@ +dependencies { + testCompile 'org.junit.jupiter:junit-jupiter:5.4.1' +} + +test { + useJUnitPlatform() + testLogging { + events "passed", "skipped", "failed" + } +} + From 6751ffb4a41bf7ceef2bd06b3899dba73db9190f Mon Sep 17 00:00:00 2001 From: Andrei Gavrilov Date: Sun, 31 Mar 2019 03:08:02 +0300 Subject: [PATCH 009/128] Update get_it.sh --- get_it.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/get_it.sh b/get_it.sh index f37055af..7d6114d4 100755 --- a/get_it.sh +++ b/get_it.sh @@ -1,4 +1,5 @@ #!/bin/sh git clone https://github.com/GravitLauncher/Launcher.git +cd Launcher sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules git submodule update --init --recursive From d6ef1fd99d44e6888ab5f5d783549ee68d57f0e8 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 3 Apr 2019 15:46:18 +0700 Subject: [PATCH 010/128] [FEATURE] ServerWrapperSetup --- .../gravit/launcher/server/ServerWrapper.java | 46 ++++-- .../server/setup/ServerWrapperCommands.java | 36 +++++ .../server/setup/ServerWrapperSetup.java | 141 ++++++++++++++++++ 3 files changed, 211 insertions(+), 12 deletions(-) create mode 100644 ServerWrapper/src/main/java/ru/gravit/launcher/server/setup/ServerWrapperCommands.java create mode 100644 ServerWrapper/src/main/java/ru/gravit/launcher/server/setup/ServerWrapperSetup.java diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index 999b8593..c4c8b3a4 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -9,6 +9,7 @@ import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.request.auth.AuthServerRequest; import ru.gravit.launcher.request.update.ProfilesRequest; +import ru.gravit.launcher.server.setup.ServerWrapperSetup; import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; @@ -33,12 +34,14 @@ public class ServerWrapper { public static PublicURLClassLoader ucp; public static ClassLoader loader; public static ClientPermissions permissions; + public static ServerWrapper wrapper; private static Gson gson; private static GsonBuilder gsonBuiler; public static Path modulesDir = Paths.get(System.getProperty("serverwrapper.modulesDir", "modules")); public static Path configFile = Paths.get(System.getProperty("serverwrapper.configFile", "ServerWrapperConfig.json")); public static Path publicKeyFile = Paths.get(System.getProperty("serverwrapper.publicKeyFile", "public.key")); + public static boolean disableSetup = Boolean.valueOf(System.getProperty("serverwrapper.disableSetup", "false")); public static boolean auth(ServerWrapper wrapper) { try { @@ -93,18 +96,29 @@ public static void initGson() { } public static void main(String... args) throws Throwable { - ServerWrapper wrapper = new ServerWrapper(); LogHelper.printVersion("ServerWrapper"); LogHelper.printLicense("ServerWrapper"); + wrapper = new ServerWrapper(); + gsonBuiler = new GsonBuilder(); + gsonBuiler.setPrettyPrinting(); + gson = gsonBuiler.create(); + initGson(); + if(args.length > 0 && args[0].equals("setup")) + { + generateConfigIfNotExists(); + LogHelper.debug("Read ServerWrapperConfig.json"); + try (Reader reader = IOHelper.newReader(configFile)) { + config = gson.fromJson(reader, Config.class); + } + ServerWrapperSetup setup = new ServerWrapperSetup(); + setup.run(); + System.exit(0); + } modulesManager = new ModulesManager(wrapper); modulesManager.autoload(modulesDir); Launcher.modulesManager = modulesManager; modulesManager.preInitModules(); LogHelper.debug("Read ServerWrapperConfig.json"); - gsonBuiler = new GsonBuilder(); - gsonBuiler.setPrettyPrinting(); - gson = gsonBuiler.create(); - initGson(); generateConfigIfNotExists(); try (Reader reader = IOHelper.newReader(configFile)) { config = gson.fromJson(reader, Config.class); @@ -160,11 +174,15 @@ public static void main(String... args) throws Throwable { LogHelper.debug("Invoke main method %s", mainClass.getName()); if(config.args == null) { - String[] real_args = new String[args.length - 1]; - System.arraycopy(args, 1, real_args, 0, args.length - 1); + String[] real_args; + if(args.length > 0) + { + real_args = new String[args.length - 1]; + System.arraycopy(args, 1, real_args, 0, args.length - 1); + } else real_args = args; + mainMethod.invoke(real_args); } - else { mainMethod.invoke(config.args); @@ -194,10 +212,7 @@ private static void generateConfigIfNotExists() throws IOException { LogHelper.warning("Title is not set. Please show ServerWrapper.cfg"); // Write LaunchServer config - LogHelper.info("Writing ServerWrapper config file"); - try (Writer writer = IOHelper.newWriter(configFile)) { - gson.toJson(newConfig, writer); - } + newConfig.save(); } public static final class Config { @@ -220,6 +235,13 @@ public static final class Config { public String password; public String auth_id = ""; public LauncherConfig.LauncherEnvironment env; + public void save() throws IOException + { + LogHelper.info("Writing ServerWrapper config file"); + try (Writer writer = IOHelper.newWriter(configFile)) { + gson.toJson(this, writer); + } + } } public ClientProfile profile; diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/setup/ServerWrapperCommands.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/setup/ServerWrapperCommands.java new file mode 100644 index 00000000..7ab8e07d --- /dev/null +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/setup/ServerWrapperCommands.java @@ -0,0 +1,36 @@ +package ru.gravit.launcher.server.setup; + +import ru.gravit.utils.command.CommandHandler; +import ru.gravit.utils.command.JLineCommandHandler; +import ru.gravit.utils.command.StdCommandHandler; +import ru.gravit.utils.helper.LogHelper; + +import java.io.IOException; + +public class ServerWrapperCommands { + public final CommandHandler commandHandler; + public void registerCommands() + { + //FUTURE + } + + public ServerWrapperCommands(CommandHandler commandHandler) { + this.commandHandler = commandHandler; + } + + public ServerWrapperCommands() throws IOException { + // Set command handler + CommandHandler localCommandHandler; + try { + Class.forName("jline.Terminal"); + + // JLine2 available + localCommandHandler = new JLineCommandHandler(); + LogHelper.info("JLine2 terminal enabled"); + } catch (ClassNotFoundException ignored) { + localCommandHandler = new StdCommandHandler(true); + LogHelper.warning("JLine2 isn't in classpath, using std"); + } + commandHandler = localCommandHandler; + } +} diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/setup/ServerWrapperSetup.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/setup/ServerWrapperSetup.java new file mode 100644 index 00000000..95af4fc6 --- /dev/null +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/setup/ServerWrapperSetup.java @@ -0,0 +1,141 @@ +package ru.gravit.launcher.server.setup; + +import ru.gravit.launcher.Launcher; +import ru.gravit.launcher.LauncherConfig; +import ru.gravit.launcher.server.ServerWrapper; +import ru.gravit.utils.PublicURLClassLoader; +import ru.gravit.utils.helper.IOHelper; +import ru.gravit.utils.helper.JVMHelper; +import ru.gravit.utils.helper.LogHelper; +import ru.gravit.utils.helper.SecurityHelper; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.Writer; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.spec.InvalidKeySpecException; +import java.util.HashMap; +import java.util.jar.JarFile; + +public class ServerWrapperSetup { + public ServerWrapperCommands commands; + public PublicURLClassLoader urlClassLoader; + public void run() throws IOException + { + System.out.println("Print jar filename:"); + String jarName = commands.commandHandler.readLine(); + Path jarPath = Paths.get(jarName); + JarFile file = new JarFile(jarPath.toFile()); + URL jarURL = jarPath.toUri().toURL(); + urlClassLoader = new PublicURLClassLoader(new URL[]{jarURL}); + LogHelper.info("Check jar MainClass"); + String mainClassName = file.getManifest().getMainAttributes().getValue("Main-Class"); + if(mainClassName == null) + { + LogHelper.error("Main-Class not found in MANIFEST"); + return; + } + try { + Class mainClass = Class.forName(mainClassName, false, urlClassLoader); + } catch (ClassNotFoundException e) + { + LogHelper.error(e); + return; + } + LogHelper.info("Found MainClass %s", mainClassName); + System.out.println("Print launchserver host:"); + String address = commands.commandHandler.readLine(); + System.out.println("Print launchserver port:"); + int port = Integer.valueOf(commands.commandHandler.readLine()); + ServerWrapper.config.mainclass = mainClassName; + ServerWrapper.config.address = address; + ServerWrapper.config.port = port; + if(!Files.exists(ServerWrapper.publicKeyFile)) + { + LogHelper.error("public.key not found"); + for(int i=0;i<10;++i) + { + System.out.println("Print F to continue:"); + String printF = commands.commandHandler.readLine(); + if(printF.equals("stop")) return; + if(Files.exists(ServerWrapper.publicKeyFile)) break; + else LogHelper.error("public.key not found"); + } + } + boolean stopOnError = ServerWrapper.config.stopOnError; + for(int i=0;i<10;++i) + { + System.out.println("Print server account login:"); + String login = commands.commandHandler.readLine(); + System.out.println("Print server account password:"); + String password = commands.commandHandler.readLine(); + System.out.println("Print profile title:"); + String title = commands.commandHandler.readLine(); + ServerWrapper.config.login = login; + ServerWrapper.config.password = password; + ServerWrapper.config.title = title; + ServerWrapper.config.stopOnError = false; + LauncherConfig cfg = null; + try { + cfg = new LauncherConfig(ServerWrapper.config.address, ServerWrapper.config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(ServerWrapper.publicKeyFile)), new HashMap<>(), ServerWrapper.config.projectname); + } catch (InvalidKeySpecException e) { + LogHelper.error(e); + } + Launcher.setConfig(cfg); + if(ServerWrapper.auth(ServerWrapper.wrapper)) + { + break; + } + else + { + LogHelper.error("Auth error. Recheck account params"); + } + } + ServerWrapper.config.stopOnError = stopOnError; + ServerWrapper.config.save(); + LogHelper.info("Generate start script"); + Path startScript; + if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) startScript = Paths.get("start.bat"); + else startScript = Paths.get("start.sh"); + if(Files.exists(startScript)) + { + LogHelper.warning("start script found. Move to start.bak"); + Path startScriptBak = Paths.get("start.bak"); + IOHelper.move(startScript, startScriptBak); + } + try(Writer writer = IOHelper.newWriter(startScript)) + { + if(JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) + { + writer.append("#!/bin/sh\n\n"); + } + writer.append("java "); + if(mainClassName.contains("bungee")) + { + LogHelper.info("Found BungeeCord mainclass. Modules dir change to modules_srv"); + writer.append(JVMHelper.jvmProperty("serverwrapper.modulesDir", "modules_srv")); + writer.append(" "); + } + //More args + writer.append("-cp "); + String pathServerWrapper = IOHelper.getCodeSource(ServerWrapper.class).getFileName().toString(); + writer.append(pathServerWrapper); + if(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) + { + writer.append(";"); + } else writer.append(":"); + writer.append(jarName); + writer.append(" "); + writer.append(ServerWrapper.class.getName()); + writer.append("\n"); + } + + } + + public ServerWrapperSetup() throws IOException { + commands = new ServerWrapperCommands(); + } +} From 5c88b8eb148cb9e28b59c9f366d2e41b6ff56a51 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 3 Apr 2019 15:51:41 +0700 Subject: [PATCH 011/128] =?UTF-8?q?[FEATURE]=20ClientPermissions=20=D1=81?= =?UTF-8?q?=D0=B5=D1=80=D0=B8=D0=B0=D0=BB=D0=B8=D0=B7=D1=83=D0=B5=D1=82?= =?UTF-8?q?=D1=81=D1=8F=20=D0=B2=20Long?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launcher/server/ServerWrapper.java | 2 +- .../ru/gravit/launcher/ClientPermissions.java | 26 ++++++------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index c4c8b3a4..3dd22fcd 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -103,7 +103,7 @@ public static void main(String... args) throws Throwable { gsonBuiler.setPrettyPrinting(); gson = gsonBuiler.create(); initGson(); - if(args.length > 0 && args[0].equals("setup")) + if(args.length > 0 && args[0].equals("setup") && !disableSetup) { generateConfigIfNotExists(); LogHelper.debug("Read ServerWrapperConfig.json"); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java b/libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java index c13828a6..75957772 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java @@ -8,25 +8,20 @@ public class ClientPermissions { public static final ClientPermissions DEFAULT = new ClientPermissions(); @LauncherAPI - public boolean canAdmin = false; + public boolean canAdmin; @LauncherAPI - public boolean canServer = false; + public boolean canServer; @LauncherAPI - public boolean canUSR1 = false; + public boolean canUSR1; @LauncherAPI - public boolean canUSR2 = false; + public boolean canUSR2; @LauncherAPI - public boolean canUSR3 = false; + public boolean canUSR3; @LauncherAPI - public boolean canBot = false; + public boolean canBot; public ClientPermissions(HInput input) throws IOException { - canAdmin = input.readBoolean(); - canServer = input.readBoolean(); - canUSR1 = input.readBoolean(); - canUSR2 = input.readBoolean(); - canUSR3 = input.readBoolean(); - canBot = input.readBoolean(); + this(input.readLong()); } public ClientPermissions() { @@ -67,11 +62,6 @@ public static ClientPermissions getSuperuserAccount() { } public void write(HOutput output) throws IOException { - output.writeBoolean(canAdmin); - output.writeBoolean(canServer); - output.writeBoolean(canUSR1); - output.writeBoolean(canUSR2); - output.writeBoolean(canUSR3); - output.writeBoolean(canBot); + output.writeLong(toLong()); } } From e9f36fa44fdfbe49a5caa2aa2c330412fae19811 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 3 Apr 2019 16:21:53 +0700 Subject: [PATCH 012/128] [FEATURE] GetPermissions/GivePermissions command --- .../permissions/ConfigPermissionsHandler.java | 5 ++ .../DefaultPermissionsHandler.java | 5 ++ .../JsonFilePermissionsHandler.java | 5 ++ .../JsonLongFilePermissionsHandler.java | 5 ++ .../auth/permissions/PermissionsHandler.java | 2 + .../command/handler/CommandHandler.java | 2 + .../service/GetPermissionsCommand.java | 30 ++++++++++ .../service/GivePermissionsCommand.java | 56 +++++++++++++++++++ .../ru/gravit/launcher/ClientPermissions.java | 13 +++++ 9 files changed, 123 insertions(+) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetPermissionsCommand.java create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GivePermissionsCommand.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java index 44f12eff..0ce83335 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/ConfigPermissionsHandler.java @@ -19,6 +19,11 @@ public ClientPermissions getPermissions(String username) { return permissions; } + @Override + public void setPermissions(String username, ClientPermissions permissions) { + //Unsupported + } + @Override public void close() { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java index 4b14873b..b9689b38 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/DefaultPermissionsHandler.java @@ -13,6 +13,11 @@ public ClientPermissions getPermissions(String username) { return ClientPermissions.DEFAULT; } + @Override + public void setPermissions(String username, ClientPermissions permissions) { + //Unsupported + } + @Override public void close() throws Exception { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java index bd3903f2..43778464 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonFilePermissionsHandler.java @@ -68,6 +68,11 @@ public ClientPermissions getPermissions(String username) { return map.getOrDefault(username, ClientPermissions.DEFAULT); } + @Override + public void setPermissions(String username, ClientPermissions permissions) { + map.put(username, permissions); + } + public JsonFilePermissionsHandler() { } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java index ada99916..3cfb3262 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/JsonLongFilePermissionsHandler.java @@ -69,6 +69,11 @@ public ClientPermissions getPermissions(String username) { return new ClientPermissions(map.getOrDefault(username, defaultPerms)); } + @Override + public void setPermissions(String username, ClientPermissions permissions) { + map.put(username, permissions.toLong()); + } + public JsonLongFilePermissionsHandler() { } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java index d3898138..cf8dad23 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/permissions/PermissionsHandler.java @@ -41,4 +41,6 @@ public static void registerHandlers() { public abstract void init(); public abstract ClientPermissions getPermissions(String username); + + public abstract void setPermissions(String username, ClientPermissions permissions); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java index fe387086..7b307ea1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java @@ -66,5 +66,7 @@ public static void registerCommands(ru.gravit.utils.command.CommandHandler handl handler.registerCommand("multi", new MultiCommand(server)); handler.registerCommand("getModulus", new GetModulusCommand(server)); handler.registerCommand("component", new ComponentCommand(server)); + handler.registerCommand("givePermission", new GivePermissionsCommand(server)); + handler.registerCommand("getPermissions", new GetPermissionsCommand(server)); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetPermissionsCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetPermissionsCommand.java new file mode 100644 index 00000000..f0bb6ebf --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetPermissionsCommand.java @@ -0,0 +1,30 @@ +package ru.gravit.launchserver.command.service; + +import ru.gravit.launcher.ClientPermissions; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; +import ru.gravit.utils.helper.LogHelper; + +public class GetPermissionsCommand extends Command { + public GetPermissionsCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[username]"; + } + + @Override + public String getUsageDescription() { + return "print username permissions"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args,1); + String username = args[0]; + ClientPermissions permissions = server.config.permissionsHandler.getPermissions(username); + LogHelper.info("Permissions %s: %s (long: %d)", username, permissions.toString(), permissions.toLong()); + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GivePermissionsCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GivePermissionsCommand.java new file mode 100644 index 00000000..cc0b1083 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GivePermissionsCommand.java @@ -0,0 +1,56 @@ +package ru.gravit.launchserver.command.service; + +import ru.gravit.launcher.ClientPermissions; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; +import ru.gravit.utils.helper.LogHelper; + +public class GivePermissionsCommand extends Command { + public GivePermissionsCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[username] [permission] [true/false]"; + } + + @Override + public String getUsageDescription() { + return "give permissions"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 3); + String username = args[0]; + ClientPermissions permissions = server.config.permissionsHandler.getPermissions(username); + String permission = args[1]; + boolean isEnabled = Boolean.valueOf(args[2]); + switch (permission) + { + case "admin": + { + permissions.canAdmin = isEnabled; + break; + } + case "server": + { + permissions.canServer = isEnabled; + break; + } + case "bot": + { + permissions.canBot = isEnabled; + break; + } + default: + { + LogHelper.error("Unknown permission: %s", permission); + return; + } + } + LogHelper.info("Write new permissions for %s", username); + server.config.permissionsHandler.setPermissions(username, permissions); + } +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java b/libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java index 75957772..81ee4ae1 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/ClientPermissions.java @@ -4,6 +4,7 @@ import ru.gravit.launcher.serialize.HOutput; import java.io.IOException; +import java.util.StringJoiner; public class ClientPermissions { public static final ClientPermissions DEFAULT = new ClientPermissions(); @@ -64,4 +65,16 @@ public static ClientPermissions getSuperuserAccount() { public void write(HOutput output) throws IOException { output.writeLong(toLong()); } + + @Override + public String toString() { + return new StringJoiner(", ", ClientPermissions.class.getSimpleName() + "[", "]") + .add("canAdmin=" + canAdmin) + .add("canServer=" + canServer) + .add("canUSR1=" + canUSR1) + .add("canUSR2=" + canUSR2) + .add("canUSR3=" + canUSR3) + .add("canBot=" + canBot) + .toString(); + } } From a636fbe336f191f3f41e6a65616c956e3277934b Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 3 Apr 2019 17:09:53 +0700 Subject: [PATCH 013/128] [FEATURE] ConfigManager --- .../ru/gravit/launchserver/LaunchServer.java | 55 ++++++++++-------- .../{ => adapter}/AuthHandlerAdapter.java | 2 +- .../{ => adapter}/AuthProviderAdapter.java | 2 +- .../{ => adapter}/ComponentAdapter.java | 2 +- .../{ => adapter}/HWIDHandlerAdapter.java | 2 +- .../PermissionsHandlerAdapter.java | 2 +- .../{ => adapter}/ProtectHandlerAdapter.java | 2 +- .../{ => adapter}/TextureProviderAdapter.java | 2 +- .../launcher/managers/ConfigManager.java | 55 ++++++++++++++++++ .../gravit/utils/config/JsonConfigurable.java | 58 +++++++++++++++++++ 10 files changed, 152 insertions(+), 30 deletions(-) rename LaunchServer/src/main/java/ru/gravit/launchserver/config/{ => adapter}/AuthHandlerAdapter.java (96%) rename LaunchServer/src/main/java/ru/gravit/launchserver/config/{ => adapter}/AuthProviderAdapter.java (96%) rename LaunchServer/src/main/java/ru/gravit/launchserver/config/{ => adapter}/ComponentAdapter.java (96%) rename LaunchServer/src/main/java/ru/gravit/launchserver/config/{ => adapter}/HWIDHandlerAdapter.java (96%) rename LaunchServer/src/main/java/ru/gravit/launchserver/config/{ => adapter}/PermissionsHandlerAdapter.java (96%) rename LaunchServer/src/main/java/ru/gravit/launchserver/config/{ => adapter}/ProtectHandlerAdapter.java (96%) rename LaunchServer/src/main/java/ru/gravit/launchserver/config/{ => adapter}/TextureProviderAdapter.java (96%) create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/managers/ConfigManager.java create mode 100644 libLauncher/src/main/java/ru/gravit/utils/config/JsonConfigurable.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index f3299a08..66646a1e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -4,7 +4,9 @@ import com.google.gson.GsonBuilder; import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherConfig; +import ru.gravit.launcher.NeedGarbageCollection; import ru.gravit.launcher.hasher.HashedDir; +import ru.gravit.launcher.managers.ConfigManager; import ru.gravit.launcher.managers.GarbageManager; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; @@ -22,10 +24,11 @@ import ru.gravit.launchserver.auth.provider.RejectAuthProvider; import ru.gravit.launchserver.binary.*; import ru.gravit.launchserver.components.Component; +import ru.gravit.utils.config.JsonConfigurable; +import ru.gravit.launchserver.config.adapter.*; import ru.gravit.utils.command.CommandHandler; import ru.gravit.utils.command.JLineCommandHandler; import ru.gravit.utils.command.StdCommandHandler; -import ru.gravit.launchserver.config.*; import ru.gravit.launchserver.manangers.*; import ru.gravit.launchserver.manangers.hook.AuthHookManager; import ru.gravit.launchserver.manangers.hook.BuildHookManager; @@ -360,6 +363,8 @@ public static void main(String... args) throws Throwable { public final ReconfigurableManager reconfigurableManager; + public final ConfigManager configManager; + public final BuildHookManager buildHookManager; @@ -487,32 +492,15 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE reconfigurableManager = new ReconfigurableManager(); socketHookManager = new SocketHookManager(); authHookManager = new AuthHookManager(); + configManager = new ConfigManager(); GarbageManager.registerNeedGC(sessionManager); reloadManager.registerReloadable("launchServer", this); - if (config.permissionsHandler instanceof Reloadable) - reloadManager.registerReloadable("permissionsHandler", (Reloadable) config.permissionsHandler); + registerObject("permissionsHandler", config.permissionsHandler); for (int i = 0; i < config.auth.length; ++i) { AuthProviderPair pair = config.auth[i]; - if (pair.provider instanceof Reloadable) - reloadManager.registerReloadable("auth.".concat(pair.name).concat(".provider"), (Reloadable) pair.provider); - if (pair.handler instanceof Reloadable) - reloadManager.registerReloadable("auth.".concat(pair.name).concat(".handler"), (Reloadable) pair.handler); - if (pair.textureProvider instanceof Reloadable) - reloadManager.registerReloadable("auth.".concat(pair.name).concat(".texture"), (Reloadable) pair.textureProvider); - } - - Arrays.stream(config.mirrors).forEach(mirrorManager::addMirror); - - if (config.permissionsHandler instanceof Reconfigurable) - reconfigurableManager.registerReconfigurable("permissionsHandler", (Reconfigurable) config.permissionsHandler); - for (int i = 0; i < config.auth.length; ++i) { - AuthProviderPair pair = config.auth[i]; - if (pair.provider instanceof Reconfigurable) - reconfigurableManager.registerReconfigurable("auth.".concat(pair.name).concat(".provider"), (Reconfigurable) pair.provider); - if (pair.handler instanceof Reconfigurable) - reconfigurableManager.registerReconfigurable("auth.".concat(pair.name).concat(".handler"), (Reconfigurable) pair.handler); - if (pair.textureProvider instanceof Reconfigurable) - reconfigurableManager.registerReconfigurable("auth.".concat(pair.name).concat(".texture"), (Reconfigurable) pair.textureProvider); + registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider); + registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler); + registerObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider); } Arrays.stream(config.mirrors).forEach(mirrorManager::addMirror); @@ -524,6 +512,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE LogHelper.debug("Init components"); config.components.forEach((k,v) -> { LogHelper.subDebug("Init component %s", k); + registerObject("component.".concat(k),v); v.init(this); }); LogHelper.debug("Init components successful"); @@ -800,6 +789,26 @@ public void restart() { } } + public void registerObject(String name, Object object) + { + if(object instanceof Reloadable) + { + reloadManager.registerReloadable(name, (Reloadable) object); + } + if(object instanceof Reconfigurable) + { + reconfigurableManager.registerReconfigurable(name, (Reconfigurable) object); + } + if(object instanceof NeedGarbageCollection) + { + GarbageManager.registerNeedGC((NeedGarbageCollection) object); + } + if(object instanceof JsonConfigurable) + { + + } + } + public void fullyRestart() { restart(); JVMHelper.RUNTIME.exit(0); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/AuthHandlerAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthHandlerAdapter.java similarity index 96% rename from LaunchServer/src/main/java/ru/gravit/launchserver/config/AuthHandlerAdapter.java rename to LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthHandlerAdapter.java index f796e921..d636f196 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/AuthHandlerAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthHandlerAdapter.java @@ -1,4 +1,4 @@ -package ru.gravit.launchserver.config; +package ru.gravit.launchserver.config.adapter; import com.google.gson.*; import ru.gravit.launchserver.auth.handler.AuthHandler; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/AuthProviderAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthProviderAdapter.java similarity index 96% rename from LaunchServer/src/main/java/ru/gravit/launchserver/config/AuthProviderAdapter.java rename to LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthProviderAdapter.java index f4e74c95..017208c9 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/AuthProviderAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthProviderAdapter.java @@ -1,4 +1,4 @@ -package ru.gravit.launchserver.config; +package ru.gravit.launchserver.config.adapter; import com.google.gson.*; import ru.gravit.launchserver.auth.provider.AuthProvider; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/ComponentAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/ComponentAdapter.java similarity index 96% rename from LaunchServer/src/main/java/ru/gravit/launchserver/config/ComponentAdapter.java rename to LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/ComponentAdapter.java index 65c8f7da..1342a1d5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/ComponentAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/ComponentAdapter.java @@ -1,4 +1,4 @@ -package ru.gravit.launchserver.config; +package ru.gravit.launchserver.config.adapter; import com.google.gson.*; import ru.gravit.launchserver.components.Component; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/HWIDHandlerAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/HWIDHandlerAdapter.java similarity index 96% rename from LaunchServer/src/main/java/ru/gravit/launchserver/config/HWIDHandlerAdapter.java rename to LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/HWIDHandlerAdapter.java index 3a2d994c..0c97d3dc 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/HWIDHandlerAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/HWIDHandlerAdapter.java @@ -1,4 +1,4 @@ -package ru.gravit.launchserver.config; +package ru.gravit.launchserver.config.adapter; import com.google.gson.*; import ru.gravit.launchserver.auth.hwid.HWIDHandler; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/PermissionsHandlerAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/PermissionsHandlerAdapter.java similarity index 96% rename from LaunchServer/src/main/java/ru/gravit/launchserver/config/PermissionsHandlerAdapter.java rename to LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/PermissionsHandlerAdapter.java index bc2e21ae..aef7f2fc 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/PermissionsHandlerAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/PermissionsHandlerAdapter.java @@ -1,4 +1,4 @@ -package ru.gravit.launchserver.config; +package ru.gravit.launchserver.config.adapter; import com.google.gson.*; import ru.gravit.launchserver.auth.permissions.PermissionsHandler; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/ProtectHandlerAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/ProtectHandlerAdapter.java similarity index 96% rename from LaunchServer/src/main/java/ru/gravit/launchserver/config/ProtectHandlerAdapter.java rename to LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/ProtectHandlerAdapter.java index b342a14f..a1120de5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/ProtectHandlerAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/ProtectHandlerAdapter.java @@ -1,4 +1,4 @@ -package ru.gravit.launchserver.config; +package ru.gravit.launchserver.config.adapter; import com.google.gson.*; import ru.gravit.launchserver.auth.protect.ProtectHandler; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/TextureProviderAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/TextureProviderAdapter.java similarity index 96% rename from LaunchServer/src/main/java/ru/gravit/launchserver/config/TextureProviderAdapter.java rename to LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/TextureProviderAdapter.java index 75aba651..908099a9 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/TextureProviderAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/TextureProviderAdapter.java @@ -1,4 +1,4 @@ -package ru.gravit.launchserver.config; +package ru.gravit.launchserver.config.adapter; import com.google.gson.*; import ru.gravit.launchserver.texture.TextureProvider; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/managers/ConfigManager.java b/libLauncher/src/main/java/ru/gravit/launcher/managers/ConfigManager.java new file mode 100644 index 00000000..465790c5 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/managers/ConfigManager.java @@ -0,0 +1,55 @@ +package ru.gravit.launcher.managers; + +import ru.gravit.utils.config.JsonConfigurable; +import ru.gravit.utils.helper.LogHelper; +import ru.gravit.utils.helper.VerifyHelper; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Objects; + +public class ConfigManager { + private final HashMap CONFIGURABLE = new HashMap<>(); + + public void registerConfigurable(String name, JsonConfigurable reconfigurable) { + VerifyHelper.putIfAbsent(CONFIGURABLE, name.toLowerCase(), Objects.requireNonNull(reconfigurable, "adapter"), + String.format("Reloadable has been already registered: '%s'", name)); + } + + public void printConfigurables() { + LogHelper.info("Print configurables"); + CONFIGURABLE.forEach((k, v) -> LogHelper.subInfo(k)); + LogHelper.info("Found %d configurables", CONFIGURABLE.size()); + } + + public void save(String name) throws IOException + { + CONFIGURABLE.get(name).saveConfig(); + } + + public void load(String name) throws IOException + { + CONFIGURABLE.get(name).loadConfig(); + } + + public void save(String name, Path path) throws IOException + { + CONFIGURABLE.get(name).saveConfig(path); + } + + public void reset(String name) throws IOException + { + CONFIGURABLE.get(name).resetConfig(); + } + + public void load(String name, Path path) throws IOException + { + CONFIGURABLE.get(name).loadConfig(path); + } + + public void reset(String name, Path path) throws IOException + { + CONFIGURABLE.get(name).resetConfig(path); + } +} diff --git a/libLauncher/src/main/java/ru/gravit/utils/config/JsonConfigurable.java b/libLauncher/src/main/java/ru/gravit/utils/config/JsonConfigurable.java new file mode 100644 index 00000000..ca8cb6b2 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/utils/config/JsonConfigurable.java @@ -0,0 +1,58 @@ +package ru.gravit.utils.config; + +import ru.gravit.launcher.Launcher; +import ru.gravit.utils.helper.IOHelper; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.file.Path; + +public abstract class JsonConfigurable { + private Type type; + protected Path configPath; + public void saveConfig() throws IOException + { + saveConfig(configPath); + } + public void loadConfig() throws IOException + { + loadConfig(configPath); + } + + public JsonConfigurable(Type type, Path configPath) { + this.type = type; + this.configPath = configPath; + } + + public void saveConfig(Path configPath) throws IOException + { + try(BufferedWriter writer = IOHelper.newWriter(configPath)) + { + Launcher.gson.toJson(getConfig(), type, writer); + } + } + public void loadConfig(Path configPath) throws IOException + { + try (BufferedReader reader = IOHelper.newReader(configPath)) { + setConfig(Launcher.gson.fromJson(reader, type)); + } + } + + public void resetConfig() throws IOException + { + setConfig(getDefaultConfig()); + saveConfig(); + } + + public void resetConfig(Path newPath) throws IOException + { + setConfig(getDefaultConfig()); + saveConfig(newPath); + } + + public abstract T getConfig(); + public abstract T getDefaultConfig(); + public abstract void setConfig(T config); +} From f1ccfbf58e0cf32af00981a7b3b0c7421b740039 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 3 Apr 2019 17:30:58 +0700 Subject: [PATCH 014/128] =?UTF-8?q?[FEATURE]=20ServerWrapper=20=D1=80?= =?UTF-8?q?=D0=B0=D1=81=D1=88=D0=B8=D1=80=D1=8F=D0=B5=D1=82=20JsonConfigur?= =?UTF-8?q?able?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gravit/launcher/server/ServerWrapper.java | 105 ++++++++++-------- .../server/setup/ServerWrapperSetup.java | 32 +++--- .../gravit/utils/config/JsonConfigurable.java | 17 +++ 3 files changed, 88 insertions(+), 66 deletions(-) diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index 3dd22fcd..e12f726d 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -11,6 +11,7 @@ import ru.gravit.launcher.request.update.ProfilesRequest; import ru.gravit.launcher.server.setup.ServerWrapperSetup; import ru.gravit.utils.PublicURLClassLoader; +import ru.gravit.utils.config.JsonConfigurable; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; @@ -22,18 +23,20 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; +import java.lang.reflect.Type; import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; +import java.security.spec.InvalidKeySpecException; import java.util.Arrays; import java.util.HashMap; -public class ServerWrapper { - public static ModulesManager modulesManager; - public static Config config; - public static PublicURLClassLoader ucp; - public static ClassLoader loader; - public static ClientPermissions permissions; +public class ServerWrapper extends JsonConfigurable { + public ModulesManager modulesManager; + public Config config; + public PublicURLClassLoader ucp; + public ClassLoader loader; + public ClientPermissions permissions; public static ServerWrapper wrapper; private static Gson gson; private static GsonBuilder gsonBuiler; @@ -43,41 +46,45 @@ public class ServerWrapper { public static Path publicKeyFile = Paths.get(System.getProperty("serverwrapper.publicKeyFile", "public.key")); public static boolean disableSetup = Boolean.valueOf(System.getProperty("serverwrapper.disableSetup", "false")); - public static boolean auth(ServerWrapper wrapper) { + public ServerWrapper(Type type, Path configPath) { + super(type, configPath); + } + + public boolean auth() { try { LauncherConfig cfg = Launcher.getConfig(); - ServerWrapper.permissions = new AuthServerRequest(cfg, config.login, SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), config.auth_id, config.title).request(); + permissions = new AuthServerRequest(cfg, config.login, SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), config.auth_id, config.title).request(); ProfilesRequestEvent result = new ProfilesRequest(cfg).request(); for (ClientProfile p : result.profiles) { LogHelper.debug("Get profile: %s", p.getTitle()); if (p.getTitle().equals(config.title)) { - wrapper.profile = p; + profile = p; Launcher.profile = p; LogHelper.debug("Found profile: %s", Launcher.profile.getTitle()); break; } } - if (wrapper.profile == null) { + if (profile == null) { LogHelper.error("Your profile not found"); - if (ServerWrapper.config.stopOnError) System.exit(-1); + if (config.stopOnError) System.exit(-1); } return true; } catch (Throwable e) { LogHelper.error(e); - if (ServerWrapper.config.stopOnError) System.exit(-1); + if (config.stopOnError) System.exit(-1); return false; } } - public static boolean loopAuth(ServerWrapper wrapper, int count, int sleeptime) { + public boolean loopAuth(int count, int sleeptime) { if (count == 0) { while (true) { - if (auth(wrapper)) return true; + if (auth()) return true; } } for (int i = 0; i < count; ++i) { - if (auth(wrapper)) return true; + if (auth()) return true; try { Thread.sleep(sleeptime); } catch (InterruptedException e) { @@ -95,21 +102,16 @@ public static void initGson() { Launcher.gson = Launcher.gsonBuilder.create(); } - public static void main(String... args) throws Throwable { - LogHelper.printVersion("ServerWrapper"); - LogHelper.printLicense("ServerWrapper"); - wrapper = new ServerWrapper(); + public void run(String... args) throws Throwable + { gsonBuiler = new GsonBuilder(); gsonBuiler.setPrettyPrinting(); gson = gsonBuiler.create(); initGson(); if(args.length > 0 && args[0].equals("setup") && !disableSetup) { - generateConfigIfNotExists(); LogHelper.debug("Read ServerWrapperConfig.json"); - try (Reader reader = IOHelper.newReader(configFile)) { - config = gson.fromJson(reader, Config.class); - } + loadConfig(); ServerWrapperSetup setup = new ServerWrapperSetup(); setup.run(); System.exit(0); @@ -119,18 +121,14 @@ public static void main(String... args) throws Throwable { Launcher.modulesManager = modulesManager; modulesManager.preInitModules(); LogHelper.debug("Read ServerWrapperConfig.json"); - generateConfigIfNotExists(); - try (Reader reader = IOHelper.newReader(configFile)) { - config = gson.fromJson(reader, Config.class); - } - LauncherConfig cfg = new LauncherConfig(config.address, config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(publicKeyFile)), new HashMap<>(), config.projectname); - Launcher.setConfig(cfg); + loadConfig(); + updateLauncherConfig(); if(config.env != null) Launcher.applyLauncherEnv(config.env); else Launcher.applyLauncherEnv(LauncherConfig.LauncherEnvironment.STD); if (config.logFile != null) LogHelper.addOutput(IOHelper.newWriter(Paths.get(config.logFile), true)); - if (config.syncAuth) auth(wrapper); + if (config.syncAuth) auth(); else - CommonHelper.newThread("Server Auth Thread", true, () -> ServerWrapper.loopAuth(wrapper, config.reconnectCount, config.reconnectSleep)); + CommonHelper.newThread("Server Auth Thread", true, () -> loopAuth(config.reconnectCount, config.reconnectSleep)); modulesManager.initModules(); String classname = (config.mainclass == null || config.mainclass.isEmpty()) ? args[0] : config.mainclass; if (classname.length() == 0) { @@ -188,13 +186,32 @@ public static void main(String... args) throws Throwable { mainMethod.invoke(config.args); } } + public void updateLauncherConfig() + { - private static void generateConfigIfNotExists() throws IOException { - if (IOHelper.isFile(configFile)) - return; + LauncherConfig cfg = null; + try { + cfg = new LauncherConfig(config.address, config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(publicKeyFile)), new HashMap<>(), config.projectname); + } catch (InvalidKeySpecException | IOException e) { + LogHelper.error(e); + } + Launcher.setConfig(cfg); + } - // Create new config - LogHelper.info("Creating ServerWrapper config"); + public static void main(String... args) throws Throwable { + LogHelper.printVersion("ServerWrapper"); + LogHelper.printLicense("ServerWrapper"); + ServerWrapper.wrapper = new ServerWrapper(ServerWrapper.Config.class, configFile); + ServerWrapper.wrapper.run(args); + } + + @Override + public Config getConfig() { + return config; + } + + @Override + public Config getDefaultConfig() { Config newConfig = new Config(); newConfig.title = "Your profile title"; newConfig.projectname = "MineCraft"; @@ -208,11 +225,12 @@ private static void generateConfigIfNotExists() throws IOException { newConfig.reconnectCount = 10; newConfig.reconnectSleep = 1000; newConfig.env = LauncherConfig.LauncherEnvironment.STD; + return newConfig; + } - LogHelper.warning("Title is not set. Please show ServerWrapper.cfg"); - - // Write LaunchServer config - newConfig.save(); + @Override + public void setConfig(Config config) { + this.config = config; } public static final class Config { @@ -235,13 +253,6 @@ public static final class Config { public String password; public String auth_id = ""; public LauncherConfig.LauncherEnvironment env; - public void save() throws IOException - { - LogHelper.info("Writing ServerWrapper config file"); - try (Writer writer = IOHelper.newWriter(configFile)) { - gson.toJson(this, writer); - } - } } public ClientProfile profile; diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/setup/ServerWrapperSetup.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/setup/ServerWrapperSetup.java index 95af4fc6..14f339e9 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/setup/ServerWrapperSetup.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/setup/ServerWrapperSetup.java @@ -16,8 +16,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.security.spec.InvalidKeySpecException; -import java.util.HashMap; import java.util.jar.JarFile; public class ServerWrapperSetup { @@ -25,6 +23,7 @@ public class ServerWrapperSetup { public PublicURLClassLoader urlClassLoader; public void run() throws IOException { + ServerWrapper wrapper = ServerWrapper.wrapper; System.out.println("Print jar filename:"); String jarName = commands.commandHandler.readLine(); Path jarPath = Paths.get(jarName); @@ -50,9 +49,9 @@ public void run() throws IOException String address = commands.commandHandler.readLine(); System.out.println("Print launchserver port:"); int port = Integer.valueOf(commands.commandHandler.readLine()); - ServerWrapper.config.mainclass = mainClassName; - ServerWrapper.config.address = address; - ServerWrapper.config.port = port; + wrapper.config.mainclass = mainClassName; + wrapper.config.address = address; + wrapper.config.port = port; if(!Files.exists(ServerWrapper.publicKeyFile)) { LogHelper.error("public.key not found"); @@ -65,7 +64,7 @@ public void run() throws IOException else LogHelper.error("public.key not found"); } } - boolean stopOnError = ServerWrapper.config.stopOnError; + boolean stopOnError = wrapper.config.stopOnError; for(int i=0;i<10;++i) { System.out.println("Print server account login:"); @@ -74,18 +73,13 @@ public void run() throws IOException String password = commands.commandHandler.readLine(); System.out.println("Print profile title:"); String title = commands.commandHandler.readLine(); - ServerWrapper.config.login = login; - ServerWrapper.config.password = password; - ServerWrapper.config.title = title; - ServerWrapper.config.stopOnError = false; + wrapper.config.login = login; + wrapper.config.password = password; + wrapper.config.title = title; + wrapper.config.stopOnError = false; LauncherConfig cfg = null; - try { - cfg = new LauncherConfig(ServerWrapper.config.address, ServerWrapper.config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(ServerWrapper.publicKeyFile)), new HashMap<>(), ServerWrapper.config.projectname); - } catch (InvalidKeySpecException e) { - LogHelper.error(e); - } - Launcher.setConfig(cfg); - if(ServerWrapper.auth(ServerWrapper.wrapper)) + + if(wrapper.auth()) { break; } @@ -94,8 +88,8 @@ public void run() throws IOException LogHelper.error("Auth error. Recheck account params"); } } - ServerWrapper.config.stopOnError = stopOnError; - ServerWrapper.config.save(); + wrapper.config.stopOnError = stopOnError; + wrapper.saveConfig(); LogHelper.info("Generate start script"); Path startScript; if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE) startScript = Paths.get("start.bat"); diff --git a/libLauncher/src/main/java/ru/gravit/utils/config/JsonConfigurable.java b/libLauncher/src/main/java/ru/gravit/utils/config/JsonConfigurable.java index ca8cb6b2..ec5de1d7 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/config/JsonConfigurable.java +++ b/libLauncher/src/main/java/ru/gravit/utils/config/JsonConfigurable.java @@ -35,6 +35,7 @@ public void saveConfig(Path configPath) throws IOException } public void loadConfig(Path configPath) throws IOException { + if(generateConfigIfNotExists(configPath)) return; try (BufferedReader reader = IOHelper.newReader(configPath)) { setConfig(Launcher.gson.fromJson(reader, type)); } @@ -52,6 +53,22 @@ public void resetConfig(Path newPath) throws IOException saveConfig(newPath); } + public boolean generateConfigIfNotExists(Path path) throws IOException + { + if(IOHelper.isFile(path)) + return false; + resetConfig(path); + return true; + } + + public boolean generateConfigIfNotExists() throws IOException + { + if(IOHelper.isFile(configPath)) + return false; + resetConfig(); + return true; + } + public abstract T getConfig(); public abstract T getDefaultConfig(); public abstract void setConfig(T config); From bda1c3658bae041047f5cd44a7c11bcfee75da17 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 3 Apr 2019 20:27:40 +0700 Subject: [PATCH 015/128] [ANY] IDEA Reformat code --- LaunchServer/build.gradle | 190 +++++++++--------- .../ru/gravit/launchserver/LaunchServer.java | 112 +++++------ .../launchserver/auth/AuthProviderPair.java | 3 +- .../launchserver/auth/MySQLSourceConfig.java | 3 +- .../auth/handler/MySQLAuthHandler.java | 6 +- .../auth/hwid/JsonFileHWIDHandler.java | 46 ++--- .../auth/hwid/MemoryHWIDHandler.java | 37 ++-- .../auth/hwid/MysqlHWIDHandler.java | 24 +-- .../auth/provider/AuthProvider.java | 3 +- .../auth/provider/MySQLAuthProvider.java | 5 +- .../launchserver/binary/JAConfigurator.java | 5 +- .../binary/JARLauncherBinary.java | 2 +- .../launchserver/binary/ProguardConf.java | 11 +- .../binary/tasks/MainBuildTask.java | 5 +- .../binary/tasks/RadonBuildTask.java | 34 ++-- .../command/auth/AuthCommand.java | 4 +- .../command/auth/UUIDToUsernameCommand.java | 4 +- .../command/auth/UsernameToUUIDCommand.java | 4 +- .../command/dump/DumpEntryCacheCommand.java | 2 +- .../command/handler/CommandHandler.java | 3 +- .../command/hash/DownloadClientCommand.java | 2 +- .../command/install/MultiCommand.java | 3 +- .../command/service/ComponentCommand.java | 52 ++--- .../command/service/GetModulusCommand.java | 2 +- .../service/GetPermissionsCommand.java | 2 +- .../service/GivePermissionsCommand.java | 15 +- .../command/service/ServerStatusCommand.java | 3 +- .../components/AuthLimiterComponent.java | 5 +- .../components/CommandRemoverComponent.java | 11 +- .../launchserver/components/Component.java | 3 + .../config/adapter/AuthHandlerAdapter.java | 3 +- .../config/adapter/AuthProviderAdapter.java | 3 +- .../config/adapter/ComponentAdapter.java | 3 +- .../config/adapter/HWIDHandlerAdapter.java | 3 +- .../adapter/PermissionsHandlerAdapter.java | 3 +- .../config/adapter/ProtectHandlerAdapter.java | 3 +- .../adapter/TextureProviderAdapter.java | 3 +- .../manangers/ModulesManager.java | 2 +- .../response/auth/AuthResponse.java | 6 +- .../response/auth/AuthServerResponse.java | 4 +- .../ru/gravit/launchserver/socket/Client.java | 8 +- .../socket/websocket/WebSocketService.java | 3 +- .../json/admin/AddLogListenerResponse.java | 18 +- .../websocket/json/auth/AuthResponse.java | 29 ++- .../json/auth/CheckServerResponse.java | 4 +- .../websocket/json/auth/ProfilesResponse.java | 5 +- .../json/auth/SetProfileResponse.java | 4 +- .../json/profile/BatchProfileByUsername.java | 10 +- .../json/profile/ProfileByUUIDResponse.java | 3 +- .../json/profile/ProfileByUsername.java | 3 +- .../json/update/LauncherResponse.java | 2 +- .../json/update/UpdateListResponse.java | 2 +- .../websocket/json/update/UpdateResponse.java | 7 +- .../launchserver/console/ConsoleMain.java | 7 +- .../console/RemoteJLineCommandHandler.java | 6 +- .../console/RemoteStdCommandHandler.java | 6 +- Launcher/build.gradle | 38 ++-- Launcher/runtime/dialog/login.fxml | 86 ++++---- Launcher/runtime/dialog/mainmenu.fxml | 170 +++++++++------- Launcher/runtime/dialog/offline/offline.html | 25 +-- .../runtime/dialog/overlay/debug/debug.fxml | 12 +- .../dialog/overlay/options/options.fxml | 46 +++-- .../dialog/overlay/processing/processing.fxml | 29 +-- .../dialog/overlay/settings/settings.fxml | 116 ++++++----- .../runtime/dialog/overlay/update/update.fxml | 64 +++--- .../launcher/ClientLauncherWrapper.java | 4 +- .../launcher/client/ClientLauncher.java | 21 +- .../ru/gravit/launcher/client/DirBridge.java | 4 +- .../launcher/client/FunctionalBridge.java | 21 +- .../launcher/client/LauncherSettings.java | 7 +- .../guard/LauncherGuardInterface.java | 6 + .../launcher/guard/LauncherGuardManager.java | 18 +- .../launcher/guard/LauncherWrapperGuard.java | 23 +-- .../launcher/gui/JSRuntimeProvider.java | 3 +- .../launcher/hwid/OshiHWIDProvider.java | 36 ++-- LauncherAPI/build.gradle | 10 +- .../launcher/downloader/ListDownloader.java | 47 ++--- .../ru/gravit/launcher/request/Request.java | 9 +- .../launcher/request/auth/AuthRequest.java | 7 +- .../request/auth/SetProfileRequest.java | 5 +- .../request/update/LauncherRequest.java | 20 +- .../request/update/ProfilesRequest.java | 3 +- .../request/update/UpdateListRequest.java | 3 +- .../request/update/UpdateRequest.java | 4 +- .../request/websockets/ClientJSONPoint.java | 43 ++-- .../websockets/ClientWebSocketService.java | 42 ++-- .../websockets/LegacyRequestBridge.java | 22 +- .../request/websockets/WaitEventHandler.java | 14 +- ServerWrapper/build.gradle | 8 +- .../launcher/server/ModulesManager.java | 2 +- .../gravit/launcher/server/ServerAgent.java | 5 +- .../gravit/launcher/server/ServerWrapper.java | 28 +-- .../server/setup/ServerWrapperCommands.java | 4 +- .../server/setup/ServerWrapperSetup.java | 48 ++--- libLauncher/build.gradle | 6 +- .../ru/gravit/launcher/ClientPermissions.java | 4 +- .../java/ru/gravit/launcher/Launcher.java | 6 +- .../ru/gravit/launcher/LauncherConfig.java | 2 +- .../java/ru/gravit/launcher/OshiHWID.java | 17 +- .../events/request/AuthRequestEvent.java | 2 + .../BatchProfileByUsernameRequestEvent.java | 3 +- .../events/request/ErrorRequestEvent.java | 1 + .../request/ExecCommandRequestEvent.java | 1 + .../request/JoinServerRequestEvent.java | 1 + .../launcher/events/request/LogEvent.java | 1 + .../request/ProfileByUUIDRequestEvent.java | 3 +- .../ProfileByUsernameRequestEvent.java | 4 +- .../events/request/ProfilesRequestEvent.java | 4 +- .../request/UpdateListRequestEvent.java | 1 + .../events/request/UpdateRequestEvent.java | 1 + .../launcher/hasher/FileNameMatcher.java | 6 +- .../launcher/managers/ConfigManager.java | 18 +- .../managers/SimpleModuleManager.java | 48 ++--- .../ru/gravit/launcher/modules/Module.java | 6 +- .../launcher/profiles/ClientProfile.java | 39 ++-- .../profiles/optional/OptionalFile.java | 21 +- .../profiles/optional/OptionalType.java | 3 +- .../request/JsonResultSerializeAdapter.java | 1 - .../java/ru/gravit/utils/HTTPRequest.java | 3 +- .../main/java/ru/gravit/utils/Version.java | 15 +- .../gravit/utils/command/CommandHandler.java | 8 +- .../gravit/utils/config/JsonConfigurable.java | 38 ++-- .../gravit/utils/downloader/Downloader.java | 7 +- .../java/ru/gravit/utils/helper/IOHelper.java | 4 +- .../ru/gravit/utils/helper/JVMHelper.java | 5 +- .../ru/gravit/utils/helper/LogHelper.java | 49 ++--- 126 files changed, 1031 insertions(+), 1101 deletions(-) diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index 090eb514..503d2d56 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -4,140 +4,140 @@ evaluationDependsOn(':Launcher') repositories { - maven { - url "https://oss.sonatype.org/content/repositories/snapshots" - } - maven { - url "http://maven.geomajas.org/" - } + maven { + url "https://oss.sonatype.org/content/repositories/snapshots" + } + maven { + url "http://maven.geomajas.org/" + } } sourceCompatibility = '1.8' targetCompatibility = '1.8' configurations { - compileOnlyA - bundleOnly - bundle - hikari - pack - launch4j - launch4jCJ - bundleOnly.extendsFrom bundle - compile.extendsFrom bundle, hikari, pack, launch4jCJ, launch4j + compileOnlyA + bundleOnly + bundle + hikari + pack + launch4j + launch4jCJ + bundleOnly.extendsFrom bundle + compile.extendsFrom bundle, hikari, pack, launch4jCJ, launch4j } jar { - dependsOn parent.childProjects.Launcher.tasks.build - from { configurations.pack.collect { it.isDirectory() ? it : zipTree(it) } } - from(parent.childProjects.Launcher.tasks.jar.archivePath, parent.childProjects.Launcher.tasks.genRuntimeJS.archivePath) - manifest.attributes("Main-Class": mainClassName, - "Premain-Class": mainAgentName, - "Can-Redefine-Classes": "true", - "Can-Retransform-Classes": "true", - "Can-Set-Native-Method-Prefix": "true" - ) + dependsOn parent.childProjects.Launcher.tasks.build + from { configurations.pack.collect { it.isDirectory() ? it : zipTree(it) } } + from(parent.childProjects.Launcher.tasks.jar.archivePath, parent.childProjects.Launcher.tasks.genRuntimeJS.archivePath) + manifest.attributes("Main-Class": mainClassName, + "Premain-Class": mainAgentName, + "Can-Redefine-Classes": "true", + "Can-Retransform-Classes": "true", + "Can-Set-Native-Method-Prefix": "true" + ) } dependencies { - pack project(':libLauncher') - bundle project(':Radon') - bundle 'mysql:mysql-connector-java:8.0.13' - bundle 'jline:jline:2.14.6' - bundle 'net.sf.proguard:proguard-base:6.0.3' - bundle 'org.fusesource.jansi:jansi:1.17.1' - bundle 'commons-io:commons-io:2.6' - bundle 'commons-codec:commons-codec:1.11' - bundle 'org.javassist:javassist:3.24.1-GA' - bundle 'io.netty:netty-all:4.1.32.Final' + pack project(':libLauncher') + bundle project(':Radon') + bundle 'mysql:mysql-connector-java:8.0.13' + bundle 'jline:jline:2.14.6' + bundle 'net.sf.proguard:proguard-base:6.0.3' + bundle 'org.fusesource.jansi:jansi:1.17.1' + bundle 'commons-io:commons-io:2.6' + bundle 'commons-codec:commons-codec:1.11' + bundle 'org.javassist:javassist:3.24.1-GA' + bundle 'io.netty:netty-all:4.1.32.Final' - bundle 'org.slf4j:slf4j-simple:1.7.25' - bundle 'org.slf4j:slf4j-api:1.7.25' + bundle 'org.slf4j:slf4j-simple:1.7.25' + bundle 'org.slf4j:slf4j-api:1.7.25' - hikari 'io.micrometer:micrometer-core:1.0.6' - hikari('com.zaxxer:HikariCP:3.2.0') { - exclude group: 'javassist' - exclude group: 'io.micrometer' - exclude group: 'org.slf4j' - } + hikari 'io.micrometer:micrometer-core:1.0.6' + hikari('com.zaxxer:HikariCP:3.2.0') { + exclude group: 'javassist' + exclude group: 'io.micrometer' + exclude group: 'org.slf4j' + } - launch4j('net.sf.launch4j:launch4j:3.12') { - exclude group: 'org.apache.ant' - exclude group: 'net.java.abeille' - exclude group: 'foxtrot' - exclude group: 'com.jgoodies' - } + launch4j('net.sf.launch4j:launch4j:3.12') { + exclude group: 'org.apache.ant' + exclude group: 'net.java.abeille' + exclude group: 'foxtrot' + exclude group: 'com.jgoodies' + } - launch4jCJ('net.sf.launch4j:launch4j:3.12:workdir-win32') { - exclude group: '*' - } + launch4jCJ('net.sf.launch4j:launch4j:3.12:workdir-win32') { + exclude group: '*' + } - launch4jCJ('net.sf.launch4j:launch4j:3.12:workdir-linux') { - exclude group: '*' - } + launch4jCJ('net.sf.launch4j:launch4j:3.12:workdir-linux') { + exclude group: '*' + } - compileOnlyA 'com.google.guava:guava:26.0-jre' - compileOnlyA 'org.apache.logging.log4j:log4j-core:2.11.2' + compileOnlyA 'com.google.guava:guava:26.0-jre' + compileOnlyA 'org.apache.logging.log4j:log4j-core:2.11.2' } task hikari(type: Copy) { - into "$buildDir/libs/libraries/hikaricp" - from configurations.hikari + into "$buildDir/libs/libraries/hikaricp" + from configurations.hikari } task launch4jM(type: Copy) { - into "$buildDir/libs/libraries/launch4j" - from(configurations.launch4jCJ.collect { it.isDirectory() ? it : zipTree(it) }) - includeEmptyDirs false - eachFile { FileCopyDetails fcp -> - if (fcp.relativePath.pathString.startsWith("launch4j-")) { - def segments = fcp.relativePath.segments - def pathSegments = segments[1..-1] as String[] - fcp.relativePath = new RelativePath(!fcp.file.isDirectory(), pathSegments) - fcp.mode = 0755 - } else { - fcp.exclude() - } - } + into "$buildDir/libs/libraries/launch4j" + from(configurations.launch4jCJ.collect { it.isDirectory() ? it : zipTree(it) }) + includeEmptyDirs false + eachFile { FileCopyDetails fcp -> + if (fcp.relativePath.pathString.startsWith("launch4j-")) { + def segments = fcp.relativePath.segments + def pathSegments = segments[1..-1] as String[] + fcp.relativePath = new RelativePath(!fcp.file.isDirectory(), pathSegments) + fcp.mode = 0755 + } else { + fcp.exclude() + } + } } task launch4jA(type: Copy) { - into "$buildDir/libs/libraries/launch4j" - from(configurations.launch4j) - includeEmptyDirs false - eachFile { FileCopyDetails fcp -> - if (fcp.name.startsWith("launch4j")) { - fcp.name = "launch4j.jar" - } - fcp.mode = 0755 - } + into "$buildDir/libs/libraries/launch4j" + from(configurations.launch4j) + includeEmptyDirs false + eachFile { FileCopyDetails fcp -> + if (fcp.name.startsWith("launch4j")) { + fcp.name = "launch4j.jar" + } + fcp.mode = 0755 + } } task dumpLibs(type: Copy) { - dependsOn tasks.hikari, tasks.launch4jM, tasks.launch4jA - into "$buildDir/libs/libraries" - from configurations.bundleOnly + dependsOn tasks.hikari, tasks.launch4jM, tasks.launch4jA + into "$buildDir/libs/libraries" + from configurations.bundleOnly } task dumpCompileOnlyLibs(type: Copy) { - into "$buildDir/libs/launcher-libraries-compile" - from configurations.compileOnlyA + into "$buildDir/libs/launcher-libraries-compile" + from configurations.compileOnlyA } task bundle(type: Zip) { - dependsOn parent.childProjects.Launcher.tasks.build, tasks.dumpLibs, tasks.dumpCompileOnlyLibs, tasks.jar - archiveName 'LaunchServer.zip' - destinationDir file("$buildDir") - from(tasks.dumpLibs.destinationDir) { into 'libraries' } - from(tasks.dumpCompileOnlyLibs.destinationDir) { into 'launcher-libraries-compile' } - from tasks.jar.archivePath - from(parent.childProjects.Launcher.tasks.dumpLibs) { into 'launcher-libraries' } + dependsOn parent.childProjects.Launcher.tasks.build, tasks.dumpLibs, tasks.dumpCompileOnlyLibs, tasks.jar + archiveName 'LaunchServer.zip' + destinationDir file("$buildDir") + from(tasks.dumpLibs.destinationDir) { into 'libraries' } + from(tasks.dumpCompileOnlyLibs.destinationDir) { into 'launcher-libraries-compile' } + from tasks.jar.archivePath + from(parent.childProjects.Launcher.tasks.dumpLibs) { into 'launcher-libraries' } } task dumpClientLibs(type: Copy) { - dependsOn parent.childProjects.Launcher.tasks.build - into "$buildDir/libs/launcher-libraries" - from parent.childProjects.Launcher.tasks.dumpLibs.destinationDir + dependsOn parent.childProjects.Launcher.tasks.build + into "$buildDir/libs/launcher-libraries" + from parent.childProjects.Launcher.tasks.dumpLibs.destinationDir } build.dependsOn tasks.dumpLibs, tasks.dumpCompileOnlyLibs, tasks.dumpClientLibs, tasks.bundle diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 66646a1e..27b3278c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -11,24 +11,20 @@ import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launchserver.auth.AuthProviderPair; -import ru.gravit.launchserver.auth.protect.NoProtectHandler; -import ru.gravit.launchserver.auth.protect.ProtectHandler; -import ru.gravit.launchserver.components.AuthLimiterComponent; import ru.gravit.launchserver.auth.handler.AuthHandler; import ru.gravit.launchserver.auth.handler.MemoryAuthHandler; import ru.gravit.launchserver.auth.hwid.AcceptHWIDHandler; import ru.gravit.launchserver.auth.hwid.HWIDHandler; import ru.gravit.launchserver.auth.permissions.JsonFilePermissionsHandler; import ru.gravit.launchserver.auth.permissions.PermissionsHandler; +import ru.gravit.launchserver.auth.protect.NoProtectHandler; +import ru.gravit.launchserver.auth.protect.ProtectHandler; import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.RejectAuthProvider; import ru.gravit.launchserver.binary.*; +import ru.gravit.launchserver.components.AuthLimiterComponent; import ru.gravit.launchserver.components.Component; -import ru.gravit.utils.config.JsonConfigurable; import ru.gravit.launchserver.config.adapter.*; -import ru.gravit.utils.command.CommandHandler; -import ru.gravit.utils.command.JLineCommandHandler; -import ru.gravit.utils.command.StdCommandHandler; import ru.gravit.launchserver.manangers.*; import ru.gravit.launchserver.manangers.hook.AuthHookManager; import ru.gravit.launchserver.manangers.hook.BuildHookManager; @@ -38,6 +34,10 @@ import ru.gravit.launchserver.socket.ServerSocketHandler; import ru.gravit.launchserver.texture.RequestTextureProvider; import ru.gravit.launchserver.texture.TextureProvider; +import ru.gravit.utils.command.CommandHandler; +import ru.gravit.utils.command.JLineCommandHandler; +import ru.gravit.utils.command.StdCommandHandler; +import ru.gravit.utils.config.JsonConfigurable; import ru.gravit.utils.helper.*; import java.io.BufferedReader; @@ -96,25 +96,21 @@ public static final class Config { private transient AuthProviderPair authDefault; - public AuthProviderPair getAuthProviderPair(String name) - { - for(AuthProviderPair pair : auth) - { - if(pair.name.equals(name)) return pair; + public AuthProviderPair getAuthProviderPair(String name) { + for (AuthProviderPair pair : auth) { + if (pair.name.equals(name)) return pair; } return null; } + public ProtectHandler protectHandler; public PermissionsHandler permissionsHandler; - public AuthProviderPair getAuthProviderPair() - { - if(authDefault != null) return authDefault; - for(AuthProviderPair pair : auth) - { - if(pair.isDefault) - { + public AuthProviderPair getAuthProviderPair() { + if (authDefault != null) return authDefault; + for (AuthProviderPair pair : auth) { + if (pair.isDefault) { authDefault = pair; return pair; } @@ -190,18 +186,16 @@ public void verify() { throw new NullPointerException("AuthHandler must not be null"); } boolean isOneDefault = false; - for(AuthProviderPair pair : auth) { + for (AuthProviderPair pair : auth) { if (pair.isDefault) { isOneDefault = true; break; } } - if(protectHandler == null) - { + if (protectHandler == null) { throw new NullPointerException("ProtectHandler must not be null"); } - if(!isOneDefault) - { + if (!isOneDefault) { throw new IllegalStateException("No auth pairs declared by default."); } if (permissionsHandler == null) { @@ -210,13 +204,12 @@ public void verify() { if (env == null) { throw new NullPointerException("Env must not be null"); } - if(netty == null) - { + if (netty == null) { throw new NullPointerException("Netty must not be null"); } } - public void close() - { + + public void close() { try { for (AuthProviderPair p : auth) p.close(); } catch (IOException e) { @@ -248,8 +241,8 @@ public static class ExeConf { public String txtFileVersion; public String txtProductVersion; } - public class NettyConfig - { + + public class NettyConfig { public String bindAddress; public int port; public boolean clientEnabled; @@ -257,8 +250,8 @@ public class NettyConfig public String launcherEXEURL; public String address; } - public class GuardLicenseConf - { + + public class GuardLicenseConf { public String name; public String key; public String encryptKey; @@ -299,10 +292,10 @@ public static void main(String... args) throws Throwable { long startTime = System.currentTimeMillis(); try { @SuppressWarnings("resource") - LaunchServer launchserver = new LaunchServer(IOHelper.WORKING_DIR, args); - if(args.length == 0) launchserver.run(); + LaunchServer launchserver = new LaunchServer(IOHelper.WORKING_DIR, args); + if (args.length == 0) launchserver.run(); else { //Обработка команды - launchserver.commandHandler.eval(args,false); + launchserver.commandHandler.eval(args, false); } } catch (Throwable exc) { LogHelper.error(exc); @@ -318,7 +311,7 @@ public static void main(String... args) throws Throwable { public final Path launcherLibraries; - public final Path launcherLibrariesCompile; + public final Path launcherLibrariesCompile; public final List args; @@ -383,7 +376,7 @@ public static void main(String... args) throws Throwable { private volatile List profilesList; public volatile Map> updatesDirMap; - public final Timer taskPool; + public final Timer taskPool; public static Gson gson; public static GsonBuilder gsonBuilder; @@ -469,14 +462,12 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE } config.permissionsHandler.init(); config.hwidHandler.init(); - if(config.protectHandler != null) - { + if (config.protectHandler != null) { config.protectHandler.checkLaunchServerLicense(); } - if(config.components != null) - { + if (config.components != null) { LogHelper.debug("PreInit components"); - config.components.forEach((k,v) -> { + config.components.forEach((k, v) -> { LogHelper.subDebug("PreInit component %s", k); v.preInit(this); }); @@ -507,12 +498,11 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE // init modules modulesManager.initModules(); - if(config.components != null) - { + if (config.components != null) { LogHelper.debug("Init components"); - config.components.forEach((k,v) -> { + config.components.forEach((k, v) -> { LogHelper.subDebug("Init component %s", k); - registerObject("component.".concat(k),v); + registerObject("component.".concat(k), v); v.init(this); }); LogHelper.debug("Init components successful"); @@ -542,17 +532,16 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE // post init modules modulesManager.postInitModules(); - if(config.components != null) - { + if (config.components != null) { LogHelper.debug("PostInit components"); - config.components.forEach((k,v) -> { + config.components.forEach((k, v) -> { LogHelper.subDebug("PostInit component %s", k); v.postInit(this); }); LogHelper.debug("PostInit components successful"); } // start updater - if(config.netty != null) + if (config.netty != null) nettyServerSocketHandler = new NettyServerSocketHandler(this); else nettyServerSocketHandler = null; @@ -616,7 +605,7 @@ private void generateConfigIfNotExists() throws IOException { // Create new config LogHelper.info("Creating LaunchServer config"); Config newConfig = new Config(); - newConfig.mirrors = new String[]{"http://mirror.gravitlauncher.ml/","https://mirror.gravit.pro/"}; + newConfig.mirrors = new String[]{"http://mirror.gravitlauncher.ml/", "https://mirror.gravit.pro/"}; newConfig.launch4j = new ExeConf(); newConfig.launch4j.copyright = "© GravitLauncher Team"; newConfig.launch4j.fileDesc = "GravitLauncher ".concat(Launcher.getVersion().getVersionString()); @@ -630,10 +619,10 @@ private void generateConfigIfNotExists() throws IOException { newConfig.env = LauncherConfig.LauncherEnvironment.STD; newConfig.startScript = JVMHelper.OS_TYPE.equals(JVMHelper.OS.MUSTDIE) ? "." + File.separator + "start.bat" : "." + File.separator + "start.sh"; newConfig.hwidHandler = new AcceptHWIDHandler(); - newConfig.auth = new AuthProviderPair[]{ new AuthProviderPair(new RejectAuthProvider("Настройте authProvider"), + newConfig.auth = new AuthProviderPair[]{new AuthProviderPair(new RejectAuthProvider("Настройте authProvider"), new MemoryAuthHandler(), new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png") - , "std") }; + , "std")}; newConfig.protectHandler = new NoProtectHandler(); newConfig.permissionsHandler = new JsonFilePermissionsHandler(); newConfig.port = 7240; @@ -709,7 +698,7 @@ public void run() { JVMHelper.RUNTIME.addShutdownHook(CommonHelper.newThread(null, false, this::close)); CommonHelper.newThread("Command Thread", true, commandHandler).start(); rebindServerSocket(); - if(config.netty != null) + if (config.netty != null) rebindNettyServerSocket(); modulesManager.finishModules(); } @@ -789,22 +778,17 @@ public void restart() { } } - public void registerObject(String name, Object object) - { - if(object instanceof Reloadable) - { + public void registerObject(String name, Object object) { + if (object instanceof Reloadable) { reloadManager.registerReloadable(name, (Reloadable) object); } - if(object instanceof Reconfigurable) - { + if (object instanceof Reconfigurable) { reconfigurableManager.registerReconfigurable(name, (Reconfigurable) object); } - if(object instanceof NeedGarbageCollection) - { + if (object instanceof NeedGarbageCollection) { GarbageManager.registerNeedGC((NeedGarbageCollection) object); } - if(object instanceof JsonConfigurable) - { + if (object instanceof JsonConfigurable) { } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthProviderPair.java index b617f9e5..5710ec5d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthProviderPair.java @@ -20,8 +20,7 @@ public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvi this.name = name; } - public void init() - { + public void init() { provider.init(); handler.init(); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java index 19c348c1..5bae4ea5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/MySQLSourceConfig.java @@ -80,8 +80,7 @@ public synchronized Connection getConnection() throws SQLException { hikari = false; // Try using HikariCP source = mysqlSource; - if(enableHikari) - { + if (enableHikari) { try { Class.forName("com.zaxxer.hikari.HikariDataSource"); hikari = true; // Used for shutdown. Not instanceof because of possible classpath error diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java index 345bd489..30f164a0 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/MySQLAuthHandler.java @@ -65,7 +65,7 @@ protected Entry fetchEntry(UUID uuid) throws IOException { } private Entry query(String sql, String value) throws IOException { - try(Connection c = mySQLHolder.getConnection()) { + try (Connection c = mySQLHolder.getConnection()) { PreparedStatement s = c.prepareStatement(sql); s.setString(1, value); s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); @@ -79,7 +79,7 @@ private Entry query(String sql, String value) throws IOException { @Override protected boolean updateAuth(UUID uuid, String username, String accessToken) throws IOException { - try(Connection c = mySQLHolder.getConnection()) { + try (Connection c = mySQLHolder.getConnection()) { PreparedStatement s = c.prepareStatement(updateAuthSQL); s.setString(1, username); // Username case s.setString(2, accessToken); @@ -93,7 +93,7 @@ protected boolean updateAuth(UUID uuid, String username, String accessToken) thr @Override protected boolean updateServerID(UUID uuid, String serverID) throws IOException { - try(Connection c = mySQLHolder.getConnection()) { + try (Connection c = mySQLHolder.getConnection()) { PreparedStatement s = c.prepareStatement(updateServerIDSQL); s.setString(1, serverID); s.setString(2, uuid.toString()); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java index d8b6c6a8..42bbf627 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonFileHWIDHandler.java @@ -1,7 +1,6 @@ package ru.gravit.launchserver.auth.hwid; import com.google.gson.reflect.TypeToken; -import ru.gravit.launcher.ClientPermissions; import ru.gravit.launcher.HWID; import ru.gravit.launcher.Launcher; import ru.gravit.launchserver.LaunchServer; @@ -16,12 +15,10 @@ import java.nio.file.Paths; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.Objects; public class JsonFileHWIDHandler extends HWIDHandler { - public class Entry - { + public class Entry { public HWID hwid; public String username; public boolean isBanned = false; @@ -43,22 +40,22 @@ public int hashCode() { return Objects.hash(hwid); } } + public String filename = "hwids.json"; public transient LinkedList list = new LinkedList<>(); public String banMessage = "You banned"; + @Override public void ban(List hwid) throws HWIDException { - for(Entry e : list) - { - for(HWID banHWID : hwid) - { - if(e.hwid.equals(banHWID)) e.isBanned = true; + for (Entry e : list) { + for (HWID banHWID : hwid) { + if (e.hwid.equals(banHWID)) e.isBanned = true; } } } + @Override - public void init() - { + public void init() { Path path = Paths.get(filename); Type type = new TypeToken>() { }.getType(); @@ -72,16 +69,13 @@ public void init() @Override public void check0(HWID hwid, String username) throws HWIDException { boolean isOne = false; - for(Entry e : list) - { - if(e.hwid.equals(hwid)) - { + for (Entry e : list) { + if (e.hwid.equals(hwid)) { isOne = true; - if(e.isBanned) throw new HWIDException(banMessage); + if (e.isBanned) throw new HWIDException(banMessage); } } - if(!isOne) - { + if (!isOne) { list.add(new Entry(hwid)); } } @@ -89,8 +83,7 @@ public void check0(HWID hwid, String username) throws HWIDException { @Override public void close() throws Exception { Path path = Paths.get(filename); - try(Writer writer = IOHelper.newWriter(path)) - { + try (Writer writer = IOHelper.newWriter(path)) { LaunchServer.gson.toJson(list, writer); } } @@ -98,20 +91,17 @@ public void close() throws Exception { @Override public List getHwid(String username) throws HWIDException { LinkedList hwids = new LinkedList<>(); - for(Entry e : list) - { - if(e.username.equals(username)) hwids.add(e.hwid); + for (Entry e : list) { + if (e.username.equals(username)) hwids.add(e.hwid); } return hwids; } @Override public void unban(List hwid) throws HWIDException { - for(Entry e : list) - { - for(HWID banHWID : hwid) - { - if(e.hwid.equals(banHWID)) e.isBanned = false; + for (Entry e : list) { + for (HWID banHWID : hwid) { + if (e.hwid.equals(banHWID)) e.isBanned = false; } } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java index 07c7de02..3fed522a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MemoryHWIDHandler.java @@ -7,8 +7,7 @@ import java.util.Objects; public class MemoryHWIDHandler extends HWIDHandler { - public class Entry - { + public class Entry { public HWID hwid; public String username; public boolean isBanned = false; @@ -30,15 +29,15 @@ public int hashCode() { return Objects.hash(hwid); } } + public transient LinkedList list = new LinkedList<>(); public String banMessage = "You banned"; + @Override public void ban(List hwid) throws HWIDException { - for(Entry e : list) - { - for(HWID banHWID : hwid) - { - if(e.hwid.equals(banHWID)) e.isBanned = true; + for (Entry e : list) { + for (HWID banHWID : hwid) { + if (e.hwid.equals(banHWID)) e.isBanned = true; } } } @@ -46,16 +45,13 @@ public void ban(List hwid) throws HWIDException { @Override public void check0(HWID hwid, String username) throws HWIDException { boolean isOne = false; - for(Entry e : list) - { - if(e.hwid.equals(hwid)) - { + for (Entry e : list) { + if (e.hwid.equals(hwid)) { isOne = true; - if(e.isBanned) throw new HWIDException(banMessage); + if (e.isBanned) throw new HWIDException(banMessage); } } - if(!isOne) - { + if (!isOne) { list.add(new Entry(hwid)); } } @@ -73,20 +69,17 @@ public void init() { @Override public List getHwid(String username) throws HWIDException { LinkedList hwids = new LinkedList<>(); - for(Entry e : list) - { - if(e.username.equals(username)) hwids.add(e.hwid); + for (Entry e : list) { + if (e.username.equals(username)) hwids.add(e.hwid); } return hwids; } @Override public void unban(List hwid) throws HWIDException { - for(Entry e : list) - { - for(HWID banHWID : hwid) - { - if(e.hwid.equals(banHWID)) e.isBanned = false; + for (Entry e : list) { + for (HWID banHWID : hwid) { + if (e.hwid.equals(banHWID)) e.isBanned = false; } } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java index a7dbd40f..2f4f037e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java @@ -63,7 +63,7 @@ public class MysqlHWIDHandler extends HWIDHandler { public void check0(HWID hwid, String username) throws HWIDException { if (hwid instanceof OshiHWID) { OshiHWID oshiHWID = (OshiHWID) hwid; - try(Connection c = mySQLHolder.getConnection()) { + try (Connection c = mySQLHolder.getConnection()) { PreparedStatement s = c.prepareStatement(String.format("SELECT %s, %s FROM `%s` WHERE `%s` = ? LIMIT 1", userFieldHwid, userFieldLogin, tableUsers, userFieldLogin)); @@ -141,10 +141,9 @@ public void onCheckInfo(OshiHWID hwid, String username, Connection c) throws HWI } ResultSet set = a.executeQuery(); boolean isOne = false; - while(set.next()) { - if(!oneCompareMode) isOne = true; - if(compareMode) - { + while (set.next()) { + if (!oneCompareMode) isOne = true; + if (compareMode) { OshiHWID db_hwid = new OshiHWID(); db_hwid.serialNumber = set.getString(hwidFieldSerialNumber); db_hwid.processorID = set.getString(hwidFieldProcessorID); @@ -153,19 +152,18 @@ public void onCheckInfo(OshiHWID hwid, String username, Connection c) throws HWI db_hwid.macAddr = ""; LogHelper.dev("Compare HWID: %s vs %s", hwid.getSerializeString(), db_hwid.getSerializeString()); int compare_point = hwid.compare(db_hwid); - if(compare_point < compare) continue; - else - { + if (compare_point < compare) continue; + else { LogHelper.debug("User %s hwid check: found compare %d in %d", username, compare_point, set.getInt("id")); } } - if(oneCompareMode) isOne = true; + if (oneCompareMode) isOne = true; boolean isBanned = set.getBoolean(hwidFieldBanned); if (isBanned) { throw new HWIDException(banMessage); } } - if(isOne) { + if (isOne) { onUpdateInfo(hwid, username, c); } } catch (SQLException e) { @@ -177,7 +175,7 @@ public void setIsBanned(HWID hwid, boolean isBanned) { LogHelper.debug("%s Request HWID: %s", isBanned ? "Ban" : "UnBan", hwid.toString()); if (hwid instanceof OshiHWID) { OshiHWID oshiHWID = (OshiHWID) hwid; - try(Connection c = mySQLHolder.getConnection()) { + try (Connection c = mySQLHolder.getConnection()) { try (PreparedStatement a = c.prepareStatement(queryBan)) { String[] replaceParamsUpd = {"totalMemory", String.valueOf(oshiHWID.totalMemory), "serialNumber", oshiHWID.serialNumber, "HWDiskSerial", oshiHWID.HWDiskSerial, "processorID", oshiHWID.processorID, "isBanned", isBanned ? "1" : "0"}; for (int i = 0; i < paramsBan.length; i++) { @@ -212,7 +210,7 @@ public void unban(List list) { @Override public List getHwid(String username) { ArrayList list = new ArrayList<>(); - try(Connection c = mySQLHolder.getConnection()) { + try (Connection c = mySQLHolder.getConnection()) { LogHelper.debug("Try find HWID from username %s", username); PreparedStatement s = c.prepareStatement(String.format("SELECT %s, %s FROM `%s` WHERE `%s` = ? LIMIT 1", userFieldHwid, userFieldLogin, tableUsers, userFieldLogin)); s.setString(1, username); @@ -248,7 +246,7 @@ public List getHwid(String username) { @Override public void close() { - mySQLHolder.close(); + mySQLHolder.close(); } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java index 2a9572b3..50befb9b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java @@ -37,8 +37,7 @@ public static void registerProviders() { public abstract AuthProviderResult auth(String login, String password, String ip) throws Exception; - public void preAuth(String login, String password, String customText, String ip) throws Exception - { + public void preAuth(String login, String password, String customText, String ip) throws Exception { return; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java index 0f578583..2dac1451 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java @@ -29,8 +29,7 @@ public void init() { @Override public AuthProviderResult auth(String login, String password, String ip) throws SQLException, AuthException { - try(Connection c = mySQLHolder.getConnection()) - { + try (Connection c = mySQLHolder.getConnection()) { PreparedStatement s = c.prepareStatement(query); String[] replaceParams = {"login", login, "password", password, "ip", ip}; for (int i = 0; i < queryParams.length; i++) @@ -47,6 +46,6 @@ public AuthProviderResult auth(String login, String password, String ip) throws @Override public void close() { - mySQLHolder.close(); + mySQLHolder.close(); } } 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 e4280842..d1d84feb 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JAConfigurator.java @@ -70,6 +70,7 @@ public void setAddress(String address) { body.append(address); body.append("\";"); } + public void setNettyAddress(String address) { body.append("this.nettyAddress = \""); body.append(address); @@ -139,6 +140,7 @@ public void setDownloadJava(boolean b) { body.append(b ? "true" : "false"); body.append(";"); } + public void setNettyEnabled(boolean b) { body.append("this.isNettyEnabled = "); body.append(b ? "true" : "false"); @@ -151,8 +153,7 @@ public void setWarningMissArchJava(boolean b) { body.append(";"); } - public void setGuardLicense(String name, String key, String encryptKey) - { + public void setGuardLicense(String name, String key, String encryptKey) { body.append("this.guardLicenseName = \""); body.append(name); body.append("\";"); 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 b5c79351..605d3675 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java @@ -21,7 +21,7 @@ public final class JARLauncherBinary extends LauncherBinary { public final Path buildDir; public List tasks; public List coreLibs; - public List addonLibs; + public List addonLibs; public JARLauncherBinary(LaunchServer server) throws IOException { super(server); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java index 365f55a4..ec2c5ad5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/ProguardConf.java @@ -6,7 +6,9 @@ import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.UnpackHelper; -import java.io.*; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; import java.nio.file.Files; import java.nio.file.Path; import java.security.SecureRandom; @@ -18,8 +20,7 @@ public class ProguardConf { private static String generateString(SecureRandom rand, String lowString, String upString, int il) { StringBuilder sb = new StringBuilder(il + lowString.length()); - for(int i = 0;i "-libraryjars \'" + e.toAbsolutePath().toString() + "\'") .forEach(confStrs::add); srv.launcherBinary.addonLibs.stream() - .map(e -> "-libraryjars \'" + e.toAbsolutePath().toString() + "\'") - .forEach(confStrs::add); + .map(e -> "-libraryjars \'" + e.toAbsolutePath().toString() + "\'") + .forEach(confStrs::add); confStrs.add("-classobfuscationdictionary \'" + words.toFile().getName() + "\'"); confStrs.add(readConf()); return confStrs.toArray(new String[0]); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java index 7c152f26..e173282f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -131,12 +131,11 @@ public Path process(Path inputJar) throws IOException { jaConfigurator.setAddress(server.config.getAddress()); jaConfigurator.setPort(server.config.port); jaConfigurator.setNettyEnabled(server.config.netty.clientEnabled); - if(server.config.netty.clientEnabled) - { + if (server.config.netty.clientEnabled) { jaConfigurator.setNettyPort(server.config.netty.port); jaConfigurator.setNettyAddress(server.config.netty.address); } - if(server.config.guardLicense != null) + if (server.config.guardLicense != null) jaConfigurator.setGuardLicense(server.config.guardLicense.name, server.config.guardLicense.key, server.config.guardLicense.encryptKey); jaConfigurator.setProjectName(server.config.projectName); jaConfigurator.setSecretKey(SecurityHelper.randomStringAESKey()); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/RadonBuildTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/RadonBuildTask.java index c7ab1468..ad822558 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/RadonBuildTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/RadonBuildTask.java @@ -1,5 +1,8 @@ package ru.gravit.launchserver.binary.tasks; +import me.itzsomebody.radon.Radon; +import me.itzsomebody.radon.SessionInfo; +import me.itzsomebody.radon.config.ConfigurationParser; import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.UnpackHelper; @@ -10,10 +13,6 @@ import java.util.List; import java.util.stream.Collectors; -import me.itzsomebody.radon.Radon; -import me.itzsomebody.radon.SessionInfo; -import me.itzsomebody.radon.config.ConfigurationParser; - public class RadonBuildTask implements LauncherBuildTask { private final LaunchServer srv; public final Path config; @@ -31,19 +30,20 @@ public String getName() { @Override public Path process(Path inputFile) throws IOException { - Path outputFile = srv.launcherBinary.nextLowerPath(this); - if (srv.config.enabledRadon) { - if (!IOHelper.isFile(config)) UnpackHelper.unpack(IOHelper.getResourceURL("ru/gravit/launchserver/defaults/radon.cfg"), config); - ConfigurationParser p = new ConfigurationParser(IOHelper.newInput(config)); - SessionInfo info = p.createSessionFromConfig(); - info.setInput(inputFile.toFile()); - info.setOutput(outputFile.toFile()); - List libs = srv.launcherBinary.coreLibs.stream().map(e -> e.toFile()).collect(Collectors.toList()); - libs.addAll(srv.launcherBinary.addonLibs.stream().map(e -> e.toFile()).collect(Collectors.toList())); - info.setLibraries(libs); - Radon r = new Radon(info); - r.run(); - } else + Path outputFile = srv.launcherBinary.nextLowerPath(this); + if (srv.config.enabledRadon) { + if (!IOHelper.isFile(config)) + UnpackHelper.unpack(IOHelper.getResourceURL("ru/gravit/launchserver/defaults/radon.cfg"), config); + ConfigurationParser p = new ConfigurationParser(IOHelper.newInput(config)); + SessionInfo info = p.createSessionFromConfig(); + info.setInput(inputFile.toFile()); + info.setOutput(outputFile.toFile()); + List libs = srv.launcherBinary.coreLibs.stream().map(e -> e.toFile()).collect(Collectors.toList()); + libs.addAll(srv.launcherBinary.addonLibs.stream().map(e -> e.toFile()).collect(Collectors.toList())); + info.setLibraries(libs); + Radon r = new Radon(info); + r.run(); + } else IOHelper.copy(inputFile, outputFile); return outputFile; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/AuthCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/AuthCommand.java index 438191c9..bd40d862 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/AuthCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/AuthCommand.java @@ -28,9 +28,9 @@ public String getUsageDescription() { public void invoke(String... args) throws Exception { verifyArgs(args, 2); AuthProviderPair pair; - if(args.length > 2) pair = server.config.getAuthProviderPair(args[2]); + if (args.length > 2) pair = server.config.getAuthProviderPair(args[2]); else pair = server.config.getAuthProviderPair(); - if(pair == null) throw new IllegalStateException(String.format("Auth %s not found", args[1])); + if (pair == null) throw new IllegalStateException(String.format("Auth %s not found", args[1])); String login = args[0]; String password = args[1]; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java index 3a33d05e..c78d76d2 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java @@ -28,9 +28,9 @@ public String getUsageDescription() { public void invoke(String... args) throws CommandException, IOException { verifyArgs(args, 1); AuthProviderPair pair; - if(args.length > 1) pair = server.config.getAuthProviderPair(args[1]); + if (args.length > 1) pair = server.config.getAuthProviderPair(args[1]); else pair = server.config.getAuthProviderPair(); - if(pair == null) throw new IllegalStateException(String.format("Auth %s not found", args[1])); + if (pair == null) throw new IllegalStateException(String.format("Auth %s not found", args[1])); UUID uuid = parseUUID(args[0]); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java index c1cdd9cc..a7b2ddc3 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java @@ -28,9 +28,9 @@ public String getUsageDescription() { public void invoke(String... args) throws CommandException, IOException { verifyArgs(args, 1); AuthProviderPair pair; - if(args.length > 1) pair = server.config.getAuthProviderPair(args[1]); + if (args.length > 1) pair = server.config.getAuthProviderPair(args[1]); else pair = server.config.getAuthProviderPair(); - if(pair == null) throw new IllegalStateException(String.format("Auth %s not found", args[1])); + if (pair == null) throw new IllegalStateException(String.format("Auth %s not found", args[1])); String username = parseUsername(args[0]); // Get UUID by username diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/dump/DumpEntryCacheCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/dump/DumpEntryCacheCommand.java index 498894df..d3fcc39b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/dump/DumpEntryCacheCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/dump/DumpEntryCacheCommand.java @@ -32,7 +32,7 @@ public String getUsageDescription() { public void invoke(String... args) throws Exception { verifyArgs(args, 3); AuthProviderPair pair = server.config.getAuthProviderPair(args[1]); - if(pair == null) throw new IllegalStateException(String.format("Auth %s not found", args[1])); + if (pair == null) throw new IllegalStateException(String.format("Auth %s not found", args[1])); if (!(pair.handler instanceof CachedAuthHandler)) throw new UnsupportedOperationException("This command used only CachedAuthHandler"); CachedAuthHandler authHandler = (CachedAuthHandler) pair.handler; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java index 7b307ea1..6bd6a752 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java @@ -13,8 +13,7 @@ import ru.gravit.launchserver.command.service.*; public abstract class CommandHandler extends ru.gravit.utils.command.CommandHandler { - public static void registerCommands(ru.gravit.utils.command.CommandHandler handler) - { + public static void registerCommands(ru.gravit.utils.command.CommandHandler handler) { LaunchServer server = LaunchServer.server; // Register basic commands handler.registerCommand("help", new HelpCommand(server)); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadClientCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadClientCommand.java index 7886f1f3..bb6682f3 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadClientCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/hash/DownloadClientCommand.java @@ -4,8 +4,8 @@ import ru.gravit.launcher.profiles.ClientProfile.Version; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; -import ru.gravit.utils.command.CommandException; import ru.gravit.utils.HttpDownloader; +import ru.gravit.utils.command.CommandException; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/install/MultiCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/install/MultiCommand.java index 6033e9ae..52fd7cd4 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/install/MultiCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/install/MultiCommand.java @@ -20,8 +20,7 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - for(String arg : args) - { + for (String arg : args) { server.commandHandler.eval(arg, false); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ComponentCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ComponentCommand.java index 9475d9b0..2d9ea888 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ComponentCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ComponentCommand.java @@ -25,8 +25,7 @@ public String getUsageDescription() { return "component manager"; } - public void printHelp() - { + public void printHelp() { LogHelper.info("Print help for component:"); LogHelper.subInfo("component unload [componentName]"); LogHelper.subInfo("component load [componentName] [filename]"); @@ -37,54 +36,43 @@ public void printHelp() public void invoke(String... args) throws Exception { verifyArgs(args, 1); String componentName = null; - if(args.length > 1) componentName = args[1]; - switch(args[0]) - { - case "unload": - { - if(componentName == null) throw new IllegalArgumentException("Must set componentName"); + if (args.length > 1) componentName = args[1]; + switch (args[0]) { + case "unload": { + if (componentName == null) throw new IllegalArgumentException("Must set componentName"); Component component = server.config.components.get(componentName); - if(component == null) { + if (component == null) { LogHelper.error("Component %s not found", componentName); return; } - if(component instanceof AutoCloseable) - { + if (component instanceof AutoCloseable) { ((AutoCloseable) component).close(); - } - else - { + } else { LogHelper.error("Component %s unload not supported", componentName); return; } break; } - case "gc": - { - if(componentName == null) throw new IllegalArgumentException("Must set componentName"); + case "gc": { + if (componentName == null) throw new IllegalArgumentException("Must set componentName"); Component component = server.config.components.get(componentName); - if(component == null) { + if (component == null) { LogHelper.error("Component %s not found", componentName); return; } - if(component instanceof NeedGarbageCollection) - { + if (component instanceof NeedGarbageCollection) { ((NeedGarbageCollection) component).garbageCollection(); - } - else - { + } else { LogHelper.error("Component %s gc not supported", componentName); return; } break; } - case "load": - { - if(componentName == null) throw new IllegalArgumentException("Must set componentName"); - if(args.length <= 2) throw new IllegalArgumentException("Must set file"); + case "load": { + if (componentName == null) throw new IllegalArgumentException("Must set componentName"); + if (args.length <= 2) throw new IllegalArgumentException("Must set file"); String fileName = args[2]; - try(Reader reader = IOHelper.newReader(Paths.get(fileName))) - { + try (Reader reader = IOHelper.newReader(Paths.get(fileName))) { Component component = LaunchServer.gson.fromJson(reader, Component.class); component.preInit(server); component.init(server); @@ -92,12 +80,10 @@ public void invoke(String... args) throws Exception { LogHelper.info("Component %s(%s) loaded", componentName, component.getClass().getName()); } } - case "help": - { + case "help": { printHelp(); } - default: - { + default: { printHelp(); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetModulusCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetModulusCommand.java index 848fe1d0..16b8b75b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetModulusCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetModulusCommand.java @@ -1,5 +1,5 @@ package ru.gravit.launchserver.command.service; - + import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.utils.helper.LogHelper; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetPermissionsCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetPermissionsCommand.java index f0bb6ebf..80c022eb 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetPermissionsCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GetPermissionsCommand.java @@ -22,7 +22,7 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - verifyArgs(args,1); + verifyArgs(args, 1); String username = args[0]; ClientPermissions permissions = server.config.permissionsHandler.getPermissions(username); LogHelper.info("Permissions %s: %s (long: %d)", username, permissions.toString(), permissions.toLong()); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GivePermissionsCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GivePermissionsCommand.java index cc0b1083..32a04b2c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GivePermissionsCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/GivePermissionsCommand.java @@ -27,25 +27,20 @@ public void invoke(String... args) throws Exception { ClientPermissions permissions = server.config.permissionsHandler.getPermissions(username); String permission = args[1]; boolean isEnabled = Boolean.valueOf(args[2]); - switch (permission) - { - case "admin": - { + switch (permission) { + case "admin": { permissions.canAdmin = isEnabled; break; } - case "server": - { + case "server": { permissions.canServer = isEnabled; break; } - case "bot": - { + case "bot": { permissions.canBot = isEnabled; break; } - default: - { + default: { LogHelper.error("Unknown permission: %s", permission); return; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ServerStatusCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ServerStatusCommand.java index 1783578a..f3abc242 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ServerStatusCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ServerStatusCommand.java @@ -34,8 +34,7 @@ public void invoke(String... args) { LogHelper.info("Uptime: %d days %d hours %d minutes %d seconds", days, hour, min, second); LogHelper.info("Uptime (double): %f", (double) JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000); LogHelper.info("Sessions: %d | Modules: %d | Commands: %d", server.sessionManager.getSessions().size(), server.modulesManager.modules.size(), server.commandHandler.commandsMap().size()); - for(AuthProviderPair pair : server.config.auth) - { + for (AuthProviderPair pair : server.config.auth) { if (pair.handler instanceof CachedAuthHandler) { LogHelper.info("AuthHandler %s: EntryCache: %d | usernameCache: %d", pair.name, ((CachedAuthHandler) pair.handler).getEntryCache().size(), ((CachedAuthHandler) pair.handler).getUsernamesCache().size()); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/components/AuthLimiterComponent.java b/LaunchServer/src/main/java/ru/gravit/launchserver/components/AuthLimiterComponent.java index 2d357355..00eb2947 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/components/AuthLimiterComponent.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/components/AuthLimiterComponent.java @@ -4,7 +4,6 @@ import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.provider.AuthProvider; -import ru.gravit.launchserver.components.Component; import ru.gravit.launchserver.response.auth.AuthResponse; import ru.gravit.launchserver.socket.Client; @@ -26,9 +25,9 @@ public void init(LaunchServer launchServer) { public void postInit(LaunchServer launchServer) { } + public void preAuthHook(AuthResponse.AuthContext context, Client client) throws AuthException { - if(isLimit(context.ip)) - { + if (isLimit(context.ip)) { AuthProvider.authError(message); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/components/CommandRemoverComponent.java b/LaunchServer/src/main/java/ru/gravit/launchserver/components/CommandRemoverComponent.java index a6078dbd..68863341 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/components/CommandRemoverComponent.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/components/CommandRemoverComponent.java @@ -9,6 +9,7 @@ public class CommandRemoverComponent extends Component implements AutoCloseable { public String[] removeList = new String[]{}; public transient Map commandsList = new HashMap<>(); + @Override public void preInit(LaunchServer launchServer) { @@ -21,18 +22,16 @@ public void init(LaunchServer launchServer) { @Override public void postInit(LaunchServer launchServer) { - for(String cmd : removeList) - { + for (String cmd : removeList) { Command removedCmd = launchServer.commandHandler.unregisterCommand(cmd); - if(removedCmd != null) - commandsList.put(cmd, removedCmd); + if (removedCmd != null) + commandsList.put(cmd, removedCmd); } } @Override public void close() throws Exception { - for(Map.Entry e : commandsList.entrySet()) - { + for (Map.Entry e : commandsList.entrySet()) { LaunchServer.server.commandHandler.registerCommand(e.getKey(), e.getValue()); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java b/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java index b0ebcd57..a98c3bc3 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java @@ -35,7 +35,10 @@ public static void registerComponents() { registredComp = true; } } + public abstract void preInit(LaunchServer launchServer); + public abstract void init(LaunchServer launchServer); + public abstract void postInit(LaunchServer launchServer); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthHandlerAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthHandlerAdapter.java index d636f196..4fdd35c5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthHandlerAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthHandlerAdapter.java @@ -13,8 +13,7 @@ public class AuthHandlerAdapter implements JsonSerializer, JsonDese public AuthHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); Class cls = AuthHandler.getHandlerClass(typename); - if(cls == null) - { + if (cls == null) { LogHelper.error("AuthHandler %s not found", typename); return null; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthProviderAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthProviderAdapter.java index 017208c9..38f9e119 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthProviderAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/AuthProviderAdapter.java @@ -13,8 +13,7 @@ public class AuthProviderAdapter implements JsonSerializer, JsonDe public AuthProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); Class cls = AuthProvider.getProviderClass(typename); - if(cls == null) - { + if (cls == null) { LogHelper.error("AuthProvider %s not found", typename); return null; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/ComponentAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/ComponentAdapter.java index 1342a1d5..b4b9e312 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/ComponentAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/ComponentAdapter.java @@ -13,8 +13,7 @@ public class ComponentAdapter implements JsonSerializer, JsonDeserial public Component deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); Class cls = Component.getComponentClass(typename); - if(cls == null) - { + if (cls == null) { LogHelper.error("Component %s not found", typename); return null; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/HWIDHandlerAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/HWIDHandlerAdapter.java index 0c97d3dc..f16149e9 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/HWIDHandlerAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/HWIDHandlerAdapter.java @@ -13,8 +13,7 @@ public class HWIDHandlerAdapter implements JsonSerializer, JsonDese public HWIDHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); Class cls = HWIDHandler.getHandlerClass(typename); - if(cls == null) - { + if (cls == null) { LogHelper.error("HWIDHandler %s not found", typename); return null; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/PermissionsHandlerAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/PermissionsHandlerAdapter.java index aef7f2fc..35c30a72 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/PermissionsHandlerAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/PermissionsHandlerAdapter.java @@ -13,8 +13,7 @@ public class PermissionsHandlerAdapter implements JsonSerializer cls = PermissionsHandler.getHandlerClass(typename); - if(cls == null) - { + if (cls == null) { LogHelper.error("PermissionsHandler %s not found", typename); return null; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/ProtectHandlerAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/ProtectHandlerAdapter.java index a1120de5..48fca6f8 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/ProtectHandlerAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/ProtectHandlerAdapter.java @@ -13,8 +13,7 @@ public class ProtectHandlerAdapter implements JsonSerializer, Js public ProtectHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); Class cls = ProtectHandler.getHandlerClass(typename); - if(cls == null) - { + if (cls == null) { LogHelper.error("ProtectHandler %s not found", typename); return null; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/TextureProviderAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/TextureProviderAdapter.java index 908099a9..80d81cd3 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/TextureProviderAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/adapter/TextureProviderAdapter.java @@ -13,8 +13,7 @@ public class TextureProviderAdapter implements JsonSerializer, public TextureProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); Class cls = TextureProvider.getProviderClass(typename); - if(cls == null) - { + if (cls == null) { LogHelper.error("TextureProvider %s not found", typename); return null; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java index d50eda93..481dbe88 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java @@ -1,7 +1,7 @@ package ru.gravit.launchserver.manangers; -import ru.gravit.launcher.managers.SimpleModulesConfigManager; import ru.gravit.launcher.managers.SimpleModuleManager; +import ru.gravit.launcher.managers.SimpleModulesConfigManager; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.modules.CoreModule; import ru.gravit.launchserver.modules.LaunchServerModuleContext; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java index 69028ae8..da36c8e5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java @@ -83,9 +83,9 @@ public void reply() throws Exception { debug("Login: '%s', Password: '%s'", login, echo(password.length())); AuthProviderResult result; AuthProviderPair pair; - if(auth_id.isEmpty()) pair = server.config.getAuthProviderPair(); + if (auth_id.isEmpty()) pair = server.config.getAuthProviderPair(); else pair = server.config.getAuthProviderPair(auth_id); - if(pair == null) requestError("Auth type not found"); + if (pair == null) requestError("Auth type not found"); AuthProvider provider = pair.provider; clientData.type = Client.Type.USER; AuthContext context = new AuthContext(session, login, password.length(), customText, client, hwid_str, ip, false); @@ -94,7 +94,7 @@ public void reply() throws Exception { if (!clientData.checkSign) { throw new AuthException("You must using checkLauncher"); } - provider.preAuth(login,password,customText,ip); + provider.preAuth(login, password, customText, ip); result = provider.auth(login, password, ip); if (!VerifyHelper.isValidUsername(result.username)) { AuthProvider.authError(String.format("Illegal result: '%s'", result.username)); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java index 52551c15..ada8529e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthServerResponse.java @@ -52,9 +52,9 @@ public void reply() throws Exception { debug("ServerLogin: '%s', Password: '%s'", login, echo(password.length())); AuthProviderResult result; AuthProviderPair pair; - if(auth_id.isEmpty()) pair = server.config.getAuthProviderPair(); + if (auth_id.isEmpty()) pair = server.config.getAuthProviderPair(); else pair = server.config.getAuthProviderPair(auth_id); - if(pair == null) requestError("Auth type not found"); + if (pair == null) requestError("Auth type not found"); AuthProvider provider = pair.provider; AuthResponse.AuthContext context = new AuthResponse.AuthContext(session, login, password.length(), null, client, null, ip, true); try { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/Client.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/Client.java index 9db84f43..e384953e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/Client.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/Client.java @@ -34,10 +34,10 @@ public Client(long session) { public void up() { timestamp = System.currentTimeMillis(); } - public void updateAuth() - { - if(!isAuth) return; - if(auth_id.isEmpty()) auth = LaunchServer.server.config.getAuthProviderPair(); + + public void updateAuth() { + if (!isAuth) return; + if (auth_id.isEmpty()) auth = LaunchServer.server.config.getAuthProviderPair(); else auth = LaunchServer.server.config.getAuthProviderPair(auth_id); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java index e9b5db5e..4b27efc5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java @@ -36,7 +36,7 @@ public WebSocketService(ChannelGroup channels, LaunchServer server, GsonBuilder this.server = server; this.gsonBuiler = gson; this.gsonBuiler.registerTypeAdapter(JsonResponseInterface.class, new JsonResponseAdapter(this)); - this.gsonBuiler.registerTypeAdapter(ResultInterface.class,new JsonResultSerializeAdapter()); + this.gsonBuiler.registerTypeAdapter(ResultInterface.class, new JsonResultSerializeAdapter()); this.gsonBuiler.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter()); this.gson = gsonBuiler.create(); } @@ -86,6 +86,7 @@ public void registerResponses() { public void sendObject(ChannelHandlerContext ctx, Object obj) { ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, ResultInterface.class))); } + public void sendObject(ChannelHandlerContext ctx, Object obj, Type type) { ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, type))); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/admin/AddLogListenerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/admin/AddLogListenerResponse.java index f2ad8c38..9f9b4754 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/admin/AddLogListenerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/admin/AddLogListenerResponse.java @@ -10,6 +10,7 @@ public class AddLogListenerResponse implements JsonResponseInterface { public LogHelper.OutputTypes outputType = LogHelper.OutputTypes.PLAIN; + @Override public String getType() { return "addLogListener"; @@ -25,25 +26,20 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client service.sendObject(ctx, new ErrorRequestEvent("Access denied")); return; } - if(client.logOutput != null) - { + if (client.logOutput != null) { LogHelper.info("Client %s remove log listener", client.username); LogHelper.removeOutput(client.logOutput); - } - else - { + } else { LogHelper.info("Client %s add log listener", client.username); LogHelper.Output output = (str) -> { - if(!ctx.isRemoved()) - { - service.sendObject(ctx,new LogEvent(str)); - } - else { + if (!ctx.isRemoved()) { + service.sendObject(ctx, new LogEvent(str)); + } else { LogHelper.removeOutput(client.logOutput); LogHelper.info("Client %s remove log listener", client.username); } }; - client.logOutput = new LogHelper.OutputEnity(output,outputType); + client.logOutput = new LogHelper.OutputEnity(output, outputType); LogHelper.addOutput(client.logOutput); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java index e36a47aa..a0d746de 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java @@ -42,9 +42,9 @@ public AuthResponse(String login, String password, String auth_id, OshiHWID hwid public String auth_id; public ConnectTypes authType; public OshiHWID hwid; - public enum ConnectTypes - { - SERVER,CLIENT,BOT + + public enum ConnectTypes { + SERVER, CLIENT, BOT } @Override @@ -57,12 +57,11 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client try { AuthRequestEvent result = new AuthRequestEvent(); String ip = IOHelper.getIP(ctx.channel().remoteAddress()); - if ((authType == null || authType == ConnectTypes.CLIENT) &&!clientData.checkSign) { + if ((authType == null || authType == ConnectTypes.CLIENT) && !clientData.checkSign) { AuthProvider.authError("Don't skip Launcher Update"); return; } - if(password == null) - { + if (password == null) { try { password = IOHelper.decode(SecurityHelper.newRSADecryptCipher(LaunchServer.server.privateKey). doFinal(encryptedPassword)); @@ -71,21 +70,19 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client } } clientData.permissions = LaunchServer.server.config.permissionsHandler.getPermissions(login); - if(authType == ConnectTypes.BOT && !clientData.permissions.canBot) - { + if (authType == ConnectTypes.BOT && !clientData.permissions.canBot) { AuthProvider.authError("authType: BOT not allowed for this account"); } - if(authType == ConnectTypes.SERVER && !clientData.permissions.canServer) - { + if (authType == ConnectTypes.SERVER && !clientData.permissions.canServer) { AuthProvider.authError("authType: SERVER not allowed for this account"); } AuthProviderPair pair; - if(auth_id.isEmpty()) pair = LaunchServer.server.config.getAuthProviderPair(); + if (auth_id.isEmpty()) pair = LaunchServer.server.config.getAuthProviderPair(); else pair = LaunchServer.server.config.getAuthProviderPair(auth_id); - ru.gravit.launchserver.response.auth.AuthResponse.AuthContext context = new ru.gravit.launchserver.response.auth.AuthResponse.AuthContext(0, login, password.length(),customText, client, ip, null, false); + ru.gravit.launchserver.response.auth.AuthResponse.AuthContext context = new ru.gravit.launchserver.response.auth.AuthResponse.AuthContext(0, login, password.length(), customText, client, ip, null, false); AuthProvider provider = pair.provider; LaunchServer.server.authHookManager.preHook(context, clientData); - provider.preAuth(login,password,customText,ip); + provider.preAuth(login, password, customText, ip); AuthProviderResult aresult = provider.auth(login, password, ip); if (!VerifyHelper.isValidUsername(aresult.username)) { AuthProvider.authError(String.format("Illegal result: '%s'", aresult.username)); @@ -104,8 +101,8 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client // throw new AuthException("You profile not found"); //} UUID uuid = pair.handler.auth(aresult); - if(authType == ConnectTypes.CLIENT) - LaunchServer.server.config.hwidHandler.check(hwid, aresult.username); + if (authType == ConnectTypes.CLIENT) + LaunchServer.server.config.hwidHandler.check(hwid, aresult.username); LaunchServer.server.authHookManager.postHook(context, clientData); clientData.isAuth = true; clientData.permissions = aresult.permissions; @@ -113,7 +110,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client clientData.updateAuth(); result.accessToken = aresult.accessToken; result.permissions = clientData.permissions; - result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,uuid,aresult.username,client, clientData.auth.textureProvider); + result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server, uuid, aresult.username, client, clientData.auth.textureProvider); service.sendObject(ctx, result); } catch (AuthException | HWIDException e) { service.sendObject(ctx, new ErrorRequestEvent(e.getMessage())); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java index 46c1bdfc..e66e2263 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java @@ -26,8 +26,8 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client CheckServerRequestEvent result = new CheckServerRequestEvent(); try { result.uuid = pClient.auth.handler.checkServer(username, serverID); - if(result.uuid != null) - result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,result.uuid,username,client, pClient.auth.textureProvider); + if (result.uuid != null) + result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server, result.uuid, username, client, pClient.auth.textureProvider); } catch (AuthException e) { service.sendObject(ctx, new ErrorRequestEvent(e.getMessage())); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java index e4610cc4..592928f5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java @@ -11,7 +11,7 @@ import java.util.List; -public class ProfilesResponse implements JsonResponseInterface { +public class ProfilesResponse implements JsonResponseInterface { @Override public String getType() { return "profiles"; @@ -19,8 +19,7 @@ public String getType() { @Override public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { - if(!client.checkSign) - { + if (!client.checkSign) { service.sendObject(ctx, new ErrorRequestEvent("Access denied")); return; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java index c12b5053..25cd7b2e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java @@ -13,6 +13,7 @@ public class SetProfileResponse implements JsonResponseInterface { public String client; + @Override public String getType() { return "setProfile"; @@ -20,8 +21,7 @@ public String getType() { @Override public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { - if(!client.isAuth) - { + if (!client.isAuth) { service.sendObject(ctx, new ErrorRequestEvent("Access denied")); return; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java index c3945080..a1127bf8 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java @@ -11,12 +11,13 @@ import java.util.UUID; public class BatchProfileByUsername implements JsonResponseInterface { - class Entry - { + class Entry { String username; String client; } + Entry[] list; + @Override public String getType() { return "batchProfileByUsername"; @@ -26,10 +27,9 @@ public String getType() { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { BatchProfileByUsernameRequestEvent result = new BatchProfileByUsernameRequestEvent(); result.playerProfiles = new PlayerProfile[list.length]; - for(int i=0;i set = new HashSet<>(); - for(Map.Entry> entry : LaunchServer.server.updatesDirMap.entrySet()) + for (Map.Entry> entry : LaunchServer.server.updatesDirMap.entrySet()) set.add(entry.getKey()); service.sendObject(ctx, new UpdateListRequestEvent(set)); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateResponse.java index 26965f25..4c7ece96 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/UpdateResponse.java @@ -11,6 +11,7 @@ public class UpdateResponse implements JsonResponseInterface { public String dir; + @Override public String getType() { return "update"; @@ -19,18 +20,18 @@ public String getType() { @Override public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { if (!client.isAuth || client.type != Client.Type.USER || client.profile == null) { - service.sendObject(ctx,new ErrorRequestEvent("Access denied")); + service.sendObject(ctx, new ErrorRequestEvent("Access denied")); return; } if (!client.permissions.canAdmin) { for (ClientProfile p : LaunchServer.server.getProfiles()) { if (!client.profile.getTitle().equals(p.getTitle())) continue; if (!p.isWhitelistContains(client.username)) { - service.sendObject(ctx,new ErrorRequestEvent("You don't download this folder")); + service.sendObject(ctx, new ErrorRequestEvent("You don't download this folder")); return; } } } - service.sendObject(ctx,new UpdateRequestEvent(LaunchServer.server.updatesDirMap.get(dir).object)); + service.sendObject(ctx, new UpdateRequestEvent(LaunchServer.server.updatesDirMap.get(dir).object)); } } diff --git a/LaunchServerConsole/src/main/java/ru/gravit/launchserver/console/ConsoleMain.java b/LaunchServerConsole/src/main/java/ru/gravit/launchserver/console/ConsoleMain.java index 1ef58115..783d65e0 100644 --- a/LaunchServerConsole/src/main/java/ru/gravit/launchserver/console/ConsoleMain.java +++ b/LaunchServerConsole/src/main/java/ru/gravit/launchserver/console/ConsoleMain.java @@ -8,13 +8,12 @@ public class ConsoleMain { public static CommandHandler commandHandler; + public static void main(String[] args) throws IOException { - if(ServerWrapper.config == null) - { + if (ServerWrapper.config == null) { LogHelper.warning("ServerWrapper not found"); } - if(!ServerWrapper.permissions.canAdmin) - { + if (!ServerWrapper.permissions.canAdmin) { LogHelper.warning("Permission canAdmin not found"); } try { diff --git a/LaunchServerConsole/src/main/java/ru/gravit/launchserver/console/RemoteJLineCommandHandler.java b/LaunchServerConsole/src/main/java/ru/gravit/launchserver/console/RemoteJLineCommandHandler.java index f3ff23b1..7032c840 100644 --- a/LaunchServerConsole/src/main/java/ru/gravit/launchserver/console/RemoteJLineCommandHandler.java +++ b/LaunchServerConsole/src/main/java/ru/gravit/launchserver/console/RemoteJLineCommandHandler.java @@ -9,10 +9,10 @@ public class RemoteJLineCommandHandler extends JLineCommandHandler { public RemoteJLineCommandHandler() throws IOException { } + @Override - public void eval(String line, boolean bell) - { - if(line.equals("exit")) System.exit(0); + public void eval(String line, boolean bell) { + if (line.equals("exit")) System.exit(0); ExecCommandRequest request = new ExecCommandRequest(System.out::println, line); try { request.request(); diff --git a/LaunchServerConsole/src/main/java/ru/gravit/launchserver/console/RemoteStdCommandHandler.java b/LaunchServerConsole/src/main/java/ru/gravit/launchserver/console/RemoteStdCommandHandler.java index 8be4c4b7..6bc07031 100644 --- a/LaunchServerConsole/src/main/java/ru/gravit/launchserver/console/RemoteStdCommandHandler.java +++ b/LaunchServerConsole/src/main/java/ru/gravit/launchserver/console/RemoteStdCommandHandler.java @@ -8,10 +8,10 @@ public class RemoteStdCommandHandler extends StdCommandHandler { public RemoteStdCommandHandler(boolean readCommands) { super(readCommands); } + @Override - public void eval(String line, boolean bell) - { - if(line.equals("exit")) System.exit(0); + public void eval(String line, boolean bell) { + if (line.equals("exit")) System.exit(0); ExecCommandRequest request = new ExecCommandRequest(System.out::println, line); try { request.request(); diff --git a/Launcher/build.gradle b/Launcher/build.gradle index 0007a5fe..a5f72937 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -2,43 +2,43 @@ String mainAgentName = "ru.gravit.launcher.LauncherAgent" repositories { - maven { - url "http://repo.spring.io/plugins-release/" - } + maven { + url "http://repo.spring.io/plugins-release/" + } } sourceCompatibility = '1.8' targetCompatibility = '1.8' configurations { - bundle - pack - compile.extendsFrom bundle, pack + bundle + pack + compile.extendsFrom bundle, pack } jar { - from { configurations.pack.collect { it.isDirectory() ? it : zipTree(it) } } - manifest.attributes("Main-Class": mainClassName, - "Premain-Class": mainAgentName, - "Can-Redefine-Classes": "true", - "Can-Retransform-Classes": "true", - "Can-Set-Native-Method-Prefix": "true") + from { configurations.pack.collect { it.isDirectory() ? it : zipTree(it) } } + manifest.attributes("Main-Class": mainClassName, + "Premain-Class": mainAgentName, + "Can-Redefine-Classes": "true", + "Can-Retransform-Classes": "true", + "Can-Set-Native-Method-Prefix": "true") } dependencies { - pack project(':LauncherAPI') // Not error on obf. - bundle 'com.github.oshi:oshi-core:3.13.0' + pack project(':LauncherAPI') // Not error on obf. + bundle 'com.github.oshi:oshi-core:3.13.0' } task genRuntimeJS(type: Zip) { - archiveName = "runtime.zip" - destinationDir = file("${buildDir}/tmp") - from "runtime/" + archiveName = "runtime.zip" + destinationDir = file("${buildDir}/tmp") + from "runtime/" } task dumpLibs(type: Copy) { - into "$buildDir/libs/libraries" - from configurations.bundle + into "$buildDir/libs/libraries" + from configurations.bundle } diff --git a/Launcher/runtime/dialog/login.fxml b/Launcher/runtime/dialog/login.fxml index 33c4584c..d08ba181 100644 --- a/Launcher/runtime/dialog/login.fxml +++ b/Launcher/runtime/dialog/login.fxml @@ -12,42 +12,52 @@ - - - - - - - - - - - - - - - - - - - - - - +