mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-09 00:59:44 +03:00
[FEATURE][EXPERIMENTAL] Новая система модулей уже в лаунчсервере
This commit is contained in:
parent
114cd2f8c6
commit
a980935092
19 changed files with 176 additions and 30 deletions
|
@ -38,6 +38,8 @@
|
||||||
import pro.gravit.launcher.hasher.HashedDir;
|
import pro.gravit.launcher.hasher.HashedDir;
|
||||||
import pro.gravit.launcher.managers.ConfigManager;
|
import pro.gravit.launcher.managers.ConfigManager;
|
||||||
import pro.gravit.launcher.managers.GarbageManager;
|
import pro.gravit.launcher.managers.GarbageManager;
|
||||||
|
import pro.gravit.launcher.modules.LauncherModulesManager;
|
||||||
|
import pro.gravit.launcher.modules.events.ClosePhase;
|
||||||
import pro.gravit.launcher.profiles.ClientProfile;
|
import pro.gravit.launcher.profiles.ClientProfile;
|
||||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||||
import pro.gravit.launchserver.binary.EXEL4JLauncherBinary;
|
import pro.gravit.launchserver.binary.EXEL4JLauncherBinary;
|
||||||
|
@ -51,6 +53,11 @@
|
||||||
import pro.gravit.launchserver.manangers.*;
|
import pro.gravit.launchserver.manangers.*;
|
||||||
import pro.gravit.launchserver.manangers.hook.AuthHookManager;
|
import pro.gravit.launchserver.manangers.hook.AuthHookManager;
|
||||||
import pro.gravit.launchserver.manangers.hook.BuildHookManager;
|
import pro.gravit.launchserver.manangers.hook.BuildHookManager;
|
||||||
|
import pro.gravit.launchserver.modules.events.LaunchServerFullInitEvent;
|
||||||
|
import pro.gravit.launchserver.modules.events.LaunchServerInitPhase;
|
||||||
|
import pro.gravit.launchserver.modules.events.LaunchServerPostInitPhase;
|
||||||
|
import pro.gravit.launchserver.modules.events.NewLaunchServerInstanceEvent;
|
||||||
|
import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager;
|
||||||
import pro.gravit.launchserver.socket.handlers.NettyServerSocketHandler;
|
import pro.gravit.launchserver.socket.handlers.NettyServerSocketHandler;
|
||||||
import pro.gravit.utils.command.*;
|
import pro.gravit.utils.command.*;
|
||||||
import pro.gravit.utils.helper.CommonHelper;
|
import pro.gravit.utils.helper.CommonHelper;
|
||||||
|
@ -226,7 +233,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
||||||
public final AuthHookManager authHookManager;
|
public final AuthHookManager authHookManager;
|
||||||
// Server
|
// Server
|
||||||
|
|
||||||
public final ModulesManager modulesManager;
|
public final LaunchServerModulesManager modulesManager;
|
||||||
|
|
||||||
public final MirrorManager mirrorManager;
|
public final MirrorManager mirrorManager;
|
||||||
|
|
||||||
|
@ -268,7 +275,7 @@ public void collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, LaunchServerConfig config, LaunchServerRuntimeConfig runtimeConfig, LaunchServerConfigManager launchServerConfigManager, ModulesManager modulesManager, RSAPublicKey publicKey, RSAPrivateKey privateKey, CommandHandler commandHandler) throws IOException, InvalidKeySpecException {
|
public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, LaunchServerConfig config, LaunchServerRuntimeConfig runtimeConfig, LaunchServerConfigManager launchServerConfigManager, LaunchServerModulesManager modulesManager, RSAPublicKey publicKey, RSAPrivateKey privateKey, CommandHandler commandHandler) throws IOException, InvalidKeySpecException {
|
||||||
this.dir = directories.dir;
|
this.dir = directories.dir;
|
||||||
this.env = env;
|
this.env = env;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
@ -292,7 +299,7 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
|
||||||
serverCertFile = dir.resolve("server.crt");
|
serverCertFile = dir.resolve("server.crt");
|
||||||
serverKeyFile = dir.resolve("server.key");
|
serverKeyFile = dir.resolve("server.key");
|
||||||
|
|
||||||
modulesManager.initContext(this);
|
modulesManager.invokeEvent(new NewLaunchServerInstanceEvent(this));
|
||||||
|
|
||||||
// Print keypair fingerprints
|
// Print keypair fingerprints
|
||||||
CRC32 crc = new CRC32();
|
CRC32 crc = new CRC32();
|
||||||
|
@ -302,11 +309,6 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
|
||||||
// Load class bindings.
|
// Load class bindings.
|
||||||
launcherEXEBinaryClass = defaultLauncherEXEBinaryClass;
|
launcherEXEBinaryClass = defaultLauncherEXEBinaryClass;
|
||||||
|
|
||||||
// pre init modules
|
|
||||||
//modulesManager = new ModulesManager(this);
|
|
||||||
//modulesManager.autoload(dir.resolve("modules"));
|
|
||||||
modulesManager.preInitModules();
|
|
||||||
|
|
||||||
runtime.verify();
|
runtime.verify();
|
||||||
config.verify();
|
config.verify();
|
||||||
if (config.components != null) {
|
if (config.components != null) {
|
||||||
|
@ -371,7 +373,7 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
|
||||||
pro.gravit.launchserver.command.handler.CommandHandler.registerCommands(commandHandler, this);
|
pro.gravit.launchserver.command.handler.CommandHandler.registerCommands(commandHandler, this);
|
||||||
|
|
||||||
// init modules
|
// init modules
|
||||||
modulesManager.initModules();
|
modulesManager.invokeEvent(new LaunchServerInitPhase(this));
|
||||||
if (config.components != null) {
|
if (config.components != null) {
|
||||||
LogHelper.debug("Init components");
|
LogHelper.debug("Init components");
|
||||||
config.components.forEach((k, v) -> {
|
config.components.forEach((k, v) -> {
|
||||||
|
@ -400,7 +402,7 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
|
||||||
syncProfilesDir();
|
syncProfilesDir();
|
||||||
|
|
||||||
// post init modules
|
// post init modules
|
||||||
modulesManager.postInitModules();
|
modulesManager.invokeEvent(new LaunchServerPostInitPhase(this));
|
||||||
if (config.components != null) {
|
if (config.components != null) {
|
||||||
LogHelper.debug("PostInit components");
|
LogHelper.debug("PostInit components");
|
||||||
config.components.forEach((k, v) -> {
|
config.components.forEach((k, v) -> {
|
||||||
|
@ -457,7 +459,7 @@ public void close() throws Exception {
|
||||||
|
|
||||||
// Close handlers & providers
|
// Close handlers & providers
|
||||||
config.close(ReloadType.FULL);
|
config.close(ReloadType.FULL);
|
||||||
modulesManager.close();
|
modulesManager.invokeEvent(new ClosePhase());
|
||||||
LogHelper.info("Save LaunchServer runtime config");
|
LogHelper.info("Save LaunchServer runtime config");
|
||||||
launchServerConfigManager.writeRuntimeConfig(runtime);
|
launchServerConfigManager.writeRuntimeConfig(runtime);
|
||||||
// Print last message before death :(
|
// Print last message before death :(
|
||||||
|
@ -504,7 +506,8 @@ public void run() {
|
||||||
}
|
}
|
||||||
if (config.netty != null)
|
if (config.netty != null)
|
||||||
rebindNettyServerSocket();
|
rebindNettyServerSocket();
|
||||||
modulesManager.finishModules();
|
modulesManager.fullInitializedLaunchServer(this);
|
||||||
|
modulesManager.invokeEvent(new LaunchServerFullInitEvent(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import pro.gravit.launchserver.config.LaunchServerConfig;
|
import pro.gravit.launchserver.config.LaunchServerConfig;
|
||||||
import pro.gravit.launchserver.config.LaunchServerRuntimeConfig;
|
import pro.gravit.launchserver.config.LaunchServerRuntimeConfig;
|
||||||
import pro.gravit.launchserver.manangers.ModulesManager;
|
import pro.gravit.launchserver.manangers.ModulesManager;
|
||||||
|
import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager;
|
||||||
import pro.gravit.utils.command.CommandHandler;
|
import pro.gravit.utils.command.CommandHandler;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -14,7 +15,7 @@ public class LaunchServerBuilder {
|
||||||
private LaunchServerRuntimeConfig runtimeConfig;
|
private LaunchServerRuntimeConfig runtimeConfig;
|
||||||
private CommandHandler commandHandler;
|
private CommandHandler commandHandler;
|
||||||
private LaunchServer.LaunchServerEnv env;
|
private LaunchServer.LaunchServerEnv env;
|
||||||
private ModulesManager modulesManager;
|
private LaunchServerModulesManager modulesManager;
|
||||||
private LaunchServer.LaunchServerDirectories directories = new LaunchServer.LaunchServerDirectories();
|
private LaunchServer.LaunchServerDirectories directories = new LaunchServer.LaunchServerDirectories();
|
||||||
private RSAPublicKey publicKey;
|
private RSAPublicKey publicKey;
|
||||||
private RSAPrivateKey privateKey;
|
private RSAPrivateKey privateKey;
|
||||||
|
@ -30,7 +31,7 @@ public LaunchServerBuilder setEnv(LaunchServer.LaunchServerEnv env) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LaunchServerBuilder setModulesManager(ModulesManager modulesManager) {
|
public LaunchServerBuilder setModulesManager(LaunchServerModulesManager modulesManager) {
|
||||||
this.modulesManager = modulesManager;
|
this.modulesManager = modulesManager;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launcher.hwid.HWIDProvider;
|
import pro.gravit.launcher.hwid.HWIDProvider;
|
||||||
|
import pro.gravit.launcher.modules.events.PreConfigPhase;
|
||||||
import pro.gravit.launchserver.auth.handler.AuthHandler;
|
import pro.gravit.launchserver.auth.handler.AuthHandler;
|
||||||
import pro.gravit.launchserver.auth.hwid.HWIDHandler;
|
import pro.gravit.launchserver.auth.hwid.HWIDHandler;
|
||||||
import pro.gravit.launchserver.auth.permissions.PermissionsHandler;
|
import pro.gravit.launchserver.auth.permissions.PermissionsHandler;
|
||||||
|
@ -14,6 +15,7 @@
|
||||||
import pro.gravit.launchserver.dao.provider.DaoProvider;
|
import pro.gravit.launchserver.dao.provider.DaoProvider;
|
||||||
import pro.gravit.launchserver.manangers.LaunchServerGsonManager;
|
import pro.gravit.launchserver.manangers.LaunchServerGsonManager;
|
||||||
import pro.gravit.launchserver.manangers.ModulesManager;
|
import pro.gravit.launchserver.manangers.ModulesManager;
|
||||||
|
import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager;
|
||||||
import pro.gravit.launchserver.socket.WebSocketService;
|
import pro.gravit.launchserver.socket.WebSocketService;
|
||||||
import pro.gravit.utils.command.CommandHandler;
|
import pro.gravit.utils.command.CommandHandler;
|
||||||
import pro.gravit.utils.command.JLineCommandHandler;
|
import pro.gravit.utils.command.JLineCommandHandler;
|
||||||
|
@ -55,10 +57,11 @@ public static void main(String[] args) throws Exception {
|
||||||
LaunchServerRuntimeConfig runtimeConfig;
|
LaunchServerRuntimeConfig runtimeConfig;
|
||||||
LaunchServerConfig config;
|
LaunchServerConfig config;
|
||||||
LaunchServer.LaunchServerEnv env = LaunchServer.LaunchServerEnv.PRODUCTION;
|
LaunchServer.LaunchServerEnv env = LaunchServer.LaunchServerEnv.PRODUCTION;
|
||||||
ModulesManager modulesManager = new ModulesManager(dir.resolve("config"));
|
LaunchServerModulesManager modulesManager = new LaunchServerModulesManager(dir.resolve("modules"), dir.resolve("config"));
|
||||||
modulesManager.autoload(dir.resolve("modules"));
|
modulesManager.autoload();
|
||||||
|
modulesManager.initModules(null);
|
||||||
registerAll();
|
registerAll();
|
||||||
initGson();
|
initGson(modulesManager);
|
||||||
if (IOHelper.exists(dir.resolve("LaunchServer.conf"))) {
|
if (IOHelper.exists(dir.resolve("LaunchServer.conf"))) {
|
||||||
configFile = dir.resolve("LaunchServer.conf");
|
configFile = dir.resolve("LaunchServer.conf");
|
||||||
} else {
|
} else {
|
||||||
|
@ -107,6 +110,7 @@ public static void main(String[] args) throws Exception {
|
||||||
runtimeConfig = Launcher.gsonManager.gson.fromJson(reader, LaunchServerRuntimeConfig.class);
|
runtimeConfig = Launcher.gsonManager.gson.fromJson(reader, LaunchServerRuntimeConfig.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
modulesManager.invokeEvent(new PreConfigPhase());
|
||||||
generateConfigIfNotExists(configFile, localCommandHandler, env);
|
generateConfigIfNotExists(configFile, localCommandHandler, env);
|
||||||
LogHelper.info("Reading LaunchServer config file");
|
LogHelper.info("Reading LaunchServer config file");
|
||||||
try (BufferedReader reader = IOHelper.newReader(configFile)) {
|
try (BufferedReader reader = IOHelper.newReader(configFile)) {
|
||||||
|
@ -169,8 +173,8 @@ public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOExcept
|
||||||
server.run();
|
server.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initGson() {
|
public static void initGson(LaunchServerModulesManager modulesManager) {
|
||||||
Launcher.gsonManager = new LaunchServerGsonManager();
|
Launcher.gsonManager = new LaunchServerGsonManager(modulesManager);
|
||||||
Launcher.gsonManager.initGson();
|
Launcher.gsonManager.initGson();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package pro.gravit.launchserver.command.modules;
|
package pro.gravit.launchserver.command.modules;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
@ -24,7 +25,7 @@ public String getUsageDescription() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args, 1);
|
verifyArgs(args, 1);
|
||||||
URI uri = Paths.get(args[0]).toUri();
|
Path file = Paths.get(args[0]);
|
||||||
server.modulesManager.loadModule(uri.toURL());
|
server.modulesManager.loadModule(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,6 @@ public String getUsageDescription() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) {
|
public void invoke(String... args) {
|
||||||
server.modulesManager.printModules();
|
server.modulesManager.printModulesInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
import pro.gravit.launcher.hwid.HWID;
|
import pro.gravit.launcher.hwid.HWID;
|
||||||
import pro.gravit.launcher.hwid.HWIDProvider;
|
import pro.gravit.launcher.hwid.HWIDProvider;
|
||||||
import pro.gravit.launcher.managers.GsonManager;
|
import pro.gravit.launcher.managers.GsonManager;
|
||||||
|
import pro.gravit.launcher.modules.events.PreGsonPhase;
|
||||||
import pro.gravit.launcher.request.JsonResultSerializeAdapter;
|
import pro.gravit.launcher.request.JsonResultSerializeAdapter;
|
||||||
import pro.gravit.launcher.request.WebSocketEvent;
|
import pro.gravit.launcher.request.WebSocketEvent;
|
||||||
import pro.gravit.launchserver.auth.handler.AuthHandler;
|
import pro.gravit.launchserver.auth.handler.AuthHandler;
|
||||||
|
@ -15,11 +16,18 @@
|
||||||
import pro.gravit.launchserver.auth.texture.TextureProvider;
|
import pro.gravit.launchserver.auth.texture.TextureProvider;
|
||||||
import pro.gravit.launchserver.components.Component;
|
import pro.gravit.launchserver.components.Component;
|
||||||
import pro.gravit.launchserver.dao.provider.DaoProvider;
|
import pro.gravit.launchserver.dao.provider.DaoProvider;
|
||||||
|
import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager;
|
||||||
import pro.gravit.launchserver.socket.WebSocketService;
|
import pro.gravit.launchserver.socket.WebSocketService;
|
||||||
import pro.gravit.launchserver.socket.response.WebSocketServerResponse;
|
import pro.gravit.launchserver.socket.response.WebSocketServerResponse;
|
||||||
import pro.gravit.utils.UniversalJsonAdapter;
|
import pro.gravit.utils.UniversalJsonAdapter;
|
||||||
|
|
||||||
public class LaunchServerGsonManager extends GsonManager {
|
public class LaunchServerGsonManager extends GsonManager {
|
||||||
|
private final LaunchServerModulesManager modulesManager;
|
||||||
|
|
||||||
|
public LaunchServerGsonManager(LaunchServerModulesManager modulesManager) {
|
||||||
|
this.modulesManager = modulesManager;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerAdapters(GsonBuilder builder) {
|
public void registerAdapters(GsonBuilder builder) {
|
||||||
super.registerAdapters(builder);
|
super.registerAdapters(builder);
|
||||||
|
@ -34,6 +42,7 @@ public void registerAdapters(GsonBuilder builder) {
|
||||||
builder.registerTypeAdapter(HWID.class, new UniversalJsonAdapter<>(HWIDProvider.hwids));
|
builder.registerTypeAdapter(HWID.class, new UniversalJsonAdapter<>(HWIDProvider.hwids));
|
||||||
builder.registerTypeAdapter(WebSocketServerResponse.class, new UniversalJsonAdapter<>(WebSocketService.providers));
|
builder.registerTypeAdapter(WebSocketServerResponse.class, new UniversalJsonAdapter<>(WebSocketService.providers));
|
||||||
builder.registerTypeAdapter(WebSocketEvent.class, new JsonResultSerializeAdapter());
|
builder.registerTypeAdapter(WebSocketEvent.class, new JsonResultSerializeAdapter());
|
||||||
|
modulesManager.invokeEvent(new PreGsonPhase(builder));
|
||||||
//ClientWebSocketService.appendTypeAdapters(builder);
|
//ClientWebSocketService.appendTypeAdapters(builder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public Type getType() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModulesManager getModulesManager() {
|
public ModulesManager getModulesManager() {
|
||||||
return launchServer.modulesManager;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package pro.gravit.launchserver.modules.events;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.modules.LauncherModule;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
|
||||||
|
public class LaunchServerFullInitEvent extends LauncherModule.Event {
|
||||||
|
public final LaunchServer server;
|
||||||
|
|
||||||
|
public LaunchServerFullInitEvent(LaunchServer server) {
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package pro.gravit.launchserver.modules.events;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.modules.events.InitPhase;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
|
||||||
|
public class LaunchServerInitPhase extends InitPhase {
|
||||||
|
public final LaunchServer server;
|
||||||
|
|
||||||
|
public LaunchServerInitPhase(LaunchServer server) {
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package pro.gravit.launchserver.modules.events;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.modules.events.InitPhase;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
|
||||||
|
public class LaunchServerPostInitPhase extends InitPhase {
|
||||||
|
public final LaunchServer server;
|
||||||
|
|
||||||
|
public LaunchServerPostInitPhase(LaunchServer server) {
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package pro.gravit.launchserver.modules.events;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.modules.LauncherModule;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
|
||||||
|
public class NewLaunchServerInstanceEvent extends LauncherModule.Event {
|
||||||
|
public final LaunchServer launchServer;
|
||||||
|
|
||||||
|
public NewLaunchServerInstanceEvent(LaunchServer launchServer) {
|
||||||
|
this.launchServer = launchServer;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package pro.gravit.launchserver.modules.impl;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.modules.LauncherInitContext;
|
||||||
|
import pro.gravit.launcher.modules.LauncherModule;
|
||||||
|
import pro.gravit.launcher.modules.LauncherModuleInfo;
|
||||||
|
import pro.gravit.launchserver.modules.events.LaunchServerInitPhase;
|
||||||
|
import pro.gravit.utils.Version;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
public class LaunchServerCoreModule extends LauncherModule {
|
||||||
|
public LaunchServerCoreModule() {
|
||||||
|
super(new LauncherModuleInfo("LaunchServerCore", Version.getVersion()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(LauncherInitContext initContext) {
|
||||||
|
registerEvent(this::testEvent, LaunchServerInitPhase.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testEvent(LaunchServerInitPhase event)
|
||||||
|
{
|
||||||
|
LogHelper.debug("[LaunchServerCore] Event LaunchServerInitPhase passed");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package pro.gravit.launchserver.modules.impl;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.modules.LauncherInitContext;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
|
||||||
|
public class LaunchServerInitContext implements LauncherInitContext {
|
||||||
|
public final LaunchServer server;
|
||||||
|
|
||||||
|
public LaunchServerInitContext(LaunchServer server) {
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package pro.gravit.launchserver.modules.impl;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.modules.LauncherModule;
|
||||||
|
import pro.gravit.launcher.modules.LauncherModuleInfo;
|
||||||
|
import pro.gravit.launcher.modules.impl.SimpleModuleManager;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class LaunchServerModulesManager extends SimpleModuleManager {
|
||||||
|
public LaunchServerCoreModule coreModule;
|
||||||
|
public LaunchServerModulesManager(Path modulesDir, Path configDir) {
|
||||||
|
super(modulesDir, configDir);
|
||||||
|
coreModule = new LaunchServerCoreModule();
|
||||||
|
modules.add(coreModule);
|
||||||
|
}
|
||||||
|
public void fullInitializedLaunchServer(LaunchServer server)
|
||||||
|
{
|
||||||
|
initContext = new LaunchServerInitContext(server);
|
||||||
|
}
|
||||||
|
public void printModulesInfo()
|
||||||
|
{
|
||||||
|
for(LauncherModule module : modules)
|
||||||
|
{
|
||||||
|
LauncherModuleInfo info = module.getModuleInfo();
|
||||||
|
LogHelper.info("[MODULE] %s v: %s p: %d deps: %s", info.name, info.version.getVersionString(), info.priority, Arrays.toString(info.dependencies));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LauncherModule getCoreModule() {
|
||||||
|
return coreModule;
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,10 @@ protected LauncherModule() {
|
||||||
moduleInfo = new LauncherModuleInfo("UnknownModule");
|
moduleInfo = new LauncherModuleInfo("UnknownModule");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected LauncherModule(LauncherModuleInfo info) {
|
||||||
|
moduleInfo = info;
|
||||||
|
}
|
||||||
|
|
||||||
public LauncherModuleInfo getModuleInfo() {
|
public LauncherModuleInfo getModuleInfo() {
|
||||||
return moduleInfo;
|
return moduleInfo;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +33,7 @@ public enum InitPhase
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface EventHandler<T extends Event>
|
public interface EventHandler<T extends Event>
|
||||||
{
|
{
|
||||||
void event(T e) throws Exception;
|
void event(T e);
|
||||||
}
|
}
|
||||||
public static class Event
|
public static class Event
|
||||||
{
|
{
|
||||||
|
@ -76,7 +80,7 @@ protected <T extends Event> boolean registerEvent(EventHandler<T> handle, Class<
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public final <T extends Event> void callEvent(T event) throws Exception
|
public final <T extends Event> void callEvent(T event)
|
||||||
{
|
{
|
||||||
Class<? extends Event> tClass = event.getClass();
|
Class<? extends Event> tClass = event.getClass();
|
||||||
for(Map.Entry<Class<? extends Event>, EventHandler> e : eventMap.entrySet())
|
for(Map.Entry<Class<? extends Event>, EventHandler> e : eventMap.entrySet())
|
||||||
|
|
|
@ -23,5 +23,5 @@ default <T extends LauncherModule> boolean containsModule(Class<? extends T> cl
|
||||||
ClassLoader getModuleClassLoader();
|
ClassLoader getModuleClassLoader();
|
||||||
<T extends LauncherModule> T getModule(Class<? extends T> clazz);
|
<T extends LauncherModule> T getModule(Class<? extends T> clazz);
|
||||||
<T extends LauncherModule> T findModule(Class<? extends T> clazz, Predicate<Version> versionPredicate);
|
<T extends LauncherModule> T findModule(Class<? extends T> clazz, Predicate<Version> versionPredicate);
|
||||||
<T extends LauncherModule.Event> void invokeEvent(T event) throws Exception;
|
<T extends LauncherModule.Event> void invokeEvent(T event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package pro.gravit.launcher.modules.events;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.modules.LauncherModule;
|
||||||
|
|
||||||
|
public class ClosePhase extends LauncherModule.Event {
|
||||||
|
}
|
|
@ -5,10 +5,8 @@
|
||||||
|
|
||||||
public class PreGsonPhase extends LauncherModule.Event {
|
public class PreGsonPhase extends LauncherModule.Event {
|
||||||
public GsonBuilder gsonBuilder;
|
public GsonBuilder gsonBuilder;
|
||||||
public GsonBuilder gsonConfigBuilder;
|
|
||||||
|
|
||||||
public PreGsonPhase(GsonBuilder gsonBuilder, GsonBuilder gsonConfigBuilder) {
|
public PreGsonPhase(GsonBuilder gsonBuilder) {
|
||||||
this.gsonBuilder = gsonBuilder;
|
this.gsonBuilder = gsonBuilder;
|
||||||
this.gsonConfigBuilder = gsonConfigBuilder;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ public <T extends LauncherModule> T findModule(Class<? extends T> clazz, Predica
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends LauncherModule.Event> void invokeEvent(T event) throws Exception {
|
public <T extends LauncherModule.Event> void invokeEvent(T event) {
|
||||||
for(LauncherModule module : modules)
|
for(LauncherModule module : modules)
|
||||||
{
|
{
|
||||||
module.callEvent(event);
|
module.callEvent(event);
|
||||||
|
|
Loading…
Reference in a new issue