diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 6faec029..19b7b01d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -11,6 +11,7 @@ import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest; import pro.gravit.launchserver.auth.core.AuthCoreProvider; +import pro.gravit.launchserver.auth.mix.MixProvider; import pro.gravit.launchserver.auth.password.PasswordVerifier; import pro.gravit.launchserver.auth.protect.ProtectHandler; import pro.gravit.launchserver.auth.texture.TextureProvider; @@ -212,6 +213,7 @@ public static void registerAll() { GetAvailabilityAuthRequest.registerProviders(); OptionalAction.registerProviders(); OptionalTrigger.registerProviders(); + MixProvider.registerProviders(); } private static void printExperimentalBranch() { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java index 4a52a8d8..ba47063a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -4,6 +4,7 @@ import org.apache.logging.log4j.Logger; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.core.AuthCoreProvider; +import pro.gravit.launchserver.auth.mix.MixProvider; import pro.gravit.launchserver.auth.texture.TextureProvider; import java.io.IOException; @@ -16,6 +17,7 @@ public final class AuthProviderPair { public boolean isDefault = true; public AuthCoreProvider core; public TextureProvider textureProvider; + public Map mixes; public Map links; public transient String name; public transient Set features; @@ -55,8 +57,15 @@ public static void getFeatures(Class clazz, Set list) { public final T isSupport(Class clazz) { if (core == null) return null; - T result = null; - if (result == null) result = core.isSupport(clazz); + T result = core.isSupport(clazz); + if (result == null && mixes != null) { + for(var m : mixes.values()) { + result = m.isSupport(clazz); + if(result != null) { + break; + } + } + } return result; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/mix/MixProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/mix/MixProvider.java new file mode 100644 index 00000000..cb74a8f4 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/mix/MixProvider.java @@ -0,0 +1,23 @@ +package pro.gravit.launchserver.auth.mix; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import pro.gravit.utils.ProviderMap; + +public class MixProvider { + public static final ProviderMap providers = new ProviderMap<>("MixProvider"); + private static final Logger logger = LogManager.getLogger(); + private static boolean registredProviders = false; + + public static void registerProviders() { + if (!registredProviders) { + registredProviders = true; + } + } + + @SuppressWarnings("unchecked") + public T isSupport(Class clazz) { + if (clazz.isAssignableFrom(getClass())) return (T) this; + return null; + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java index 106abb2d..8b5e3c14 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java @@ -13,6 +13,7 @@ import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest; import pro.gravit.launchserver.auth.core.AuthCoreProvider; +import pro.gravit.launchserver.auth.mix.MixProvider; import pro.gravit.launchserver.auth.password.PasswordVerifier; import pro.gravit.launchserver.auth.protect.ProtectHandler; import pro.gravit.launchserver.auth.texture.TextureProvider; @@ -48,6 +49,7 @@ public void registerAdapters(GsonBuilder builder) { builder.registerTypeAdapter(GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails.class, new UniversalJsonAdapter<>(GetAvailabilityAuthRequest.providers)); builder.registerTypeAdapter(OptionalAction.class, new UniversalJsonAdapter<>(OptionalAction.providers)); builder.registerTypeAdapter(OptionalTrigger.class, new UniversalJsonAdapter<>(OptionalTrigger.providers)); + builder.registerTypeAdapter(MixProvider.class, new UniversalJsonAdapter<>(MixProvider.providers)); modulesManager.invokeEvent(new PreGsonPhase(builder)); //ClientWebSocketService.appendTypeAdapters(builder); }