diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 2e65c755..9ae79bd7 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -33,6 +33,7 @@ import ru.gravit.launchserver.texture.RequestTextureProvider; import ru.gravit.launchserver.texture.TextureProvider; import ru.gravit.utils.helper.*; +import sun.nio.cs.ext.COMPOUND_TEXT; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -97,6 +98,8 @@ public static final class Config { public HWIDHandler hwidHandler; + public HashMap components; + // Misc options public int threadCount; @@ -448,6 +451,15 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE provider.init(); } config.authHandler.init(); + if(config.components != null) + { + LogHelper.debug("PreInit components"); + config.components.forEach((k,v) -> { + LogHelper.subDebug("PreInit component %s", k); + v.preInit(this); + }); + LogHelper.debug("PreInit components successful"); + } // build hooks, anti-brutforce and other buildHookManager = new BuildHookManager(); @@ -492,6 +504,15 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE // init modules modulesManager.initModules(); + if(config.components != null) + { + LogHelper.debug("Init components"); + config.components.forEach((k,v) -> { + LogHelper.subDebug("Init component %s", k); + v.init(this); + }); + LogHelper.debug("Init components successful"); + } // Set launcher EXE binary launcherBinary = new JARLauncherBinary(this); @@ -517,6 +538,15 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE // post init modules modulesManager.postInitModules(); + if(config.components != null) + { + LogHelper.debug("PostInit components"); + config.components.forEach((k,v) -> { + LogHelper.subDebug("PostInit component %s", k); + v.postInit(this); + }); + LogHelper.debug("PostInit components successful"); + } // start updater this.updater = new Updater(this); if(config.netty != null) 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 a29aa529..c74704cb 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java @@ -1,26 +1,27 @@ package ru.gravit.launchserver.components; +import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.VerifyHelper; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -public class Component { +public abstract class Component { private static final Map> COMPONENTS = new ConcurrentHashMap<>(4); private static boolean registredComp = false; - public static void registerHandler(String name, Class adapter) { + public static void registerComponent(String name, Class adapter) { VerifyHelper.verifyIDName(name); VerifyHelper.putIfAbsent(COMPONENTS, name, Objects.requireNonNull(adapter, "adapter"), String.format("Auth handler has been already registered: '%s'", name)); } - public static Class getHandlerClass(String name) { + public static Class getComponentClass(String name) { return COMPONENTS.get(name); } - public static String getHandlerName(Class clazz) { + public static String getComponentName(Class clazz) { for (Map.Entry> e : COMPONENTS.entrySet()) { if (e.getValue().equals(clazz)) return e.getKey(); } @@ -32,4 +33,7 @@ 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/ComponentAdapter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/config/ComponentAdapter.java index f33d44ad..65c8f7da 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/config/ComponentAdapter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/config/ComponentAdapter.java @@ -1,7 +1,6 @@ package ru.gravit.launchserver.config; import com.google.gson.*; -import ru.gravit.launchserver.auth.handler.AuthHandler; import ru.gravit.launchserver.components.Component; import ru.gravit.utils.helper.LogHelper; @@ -13,7 +12,7 @@ public class ComponentAdapter implements JsonSerializer, JsonDeserial @Override public Component deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); - Class cls = Component.getHandlerClass(typename); + Class cls = Component.getComponentClass(typename); if(cls == null) { LogHelper.error("Component %s not found", typename); @@ -29,7 +28,7 @@ public JsonElement serialize(Component src, Type typeOfSrc, JsonSerializationCon JsonObject jo = context.serialize(src).getAsJsonObject(); @SuppressWarnings("unchecked") - String classPath = Component.getHandlerName((Class) src.getClass()); + String classPath = Component.getComponentName((Class) src.getClass()); jo.add(PROP_NAME, new JsonPrimitive(classPath)); return jo;