mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Компоненты добавлены в конфигурацию
This commit is contained in:
parent
e95557c6fd
commit
3eabd1e38e
3 changed files with 40 additions and 7 deletions
|
@ -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<String, Component> 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)
|
||||
|
|
|
@ -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<String, Class<? extends Component>> COMPONENTS = new ConcurrentHashMap<>(4);
|
||||
private static boolean registredComp = false;
|
||||
|
||||
public static void registerHandler(String name, Class<? extends Component> adapter) {
|
||||
public static void registerComponent(String name, Class<? extends Component> 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<? extends Component> getHandlerClass(String name) {
|
||||
public static Class<? extends Component> getComponentClass(String name) {
|
||||
return COMPONENTS.get(name);
|
||||
}
|
||||
|
||||
public static String getHandlerName(Class<Component> clazz) {
|
||||
public static String getComponentName(Class<Component> clazz) {
|
||||
for (Map.Entry<String, Class<? extends Component>> 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);
|
||||
}
|
||||
|
|
|
@ -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<Component>, JsonDeserial
|
|||
@Override
|
||||
public Component deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||||
Class<? extends Component> cls = Component.getHandlerClass(typename);
|
||||
Class<? extends Component> 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<Component>) src.getClass());
|
||||
String classPath = Component.getComponentName((Class<Component>) src.getClass());
|
||||
jo.add(PROP_NAME, new JsonPrimitive(classPath));
|
||||
|
||||
return jo;
|
||||
|
|
Loading…
Reference in a new issue