diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 5a4e2849..ced4b54a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -38,7 +38,6 @@ import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.net.InetSocketAddress; -import java.net.MalformedURLException; import java.net.SocketAddress; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; @@ -586,6 +585,7 @@ public void run() { JVMHelper.RUNTIME.addShutdownHook(CommonHelper.newThread(null, false, this::close)); CommonHelper.newThread("Command Thread", true, commandHandler).start(); rebindServerSocket(); + modulesManager.finishModules(); } 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 7c19b137..a98811e3 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 @@ -4,7 +4,6 @@ import ru.gravit.utils.helper.LogHelper; import java.io.IOException; -import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -66,11 +65,8 @@ protected Entry fetchEntry(UUID uuid) throws IOException { private Entry query(String sql, String value) throws IOException { try { - Connection c = mySQLHolder.getConnection(); - PreparedStatement s = c.prepareStatement(sql); + PreparedStatement s = mySQLHolder.getConnection().prepareStatement(sql); s.setString(1, value); - - // Execute query s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); try (ResultSet set = s.executeQuery()) { return constructEntry(set); @@ -83,13 +79,10 @@ 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(); - PreparedStatement s = c.prepareStatement(updateAuthSQL); + PreparedStatement s = mySQLHolder.getConnection().prepareStatement(updateAuthSQL); s.setString(1, username); // Username case s.setString(2, accessToken); s.setString(3, uuid.toString()); - - // Execute update s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); return s.executeUpdate() > 0; } catch (SQLException e) { @@ -100,12 +93,9 @@ 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(); - PreparedStatement s = c.prepareStatement(updateServerIDSQL); + PreparedStatement s = mySQLHolder.getConnection().prepareStatement(updateServerIDSQL); s.setString(1, serverID); s.setString(2, uuid.toString()); - - // Execute update s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); return s.executeUpdate() > 0; } catch (SQLException e) { 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 e102f3b7..b3852c7e 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 @@ -226,6 +226,6 @@ public List getHwid(String username) { @Override public void close() { - // Do nothing + mySQLHolder.close(); } } 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 e3e0c6ae..cb817ba5 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 @@ -7,7 +7,6 @@ import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; -import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -28,8 +27,7 @@ public void init() { @Override public AuthProviderResult auth(String login, String password, String ip) throws SQLException, AuthException { - Connection c = mySQLHolder.getConnection(); - PreparedStatement s = c.prepareStatement(query); + PreparedStatement s = mySQLHolder.getConnection().prepareStatement(query); String[] replaceParams = {"login", login, "password", password, "ip", ip}; for (int i = 0; i < queryParams.length; i++) s.setString(i + 1, CommonHelper.replace(queryParams[i], replaceParams)); @@ -43,6 +41,6 @@ public AuthProviderResult auth(String login, String password, String ip) throws @Override public void close() { - // Do nothing + mySQLHolder.close(); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java index 6e3b7723..850e573e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java @@ -1,20 +1,16 @@ package ru.gravit.launchserver.command.basic; -import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.socket.NettyServerSocketHandler; import ru.gravit.utils.helper.CommonHelper; -import ru.gravit.utils.helper.IOHelper; - -import java.io.Writer; public class TestCommand extends Command { public TestCommand(LaunchServer server) { super(server); } - NettyServerSocketHandler handler; + private NettyServerSocketHandler handler = null; @Override public String getArgsDescription() { @@ -33,14 +29,6 @@ public void invoke(String... args) throws Exception { handler = new NettyServerSocketHandler(server); if (args[0].equals("start")) { CommonHelper.newThread("Netty Server", true, handler).start(); - } - if (args[0].equals("profile")) { - ClientProfile profile = new ClientProfile("1.7.10", "asset1.7.10", 0, "Test1.7.10", "localhost", 25565, true, false, "net.minecraft.launchwrapper.Launch"); - try (Writer writer = IOHelper.newWriter(server.dir.resolve("profiles").resolve("Test.cfg"))) { - LaunchServer.gson.toJson(profile, writer); - } - - } if (args[0].equals("stop")) { handler.close(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java index 8593cccb..7f77b039 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/StdCommandHandler.java @@ -16,7 +16,6 @@ public StdCommandHandler(LaunchServer server, boolean readCommands) { @Override public void bell() { - // Do nothing, unsupported } @Override 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 a0314530..d50eda93 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java @@ -1,6 +1,6 @@ package ru.gravit.launchserver.manangers; -import ru.gravit.launcher.managers.ModulesConfigManager; +import ru.gravit.launcher.managers.SimpleModulesConfigManager; import ru.gravit.launcher.managers.SimpleModuleManager; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.modules.CoreModule; @@ -11,11 +11,11 @@ import java.util.ArrayList; public class ModulesManager extends SimpleModuleManager { - public ModulesConfigManager configManager; + public SimpleModulesConfigManager configManager; public ModulesManager(LaunchServer lsrv) { modules = new ArrayList<>(1); - configManager = new ModulesConfigManager(lsrv.dir.resolve("config")); + configManager = new SimpleModulesConfigManager(lsrv.dir.resolve("config")); classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); context = new LaunchServerModuleContext(lsrv, classloader, configManager); registerCoreModule(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/BuildHookManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/BuildHookManager.java index 703caeeb..ba82805d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/BuildHookManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/hook/BuildHookManager.java @@ -1,7 +1,6 @@ package ru.gravit.launchserver.manangers.hook; import ru.gravit.launcher.AutogenConfig; -import ru.gravit.launcher.modules.TestClientModule; import ru.gravit.launchserver.binary.BuildContext; import ru.gravit.launchserver.binary.JAConfigurator; import ru.gravit.launchserver.binary.tasks.MainBuildTask; @@ -41,7 +40,6 @@ public BuildHookManager() { registerIgnoredClass("META-INF/DEPENDENCIES"); registerIgnoredClass("META-INF/LICENSE"); registerIgnoredClass("META-INF/NOTICE"); - registerClientModuleClass(TestClientModule.class.getName()); } public void autoRegisterIgnoredClass(String clazz) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java b/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java index 1e43c23e..26bd9e1f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/modules/LaunchServerModuleContext.java @@ -1,18 +1,18 @@ package ru.gravit.launchserver.modules; -import ru.gravit.launcher.managers.ModulesConfigManager; +import ru.gravit.launcher.managers.SimpleModulesConfigManager; import ru.gravit.launcher.modules.ModuleContext; -import ru.gravit.launcher.modules.ModulesConfigManagerInterface; -import ru.gravit.launcher.modules.ModulesManagerInterface; +import ru.gravit.launcher.modules.ModulesConfigManager; +import ru.gravit.launcher.modules.ModulesManager; import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.PublicURLClassLoader; public class LaunchServerModuleContext implements ModuleContext { public final LaunchServer launchServer; public final PublicURLClassLoader classloader; - public final ModulesConfigManager modulesConfigManager; + public final SimpleModulesConfigManager modulesConfigManager; - public LaunchServerModuleContext(LaunchServer server, PublicURLClassLoader classloader, ModulesConfigManager modulesConfigManager) { + public LaunchServerModuleContext(LaunchServer server, PublicURLClassLoader classloader, SimpleModulesConfigManager modulesConfigManager) { launchServer = server; this.classloader = classloader; this.modulesConfigManager = modulesConfigManager; @@ -24,12 +24,12 @@ public Type getType() { } @Override - public ModulesManagerInterface getModulesManager() { + public ModulesManager getModulesManager() { return launchServer.modulesManager; } @Override - public ModulesConfigManagerInterface getModulesConfigManager() { + public ModulesConfigManager getModulesConfigManager() { return modulesConfigManager; } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index f05970ed..4b1bca74 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -59,7 +59,7 @@ private LauncherEngine() { public void start(String... args) throws Throwable { LogHelper.debug("%d", LauncherSettings.settingsMagic); Launcher.modulesManager = new ClientModuleManager(this); - LauncherConfig.getAutogenConfig().initModules(); //INIT + LauncherConfig.getAutogenConfig().initModules(); Launcher.modulesManager.preInitModules(); if (runtimeProvider == null) runtimeProvider = new JSRuntimeProvider(); runtimeProvider.init(false); @@ -67,10 +67,9 @@ public void start(String... args) throws Throwable { if (started.getAndSet(true)) throw new IllegalStateException("Launcher has been already started"); Launcher.modulesManager.initModules(); - // Load init.js script runtimeProvider.preLoad(); FunctionalBridge.worker = new RequestWorker(); - CommonHelper.newThread("FX Task Worker", true, FunctionalBridge.worker).start(); + CommonHelper.newThread("Task Worker", true, FunctionalBridge.worker).start(); FunctionalBridge.getHWID = CommonHelper.newThread("GetHWID Thread", true, FunctionalBridge::getHWID); FunctionalBridge.getHWID.start(); LogHelper.debug("Dir: %s", DirBridge.dir); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java index 2328565c..1253b764 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleContext.java @@ -3,8 +3,8 @@ import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherEngine; import ru.gravit.launcher.modules.ModuleContext; -import ru.gravit.launcher.modules.ModulesConfigManagerInterface; -import ru.gravit.launcher.modules.ModulesManagerInterface; +import ru.gravit.launcher.modules.ModulesConfigManager; +import ru.gravit.launcher.modules.ModulesManager; public class ClientModuleContext implements ModuleContext { public final LauncherEngine engine; @@ -19,12 +19,12 @@ public Type getType() { } @Override - public ModulesManagerInterface getModulesManager() { + public ModulesManager getModulesManager() { return Launcher.modulesManager; } @Override - public ModulesConfigManagerInterface getModulesConfigManager() { + public ModulesConfigManager getModulesConfigManager() { return null; // ClientModuleContext не поддерживает modulesConfigManager } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java index f41cda42..3beac090 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java @@ -13,12 +13,12 @@ public ClientModuleManager(LauncherEngine engine) { } @Override - public void loadModule(URL jarpath, boolean preload) { + public void loadModule(URL jarpath, String classname) { throw new SecurityException("Custom JAR's load not allowed here"); } @Override - public void loadModule(URL jarpath, String classname, boolean preload) { + public void loadModuleFull(URL jarpath) { throw new SecurityException("Custom JAR's load not allowed here"); } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java b/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java index bcd63969..a3109c43 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/JSRuntimeProvider.java @@ -147,9 +147,9 @@ private void setScriptBindings() { public void run(String[] args) throws ScriptException, NoSuchMethodException, IOException { loadScript(Launcher.INIT_SCRIPT_FILE); LogHelper.info("Invoking start() function"); - Invocable invoker = (Invocable) engine; Launcher.modulesManager.postInitModules(); - invoker.invokeFunction("start", (Object) args); + ((Invocable) engine).invokeFunction("start", (Object) args); + Launcher.modulesManager.finishModules(); } @Override diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java index edbacbfd..de21f7f5 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ModulesManager.java @@ -1,6 +1,6 @@ package ru.gravit.launcher.server; -import ru.gravit.launcher.managers.ModulesConfigManager; +import ru.gravit.launcher.managers.SimpleModulesConfigManager; import ru.gravit.launcher.managers.SimpleModuleManager; import ru.gravit.utils.PublicURLClassLoader; @@ -9,11 +9,11 @@ import java.util.ArrayList; public class ModulesManager extends SimpleModuleManager { - public ModulesConfigManager modulesConfigManager; + public SimpleModulesConfigManager modulesConfigManager; public ModulesManager(ServerWrapper wrapper) { modules = new ArrayList<>(); - modulesConfigManager = new ModulesConfigManager(Paths.get("modules-config")); + modulesConfigManager = new SimpleModulesConfigManager(Paths.get("modules-config")); classloader = new PublicURLClassLoader(new URL[0], ClassLoader.getSystemClassLoader()); context = new ServerModuleContext(wrapper, classloader, modulesConfigManager); } diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java index 8727ca82..607cca82 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerAgent.java @@ -63,16 +63,16 @@ public static void premain(String agentArgument, Instrumentation instrumentation Object[] args = {agentArgument, instrumentation}; mainMethod.invoke(args); } catch (Throwable e) { - e.printStackTrace(); + LogHelper.error(e); } } } public static void loadLibraries(Path dir) { try { - Files.walkFileTree(dir, Collections.singleton(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new StarterVisitor()); + IOHelper.walk(dir, new StarterVisitor(), true); } catch (IOException e) { - e.printStackTrace(System.err); + LogHelper.error(e); } } } diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java index 93802a0d..f1e47397 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerModuleContext.java @@ -1,18 +1,18 @@ package ru.gravit.launcher.server; import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.managers.ModulesConfigManager; +import ru.gravit.launcher.managers.SimpleModulesConfigManager; import ru.gravit.launcher.modules.ModuleContext; -import ru.gravit.launcher.modules.ModulesConfigManagerInterface; -import ru.gravit.launcher.modules.ModulesManagerInterface; +import ru.gravit.launcher.modules.ModulesConfigManager; +import ru.gravit.launcher.modules.ModulesManager; import ru.gravit.utils.PublicURLClassLoader; public class ServerModuleContext implements ModuleContext { public final PublicURLClassLoader classLoader; public final ServerWrapper wrapper; - public final ModulesConfigManager modulesConfigManager; + public final SimpleModulesConfigManager modulesConfigManager; - public ServerModuleContext(ServerWrapper wrapper, PublicURLClassLoader classLoader, ModulesConfigManager modulesConfigManager) { + public ServerModuleContext(ServerWrapper wrapper, PublicURLClassLoader classLoader, SimpleModulesConfigManager modulesConfigManager) { this.classLoader = classLoader; this.wrapper = wrapper; this.modulesConfigManager = modulesConfigManager; @@ -24,12 +24,12 @@ public Type getType() { } @Override - public ModulesManagerInterface getModulesManager() { + public ModulesManager getModulesManager() { return Launcher.modulesManager; } @Override - public ModulesConfigManagerInterface getModulesConfigManager() { + public ModulesConfigManager getModulesConfigManager() { return modulesConfigManager; } } 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 d46e36cf..8ee17b3d 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -77,6 +77,8 @@ public static boolean loopAuth(ServerWrapper wrapper, int count, int sleeptime) try { Thread.sleep(sleeptime); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + LogHelper.error(e); return false; } } @@ -179,10 +181,6 @@ private static void generateConfigIfNotExists() throws IOException { newConfig.reconnectCount = 10; newConfig.reconnectSleep = 1000; newConfig.env = LauncherConfig.LauncherEnvironment.STD; - //try(Reader reader = IOHelper.newReader(IOHelper.getResourceURL("ru/gravit/launcher/server/ServerWrapper.cfg"))) - //{ - // newConfig = gson.fromJson(reader,Config.class); - //} LogHelper.warning("Title is not set. Please show ServerWrapper.cfg"); diff --git a/build.gradle b/build.gradle index 6c9468a2..d359fea1 100644 --- a/build.gradle +++ b/build.gradle @@ -26,4 +26,6 @@ options.encoding = "UTF-8" options.annotationProcessorPath = configurations.aptOnly } -} \ No newline at end of file +} + +defaultTasks 'build' diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index fe399fbf..9d235d96 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -2,12 +2,11 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import ru.gravit.launcher.modules.ModulesManagerInterface; +import ru.gravit.launcher.modules.ModulesManager; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.HInput; import ru.gravit.utils.Version; import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.JVMHelper; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.SecurityHelper; @@ -37,7 +36,7 @@ public final class Launcher { private static final AtomicReference CONFIG = new AtomicReference<>(); @LauncherAPI - public static ModulesManagerInterface modulesManager = null; + public static ModulesManager modulesManager = null; @LauncherAPI public static final int PROTOCOL_MAGIC_LEGACY = 0x724724_00 + 24; @LauncherAPI @@ -126,12 +125,6 @@ public static Version getVersion() { return new Version(MAJOR, MINOR, PATCH, BUILD, RELEASE); } - public static final boolean useAvanguard = true; - - public static boolean isUsingAvanguard() { - return JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE && useAvanguard; - } - public static void applyLauncherEnv(LauncherConfig.LauncherEnvironment env) { switch (env) diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java index 19b6794e..8c94c604 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java @@ -20,10 +20,6 @@ public boolean isAgentStarted() { return isAgentStarted; } - public static long getObjSize(Object obj) { - return inst.getObjectSize(obj); - } - public static void premain(String agentArgument, Instrumentation instrumentation) { System.out.println("Launcher Agent"); inst = instrumentation; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java b/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java index 40898330..fc4202d5 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModuleManager.java @@ -2,7 +2,7 @@ import ru.gravit.launcher.modules.Module; import ru.gravit.launcher.modules.ModuleContext; -import ru.gravit.launcher.modules.ModulesManagerInterface; +import ru.gravit.launcher.modules.ModulesManager; import ru.gravit.utils.PublicURLClassLoader; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; @@ -14,26 +14,20 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.jar.JarFile; -import java.util.jar.Manifest; -public class SimpleModuleManager implements ModulesManagerInterface, AutoCloseable { +public class SimpleModuleManager implements ModulesManager { protected final class ModulesVisitor extends SimpleFileVisitor { private ModulesVisitor() { } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - try { - JarFile f = new JarFile(file.toString()); - Manifest m = f.getManifest(); - String mainclass = m.getMainAttributes().getValue("Main-Class"); - loadModule(file.toUri().toURL(), mainclass, true); - f.close(); - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { - e.printStackTrace(); - } - - // Return result + if (file.toFile().getName().endsWith(".jar")) + try (JarFile f = new JarFile(file.toFile())) { + loadModule(file.toUri().toURL(), f.getManifest().getMainAttributes().getValue("Main-Class")); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + LogHelper.error(e); + } return super.visitFile(file, attrs); } } @@ -72,7 +66,6 @@ public void close() { } @Override - public void initModules() { for (Module m : modules) { m.init(context); @@ -81,53 +74,35 @@ public void initModules() { } @Override - public void load(Module module) { modules.add(module); } - @Override - - public void load(Module module, boolean preload) { - load(module); - if (!preload) module.init(context); - } - - - @Override - - public void loadModule(URL jarpath, boolean preload) throws ClassNotFoundException, IllegalAccessException, InstantiationException, URISyntaxException, IOException { - JarFile f = new JarFile(Paths.get(jarpath.toURI()).toString()); - Manifest m = f.getManifest(); - String mainclass = m.getMainAttributes().getValue("Main-Class"); - loadModule(jarpath, mainclass, preload); - f.close(); - } - public void loadModuleFull(URL jarpath) throws ClassNotFoundException, IllegalAccessException, InstantiationException, URISyntaxException, IOException { - JarFile f = new JarFile(Paths.get(jarpath.toURI()).toString()); - Manifest m = f.getManifest(); - String mainclass = m.getMainAttributes().getValue("Main-Class"); - classloader.addURL(jarpath); - Class moduleclass = Class.forName(mainclass, true, classloader); - Module module = (Module) moduleclass.newInstance(); - modules.add(module); - module.preInit(context); - module.init(context); - module.postInit(context); - LogHelper.info("Module %s version: %s loaded", module.getName(), module.getVersion()); - f.close(); + try (JarFile f = new JarFile(Paths.get(jarpath.toURI()).toFile())) { + classloader.addURL(jarpath); + Module module = (Module) Class.forName(f.getManifest().getMainAttributes().getValue("Main-Class"), true, classloader).newInstance(); + modules.add(module); + module.preInit(context); + module.init(context); + module.postInit(context); + module.finish(context); + LogHelper.info("Module %s version: %s loaded", module.getName(), module.getVersion()); + } } - @Override + @Override + public void loadModule(URL jarpath) throws Exception { + try (JarFile f = new JarFile(Paths.get(jarpath.toURI()).toFile())) { + loadModule(jarpath, f.getManifest().getMainAttributes().getValue("Main-Class")); + } + } - public void loadModule(URL jarpath, String classname, boolean preload) throws ClassNotFoundException, IllegalAccessException, InstantiationException { + @Override + public void loadModule(URL jarpath, String classname) throws ClassNotFoundException, IllegalAccessException, InstantiationException { classloader.addURL(jarpath); - Class moduleclass = Class.forName(classname, true, classloader); - Module module = (Module) moduleclass.newInstance(); + Module module = (Module) Class.forName(classname, true, classloader).newInstance(); modules.add(module); - module.preInit(context); - if (!preload) module.init(context); LogHelper.info("Module %s version: %s loaded", module.getName(), module.getVersion()); } @@ -141,7 +116,6 @@ public void postInitModules() { @Override - public void preInitModules() { for (Module m : modules) { m.preInit(context); @@ -150,7 +124,6 @@ public void preInitModules() { } @Override - public void printModules() { for (Module m : modules) LogHelper.info("Module %s version: %s", m.getName(), m.getVersion()); @@ -158,9 +131,16 @@ public void printModules() { } @Override - - public void registerModule(Module module, boolean preload) { - load(module, preload); + public void registerModule(Module module) { + load(module); LogHelper.info("Module %s version: %s registered", module.getName(), module.getVersion()); } + + @Override + public void finishModules() { + for (Module m : modules) { + m.finish(context); + LogHelper.info("Module %s version: %s finished initialization", m.getName(), m.getVersion()); + } + } } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/managers/ModulesConfigManager.java b/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModulesConfigManager.java similarity index 82% rename from libLauncher/src/main/java/ru/gravit/launcher/managers/ModulesConfigManager.java rename to libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModulesConfigManager.java index f8561247..7a588ece 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/managers/ModulesConfigManager.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/managers/SimpleModulesConfigManager.java @@ -1,6 +1,6 @@ package ru.gravit.launcher.managers; -import ru.gravit.launcher.modules.ModulesConfigManagerInterface; +import ru.gravit.launcher.modules.ModulesConfigManager; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; @@ -8,10 +8,10 @@ import java.nio.file.Files; import java.nio.file.Path; -public class ModulesConfigManager implements ModulesConfigManagerInterface { +public class SimpleModulesConfigManager implements ModulesConfigManager { public Path configDir; - public ModulesConfigManager(Path configDir) { + public SimpleModulesConfigManager(Path configDir) { this.configDir = configDir; } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/Module.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/Module.java index f696c036..408f498d 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/Module.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/Module.java @@ -15,4 +15,8 @@ public interface Module extends AutoCloseable { void postInit(ModuleContext context); void preInit(ModuleContext context); + + default void finish(ModuleContext context) { + // NOP + }; } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java index 3161434a..2284593d 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModuleContext.java @@ -7,7 +7,7 @@ enum Type { Type getType(); - ModulesManagerInterface getModulesManager(); + ModulesManager getModulesManager(); - ModulesConfigManagerInterface getModulesConfigManager(); + ModulesConfigManager getModulesConfigManager(); } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManagerInterface.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManager.java similarity index 76% rename from libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManagerInterface.java rename to libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManager.java index f49e4406..cbf70ce8 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManagerInterface.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesConfigManager.java @@ -2,7 +2,7 @@ import java.nio.file.Path; -public interface ModulesConfigManagerInterface { +public interface ModulesConfigManager { Path getModuleConfig(String moduleName); Path getModuleConfigDir(String moduleName); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManager.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManager.java new file mode 100644 index 00000000..5ff7b7bc --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManager.java @@ -0,0 +1,25 @@ +package ru.gravit.launcher.modules; + +import java.net.URL; + +public interface ModulesManager extends AutoCloseable { + void initModules(); + + void load(Module module); + + void loadModule(URL jarpath) throws Exception; + + void loadModule(URL jarpath, String classname) throws Exception; + + void postInitModules(); + + void preInitModules(); + + void finishModules(); + + void printModules(); + + void sort(); + + void registerModule(Module module); +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManagerInterface.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManagerInterface.java deleted file mode 100644 index 87e7eb22..00000000 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/ModulesManagerInterface.java +++ /dev/null @@ -1,25 +0,0 @@ -package ru.gravit.launcher.modules; - -import java.net.URL; - -public interface ModulesManagerInterface { - void initModules(); - - void load(Module module); - - void load(Module module, boolean preload); - - void loadModule(URL jarpath, boolean preload) throws Exception; - - void loadModule(URL jarpath, String classname, boolean preload) throws Exception; - - void postInitModules(); - - void preInitModules(); - - void printModules(); - - void sort(); - - void registerModule(Module module, boolean preload); -} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/TestClientModule.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/TestClientModule.java deleted file mode 100644 index 49efd84c..00000000 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/TestClientModule.java +++ /dev/null @@ -1,42 +0,0 @@ -package ru.gravit.launcher.modules; - - -import ru.gravit.launcher.Launcher; -import ru.gravit.utils.Version; - -public class TestClientModule implements Module { - @Override - public void close() { - - } - - @Override - public String getName() { - return "TestClientModule"; - } - - @Override - public Version getVersion() { - return Launcher.getVersion(); - } - - @Override - public int getPriority() { - return 0; - } - - @Override - public void init(ModuleContext context) { - - } - - @Override - public void postInit(ModuleContext context) { - - } - - @Override - public void preInit(ModuleContext context) { - - } -} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java index ffbfb5bb..b5d6476c 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java @@ -10,22 +10,6 @@ import java.util.*; public final class ClientProfile implements Comparable { - public ClientProfile(String version, String assetIndex, int sortIndex, String title, String serverAddress, int serverPort, boolean updateFastCheck, boolean useWhitelist, String mainClass) { - this.version = version; - this.assetIndex = assetIndex; - this.sortIndex = sortIndex; - this.title = title; - this.info = info; - this.serverAddress = serverAddress; - this.serverPort = serverPort; - this.updateFastCheck = updateFastCheck; - this.useWhitelist = useWhitelist; - this.mainClass = mainClass; - } - - public ClientProfile() { - } - @LauncherAPI public enum Version { MC147("1.4.7", 51),