From bb27559314b9d6c32b55f0bf1799bea74c05053f Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 27 Apr 2019 17:05:49 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B9=20Pro?= =?UTF-8?q?viderMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launchserver/LaunchServer.java | 28 +++++++++++++++---- .../auth/handler/AuthHandler.java | 10 +++---- .../launchserver/auth/hwid/HWIDHandler.java | 8 +++--- .../auth/permissions/PermissionsHandler.java | 8 +++--- .../auth/protect/ProtectHandler.java | 2 +- .../auth/provider/AuthProvider.java | 12 ++++---- .../auth/texture/TextureProvider.java | 6 ++-- .../launchserver/components/Component.java | 4 +-- .../launcher/client/FunctionalBridge.java | 3 +- .../java/ru/gravit/utils/ProviderMap.java | 8 +++--- .../ru/gravit/utils/UniversalJsonAdapter.java | 4 +-- 11 files changed, 54 insertions(+), 39 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index b50b7403..da0a419e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -64,12 +64,7 @@ public void reload() throws Exception { config = Launcher.gsonManager.gson.fromJson(reader, Config.class); } config.verify(); - Launcher.applyLauncherEnv(config.env); - for (AuthProviderPair auth : config.auth) { - auth.init(); - } - config.permissionsHandler.init(); - config.hwidHandler.init(); + config.init(); } public static final class Config { @@ -201,6 +196,27 @@ public void verify() { throw new NullPointerException("Netty must not be null"); } } + public void init() + { + Launcher.applyLauncherEnv(env); + for (AuthProviderPair provider : auth) { + provider.init(); + } + permissionsHandler.init(); + hwidHandler.init(); + if (protectHandler != null) { + protectHandler.checkLaunchServerLicense(); + } + LaunchServer.server.registerObject("permissionsHandler", permissionsHandler); + for (int i = 0; i < auth.length; ++i) { + AuthProviderPair pair = auth[i]; + LaunchServer.server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider); + LaunchServer.server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler); + LaunchServer.server.registerObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider); + } + + Arrays.stream(mirrors).forEach(LaunchServer.server.mirrorManager::addMirror); + } public void close() { try { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java index a0ca3588..8c49e93a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java @@ -18,11 +18,11 @@ public static UUID authError(String message) throws AuthException { public static void registerHandlers() { if (!registredHandl) { - providers.registerProvider("null", NullAuthHandler.class); - providers.registerProvider("json", JsonAuthHandler.class); - providers.registerProvider("memory", MemoryAuthHandler.class); - providers.registerProvider("mysql", MySQLAuthHandler.class); - providers.registerProvider("request", RequestAuthHandler.class); + providers.register("null", NullAuthHandler.class); + providers.register("json", JsonAuthHandler.class); + providers.register("memory", MemoryAuthHandler.class); + providers.register("mysql", MySQLAuthHandler.class); + providers.register("request", RequestAuthHandler.class); registredHandl = true; } } 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 6aad2f97..3d2ff998 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 @@ -12,10 +12,10 @@ public abstract class HWIDHandler implements AutoCloseable { public static void registerHandlers() { if (!registredHandl) { - providers.registerProvider("accept", AcceptHWIDHandler.class); - providers.registerProvider("mysql", MysqlHWIDHandler.class); - providers.registerProvider("json", JsonHWIDHandler.class); - providers.registerProvider("memory", MemoryHWIDHandler.class); + providers.register("accept", AcceptHWIDHandler.class); + providers.register("mysql", MysqlHWIDHandler.class); + providers.register("json", JsonHWIDHandler.class); + providers.register("memory", MemoryHWIDHandler.class); registredHandl = true; } } 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 5b8c98d1..9124bf25 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 @@ -9,10 +9,10 @@ public abstract class PermissionsHandler implements AutoCloseable { public static void registerHandlers() { if (!registredHandl) { - providers.registerProvider("json", JsonFilePermissionsHandler.class); - providers.registerProvider("json-long", JsonLongFilePermissionsHandler.class); - providers.registerProvider("config", ConfigPermissionsHandler.class); - providers.registerProvider("default", DefaultPermissionsHandler.class); + providers.register("json", JsonFilePermissionsHandler.class); + providers.register("json-long", JsonLongFilePermissionsHandler.class); + providers.register("config", ConfigPermissionsHandler.class); + providers.register("default", DefaultPermissionsHandler.class); registredHandl = true; } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/protect/ProtectHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/protect/ProtectHandler.java index f9b8151a..61759f2f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/protect/ProtectHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/protect/ProtectHandler.java @@ -11,7 +11,7 @@ public abstract class ProtectHandler { public static void registerHandlers() { if (!registredHandl) { - providers.registerProvider("none", NoProtectHandler.class); + providers.register("none", NoProtectHandler.class); registredHandl = true; } } 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 6e7b7fcd..1901c186 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 @@ -15,12 +15,12 @@ public static AuthProviderResult authError(String message) throws AuthException public static void registerProviders() { if (!registredProv) { - providers.registerProvider("null", NullAuthProvider.class); - providers.registerProvider("accept", AcceptAuthProvider.class); - providers.registerProvider("reject", RejectAuthProvider.class); - providers.registerProvider("mysql", MySQLAuthProvider.class); - providers.registerProvider("request", RequestAuthProvider.class); - providers.registerProvider("json", JsonAuthProvider.class); + providers.register("null", NullAuthProvider.class); + providers.register("accept", AcceptAuthProvider.class); + providers.register("reject", RejectAuthProvider.class); + providers.register("mysql", MySQLAuthProvider.class); + providers.register("request", RequestAuthProvider.class); + providers.register("json", JsonAuthProvider.class); registredProv = true; } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/texture/TextureProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/texture/TextureProvider.java index e334ef73..04191b9b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/texture/TextureProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/texture/TextureProvider.java @@ -12,11 +12,11 @@ public abstract class TextureProvider implements AutoCloseable { public static void registerProviders() { if (!registredProv) { - providers.registerProvider("null", NullTextureProvider.class); - providers.registerProvider("void", VoidTextureProvider.class); + providers.register("null", NullTextureProvider.class); + providers.register("void", VoidTextureProvider.class); // Auth providers that doesn't do nothing :D - providers.registerProvider("request", RequestTextureProvider.class); + providers.register("request", RequestTextureProvider.class); registredProv = true; } } 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 6c194cb2..a10b6cb4 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java @@ -9,8 +9,8 @@ public abstract class Component { public static void registerComponents() { if (!registredComp) { - providers.registerProvider("authLimiter", AuthLimiterComponent.class); - providers.registerProvider("commandRemover", CommandRemoverComponent.class); + providers.register("authLimiter", AuthLimiterComponent.class); + providers.register("commandRemover", CommandRemoverComponent.class); registredComp = true; } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java index 571dab73..6639966d 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java @@ -13,7 +13,6 @@ import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.websockets.RequestInterface; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; -import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.LogHelper; import java.nio.file.Path; @@ -86,7 +85,7 @@ public static HasherStore getDefaultHasherStore() { @LauncherAPI public static void registerUserSettings(String typename, Class clazz) { - UserSettings.providers.registerProvider(typename, clazz); + UserSettings.providers.register(typename, clazz); } @LauncherAPI public static void close() throws Exception diff --git a/libLauncher/src/main/java/ru/gravit/utils/ProviderMap.java b/libLauncher/src/main/java/ru/gravit/utils/ProviderMap.java index f2c2aa1e..4d806dab 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/ProviderMap.java +++ b/libLauncher/src/main/java/ru/gravit/utils/ProviderMap.java @@ -23,23 +23,23 @@ public String getName() return name; } - public void registerProvider(String name, Class adapter) { + public void register(String name, Class adapter) { VerifyHelper.verifyIDName(name); VerifyHelper.putIfAbsent(PROVIDERS, name, Objects.requireNonNull(adapter, "adapter"), String.format("%s has been already registered: '%s'", this.name, name)); } - public Class getProviderClass(String name) { + public Class getClass(String name) { return PROVIDERS.get(name); } - public String getProviderName(Class clazz) { + public String getName(Class clazz) { for (Map.Entry> e : PROVIDERS.entrySet()) { if (e.getValue().equals(clazz)) return e.getKey(); } return null; } - public Class unregisterProvider(String name) + public Class unregister(String name) { return PROVIDERS.remove(name); } diff --git a/libLauncher/src/main/java/ru/gravit/utils/UniversalJsonAdapter.java b/libLauncher/src/main/java/ru/gravit/utils/UniversalJsonAdapter.java index f3a1003d..c375d4d3 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/UniversalJsonAdapter.java +++ b/libLauncher/src/main/java/ru/gravit/utils/UniversalJsonAdapter.java @@ -24,7 +24,7 @@ public UniversalJsonAdapter(ProviderMap providerMap, String PROP_NAME) { public R deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); - Class cls = providerMap.getProviderClass(typename); + Class cls = providerMap.getClass(typename); if (cls == null) { LogHelper.error("%s %s not found", name, typename); return null; @@ -37,7 +37,7 @@ public JsonElement serialize(R src, Type typeOfSrc, JsonSerializationContext con JsonObject jo = context.serialize(src).getAsJsonObject(); @SuppressWarnings("unchecked") - String classPath = providerMap.getProviderName((Class) src.getClass()); + String classPath = providerMap.getName((Class) src.getClass()); jo.add(PROP_NAME, new JsonPrimitive(classPath)); return jo;