mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] Универсальный адаптер заменил собой шаблонный код
This commit is contained in:
parent
2ef2d95fb9
commit
019d864130
13 changed files with 54 additions and 336 deletions
|
@ -36,6 +36,7 @@
|
|||
import ru.gravit.launchserver.socket.ServerSocketHandler;
|
||||
import ru.gravit.launchserver.auth.texture.RequestTextureProvider;
|
||||
import ru.gravit.launchserver.auth.texture.TextureProvider;
|
||||
import ru.gravit.utils.UniversalJsonAdapter;
|
||||
import ru.gravit.utils.command.CommandHandler;
|
||||
import ru.gravit.utils.command.JLineCommandHandler;
|
||||
import ru.gravit.utils.command.StdCommandHandler;
|
||||
|
@ -598,25 +599,25 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException
|
|||
public static void initGson() {
|
||||
if (Launcher.gson != null) return;
|
||||
Launcher.gsonBuilder = new GsonBuilder();
|
||||
Launcher.gsonBuilder.registerTypeAdapter(AuthProvider.class, new AuthProviderAdapter());
|
||||
Launcher.gsonBuilder.registerTypeAdapter(TextureProvider.class, new TextureProviderAdapter());
|
||||
Launcher.gsonBuilder.registerTypeAdapter(AuthHandler.class, new AuthHandlerAdapter());
|
||||
Launcher.gsonBuilder.registerTypeAdapter(PermissionsHandler.class, new PermissionsHandlerAdapter());
|
||||
Launcher.gsonBuilder.registerTypeAdapter(HWIDHandler.class, new HWIDHandlerAdapter());
|
||||
Launcher.gsonBuilder.registerTypeAdapter(Component.class, new ComponentAdapter());
|
||||
Launcher.gsonBuilder.registerTypeAdapter(ProtectHandler.class, new ProtectHandlerAdapter());
|
||||
Launcher.gsonBuilder.registerTypeAdapter(AuthProvider.class, new UniversalJsonAdapter<>(AuthProvider.providers));
|
||||
Launcher.gsonBuilder.registerTypeAdapter(TextureProvider.class, new UniversalJsonAdapter<>(TextureProvider.providers));
|
||||
Launcher.gsonBuilder.registerTypeAdapter(AuthHandler.class, new UniversalJsonAdapter<>(AuthHandler.providers));
|
||||
Launcher.gsonBuilder.registerTypeAdapter(PermissionsHandler.class, new UniversalJsonAdapter<>(PermissionsHandler.providers));
|
||||
Launcher.gsonBuilder.registerTypeAdapter(HWIDHandler.class, new UniversalJsonAdapter<>(HWIDHandler.providers));
|
||||
Launcher.gsonBuilder.registerTypeAdapter(Component.class, new UniversalJsonAdapter<>(Component.providers));
|
||||
Launcher.gsonBuilder.registerTypeAdapter(ProtectHandler.class, new UniversalJsonAdapter<>(ProtectHandler.providers));
|
||||
Launcher.gson = Launcher.gsonBuilder.create();
|
||||
|
||||
//Human readable
|
||||
LaunchServer.gsonBuilder = new GsonBuilder();
|
||||
LaunchServer.gsonBuilder.setPrettyPrinting();
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(AuthProvider.class, new AuthProviderAdapter());
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(TextureProvider.class, new TextureProviderAdapter());
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(AuthHandler.class, new AuthHandlerAdapter());
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(PermissionsHandler.class, new PermissionsHandlerAdapter());
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(HWIDHandler.class, new HWIDHandlerAdapter());
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(Component.class, new ComponentAdapter());
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(ProtectHandler.class, new ProtectHandlerAdapter());
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(AuthProvider.class, new UniversalJsonAdapter<>(AuthProvider.providers));
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(TextureProvider.class, new UniversalJsonAdapter<>(TextureProvider.providers));
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(AuthHandler.class, new UniversalJsonAdapter<>(AuthHandler.providers));
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(PermissionsHandler.class, new UniversalJsonAdapter<>(PermissionsHandler.providers));
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(HWIDHandler.class, new UniversalJsonAdapter<>(HWIDHandler.providers));
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(Component.class, new UniversalJsonAdapter<>(Component.providers));
|
||||
LaunchServer.gsonBuilder.registerTypeAdapter(ProtectHandler.class, new UniversalJsonAdapter<>(ProtectHandler.providers));
|
||||
LaunchServer.gson = LaunchServer.gsonBuilder.create();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import ru.gravit.launchserver.auth.AuthException;
|
||||
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||
import ru.gravit.utils.ProviderMap;
|
||||
import ru.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -11,7 +12,7 @@
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class AuthHandler implements AutoCloseable {
|
||||
private static final Map<String, Class<? extends AuthHandler>> AUTH_HANDLERS = new ConcurrentHashMap<>(4);
|
||||
public static ProviderMap<AuthHandler> providers = new ProviderMap<>();
|
||||
private static boolean registredHandl = false;
|
||||
|
||||
|
||||
|
@ -19,31 +20,13 @@ public static UUID authError(String message) throws AuthException {
|
|||
throw new AuthException(message);
|
||||
}
|
||||
|
||||
|
||||
public static void registerHandler(String name, Class<? extends AuthHandler> adapter) {
|
||||
VerifyHelper.verifyIDName(name);
|
||||
VerifyHelper.putIfAbsent(AUTH_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"),
|
||||
String.format("Auth handler has been already registered: '%s'", name));
|
||||
}
|
||||
|
||||
public static Class<? extends AuthHandler> getHandlerClass(String name) {
|
||||
return AUTH_HANDLERS.get(name);
|
||||
}
|
||||
|
||||
public static String getHandlerName(Class<AuthHandler> clazz) {
|
||||
for (Map.Entry<String, Class<? extends AuthHandler>> e : AUTH_HANDLERS.entrySet()) {
|
||||
if (e.getValue().equals(clazz)) return e.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void registerHandlers() {
|
||||
if (!registredHandl) {
|
||||
registerHandler("null", NullAuthHandler.class);
|
||||
registerHandler("json", JsonAuthHandler.class);
|
||||
registerHandler("memory", MemoryAuthHandler.class);
|
||||
registerHandler("mysql", MySQLAuthHandler.class);
|
||||
registerHandler("request", RequestAuthHandler.class);
|
||||
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);
|
||||
registredHandl = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ru.gravit.launchserver.auth.hwid;
|
||||
|
||||
import ru.gravit.launcher.HWID;
|
||||
import ru.gravit.utils.ProviderMap;
|
||||
import ru.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -9,22 +10,16 @@
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class HWIDHandler implements AutoCloseable {
|
||||
private static final Map<String, Class<? extends HWIDHandler>> HW_HANDLERS = new ConcurrentHashMap<>(4);
|
||||
public static ProviderMap<HWIDHandler> providers = new ProviderMap<>();
|
||||
private static boolean registredHandl = false;
|
||||
|
||||
|
||||
public static void registerHandler(String name, Class<? extends HWIDHandler> adapter) {
|
||||
VerifyHelper.verifyIDName(name);
|
||||
VerifyHelper.putIfAbsent(HW_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"),
|
||||
String.format("HWID handler has been already registered: '%s'", name));
|
||||
}
|
||||
|
||||
public static void registerHandlers() {
|
||||
if (!registredHandl) {
|
||||
registerHandler("accept", AcceptHWIDHandler.class);
|
||||
registerHandler("mysql", MysqlHWIDHandler.class);
|
||||
registerHandler("json", JsonHWIDHandler.class);
|
||||
registerHandler("memory", MemoryHWIDHandler.class);
|
||||
providers.registerProvider("accept", AcceptHWIDHandler.class);
|
||||
providers.registerProvider("mysql", MysqlHWIDHandler.class);
|
||||
providers.registerProvider("json", JsonHWIDHandler.class);
|
||||
providers.registerProvider("memory", MemoryHWIDHandler.class);
|
||||
registredHandl = true;
|
||||
}
|
||||
}
|
||||
|
@ -46,15 +41,4 @@ public void check(HWID hwid, String username) throws HWIDException {
|
|||
public abstract List<HWID> getHwid(String username) throws HWIDException;
|
||||
|
||||
public abstract void unban(List<HWID> hwid) throws HWIDException;
|
||||
|
||||
public static Class<? extends HWIDHandler> getHandlerClass(String name) {
|
||||
return HW_HANDLERS.get(name);
|
||||
}
|
||||
|
||||
public static String getHandlerName(Class<? extends HWIDHandler> clazz) {
|
||||
for (Map.Entry<String, Class<? extends HWIDHandler>> e : HW_HANDLERS.entrySet()) {
|
||||
if (e.getValue().equals(clazz)) return e.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ru.gravit.launchserver.auth.permissions;
|
||||
|
||||
import ru.gravit.launcher.ClientPermissions;
|
||||
import ru.gravit.utils.ProviderMap;
|
||||
import ru.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -8,32 +9,15 @@
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class PermissionsHandler implements AutoCloseable {
|
||||
private static final Map<String, Class<? extends PermissionsHandler>> PERMISSIONS_HANDLERS = new ConcurrentHashMap<>(4);
|
||||
public static ProviderMap<PermissionsHandler> providers = new ProviderMap<>();
|
||||
private static boolean registredHandl = false;
|
||||
|
||||
public static void registerHandler(String name, Class<? extends PermissionsHandler> adapter) {
|
||||
VerifyHelper.verifyIDName(name);
|
||||
VerifyHelper.putIfAbsent(PERMISSIONS_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"),
|
||||
String.format("Auth handler has been already registered: '%s'", name));
|
||||
}
|
||||
|
||||
public static Class<? extends PermissionsHandler> getHandlerClass(String name) {
|
||||
return PERMISSIONS_HANDLERS.get(name);
|
||||
}
|
||||
|
||||
public static String getHandlerName(Class<? extends PermissionsHandler> clazz) {
|
||||
for (Map.Entry<String, Class<? extends PermissionsHandler>> e : PERMISSIONS_HANDLERS.entrySet()) {
|
||||
if (e.getValue().equals(clazz)) return e.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void registerHandlers() {
|
||||
if (!registredHandl) {
|
||||
registerHandler("json", JsonFilePermissionsHandler.class);
|
||||
registerHandler("json-long", JsonLongFilePermissionsHandler.class);
|
||||
registerHandler("config", ConfigPermissionsHandler.class);
|
||||
registerHandler("default", DefaultPermissionsHandler.class);
|
||||
providers.registerProvider("json", JsonFilePermissionsHandler.class);
|
||||
providers.registerProvider("json-long", JsonLongFilePermissionsHandler.class);
|
||||
providers.registerProvider("config", ConfigPermissionsHandler.class);
|
||||
providers.registerProvider("default", DefaultPermissionsHandler.class);
|
||||
registredHandl = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ru.gravit.launchserver.auth.protect;
|
||||
|
||||
import ru.gravit.launchserver.websocket.json.auth.AuthResponse;
|
||||
import ru.gravit.utils.ProviderMap;
|
||||
import ru.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -8,30 +9,14 @@
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class ProtectHandler {
|
||||
private static final Map<String, Class<? extends ProtectHandler>> PROTECT_HANDLERS = new ConcurrentHashMap<>(4);
|
||||
public static ProviderMap<ProtectHandler> providers = new ProviderMap<>();
|
||||
private static boolean registredHandl = false;
|
||||
|
||||
|
||||
public static void registerHandler(String name, Class<? extends ProtectHandler> adapter) {
|
||||
VerifyHelper.verifyIDName(name);
|
||||
VerifyHelper.putIfAbsent(PROTECT_HANDLERS, name, Objects.requireNonNull(adapter, "adapter"),
|
||||
String.format("Protect handler has been already registered: '%s'", name));
|
||||
}
|
||||
|
||||
public static Class<? extends ProtectHandler> getHandlerClass(String name) {
|
||||
return PROTECT_HANDLERS.get(name);
|
||||
}
|
||||
|
||||
public static String getHandlerName(Class<ProtectHandler> clazz) {
|
||||
for (Map.Entry<String, Class<? extends ProtectHandler>> e : PROTECT_HANDLERS.entrySet()) {
|
||||
if (e.getValue().equals(clazz)) return e.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void registerHandlers() {
|
||||
if (!registredHandl) {
|
||||
registerHandler("none", NoProtectHandler.class);
|
||||
providers.registerProvider("none", NoProtectHandler.class);
|
||||
registredHandl = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ru.gravit.launchserver.auth.provider;
|
||||
|
||||
import ru.gravit.launchserver.auth.AuthException;
|
||||
import ru.gravit.utils.ProviderMap;
|
||||
import ru.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -9,27 +10,21 @@
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class AuthProvider implements AutoCloseable {
|
||||
private static final Map<String, Class<? extends AuthProvider>> AUTH_PROVIDERS = new ConcurrentHashMap<>(8);
|
||||
public static ProviderMap<AuthProvider> providers = new ProviderMap<>();
|
||||
private static boolean registredProv = false;
|
||||
|
||||
public static AuthProviderResult authError(String message) throws AuthException {
|
||||
throw new AuthException(message);
|
||||
}
|
||||
|
||||
|
||||
public static void registerProvider(String name, Class<? extends AuthProvider> adapter) {
|
||||
VerifyHelper.putIfAbsent(AUTH_PROVIDERS, name, Objects.requireNonNull(adapter, "adapter"),
|
||||
String.format("Auth provider has been already registered: '%s'", name));
|
||||
}
|
||||
|
||||
public static void registerProviders() {
|
||||
if (!registredProv) {
|
||||
registerProvider("null", NullAuthProvider.class);
|
||||
registerProvider("accept", AcceptAuthProvider.class);
|
||||
registerProvider("reject", RejectAuthProvider.class);
|
||||
registerProvider("mysql", MySQLAuthProvider.class);
|
||||
registerProvider("request", RequestAuthProvider.class);
|
||||
registerProvider("json", JsonAuthProvider.class);
|
||||
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);
|
||||
registredProv = true;
|
||||
}
|
||||
}
|
||||
|
@ -44,17 +39,6 @@ public void preAuth(String login, String password, String customText, String ip)
|
|||
@Override
|
||||
public abstract void close() throws IOException;
|
||||
|
||||
public static Class<? extends AuthProvider> getProviderClass(String name) {
|
||||
return AUTH_PROVIDERS.get(name);
|
||||
}
|
||||
|
||||
public static String getProviderName(Class<? extends AuthProvider> clazz) {
|
||||
for (Map.Entry<String, Class<? extends AuthProvider>> e : AUTH_PROVIDERS.entrySet()) {
|
||||
if (e.getValue().equals(clazz)) return e.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ru.gravit.launchserver.auth.texture;
|
||||
|
||||
import ru.gravit.launcher.profiles.Texture;
|
||||
import ru.gravit.utils.ProviderMap;
|
||||
import ru.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -10,22 +11,16 @@
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class TextureProvider implements AutoCloseable {
|
||||
private static final Map<String, Class<? extends TextureProvider>> TEXTURE_PROVIDERS = new ConcurrentHashMap<>(2);
|
||||
public static ProviderMap<TextureProvider> providers = new ProviderMap<>();
|
||||
private static boolean registredProv = false;
|
||||
|
||||
|
||||
public static void registerProvider(String name, Class<? extends TextureProvider> adapter) {
|
||||
VerifyHelper.putIfAbsent(TEXTURE_PROVIDERS, name, Objects.requireNonNull(adapter, "adapter"),
|
||||
String.format("Texture provider has been already registered: '%s'", name));
|
||||
}
|
||||
|
||||
public static void registerProviders() {
|
||||
if (!registredProv) {
|
||||
registerProvider("null", NullTextureProvider.class);
|
||||
registerProvider("void", VoidTextureProvider.class);
|
||||
providers.registerProvider("null", NullTextureProvider.class);
|
||||
providers.registerProvider("void", VoidTextureProvider.class);
|
||||
|
||||
// Auth providers that doesn't do nothing :D
|
||||
registerProvider("request", RequestTextureProvider.class);
|
||||
providers.registerProvider("request", RequestTextureProvider.class);
|
||||
registredProv = true;
|
||||
}
|
||||
}
|
||||
|
@ -38,15 +33,4 @@ public static void registerProviders() {
|
|||
|
||||
|
||||
public abstract Texture getSkinTexture(UUID uuid, String username, String client) throws IOException;
|
||||
|
||||
public static Class<? extends TextureProvider> getProviderClass(String name) {
|
||||
return TEXTURE_PROVIDERS.get(name);
|
||||
}
|
||||
|
||||
public static String getProviderName(Class<? extends TextureProvider> clazz) {
|
||||
for (Map.Entry<String, Class<? extends TextureProvider>> e : TEXTURE_PROVIDERS.entrySet()) {
|
||||
if (e.getValue().equals(clazz)) return e.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ru.gravit.launchserver.components;
|
||||
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.utils.ProviderMap;
|
||||
import ru.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -8,30 +9,13 @@
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class Component {
|
||||
private static final Map<String, Class<? extends Component>> COMPONENTS = new ConcurrentHashMap<>(4);
|
||||
public static ProviderMap<Component> providers = new ProviderMap<>();
|
||||
private static boolean registredComp = false;
|
||||
|
||||
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> getComponentClass(String name) {
|
||||
return COMPONENTS.get(name);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void registerComponents() {
|
||||
if (!registredComp) {
|
||||
registerComponent("authLimiter", AuthLimiterComponent.class);
|
||||
registerComponent("commandRemover", CommandRemoverComponent.class);
|
||||
providers.registerProvider("authLimiter", AuthLimiterComponent.class);
|
||||
providers.registerProvider("commandRemover", CommandRemoverComponent.class);
|
||||
registredComp = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package ru.gravit.launchserver.config.adapter;
|
||||
|
||||
import com.google.gson.*;
|
||||
import ru.gravit.launchserver.auth.handler.AuthHandler;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class AuthHandlerAdapter implements JsonSerializer<AuthHandler>, JsonDeserializer<AuthHandler> {
|
||||
private static final String PROP_NAME = "type";
|
||||
|
||||
@Override
|
||||
public AuthHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||||
Class<? extends AuthHandler> cls = AuthHandler.getHandlerClass(typename);
|
||||
if (cls == null) {
|
||||
LogHelper.error("AuthHandler %s not found", typename);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return (AuthHandler) context.deserialize(json, cls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(AuthHandler src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject jo = context.serialize(src).getAsJsonObject();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
String classPath = AuthHandler.getHandlerName((Class<AuthHandler>) src.getClass());
|
||||
jo.add(PROP_NAME, new JsonPrimitive(classPath));
|
||||
|
||||
return jo;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package ru.gravit.launchserver.config.adapter;
|
||||
|
||||
import com.google.gson.*;
|
||||
import ru.gravit.launchserver.auth.provider.AuthProvider;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class AuthProviderAdapter implements JsonSerializer<AuthProvider>, JsonDeserializer<AuthProvider> {
|
||||
private static final String PROP_NAME = "type";
|
||||
|
||||
@Override
|
||||
public AuthProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||||
Class<? extends AuthProvider> cls = AuthProvider.getProviderClass(typename);
|
||||
if (cls == null) {
|
||||
LogHelper.error("AuthProvider %s not found", typename);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return (AuthProvider) context.deserialize(json, cls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(AuthProvider src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject jo = context.serialize(src).getAsJsonObject();
|
||||
|
||||
String classPath = AuthProvider.getProviderName(src.getClass());
|
||||
jo.add(PROP_NAME, new JsonPrimitive(classPath));
|
||||
|
||||
return jo;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package ru.gravit.launchserver.config.adapter;
|
||||
|
||||
import com.google.gson.*;
|
||||
import ru.gravit.launchserver.auth.hwid.HWIDHandler;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class HWIDHandlerAdapter implements JsonSerializer<HWIDHandler>, JsonDeserializer<HWIDHandler> {
|
||||
private static final String PROP_NAME = "type";
|
||||
|
||||
@Override
|
||||
public HWIDHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||||
Class<? extends HWIDHandler> cls = HWIDHandler.getHandlerClass(typename);
|
||||
if (cls == null) {
|
||||
LogHelper.error("HWIDHandler %s not found", typename);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return (HWIDHandler) context.deserialize(json, cls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(HWIDHandler src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject jo = context.serialize(src).getAsJsonObject();
|
||||
|
||||
String classPath = HWIDHandler.getHandlerName(src.getClass());
|
||||
jo.add(PROP_NAME, new JsonPrimitive(classPath));
|
||||
|
||||
return jo;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package ru.gravit.launchserver.config.adapter;
|
||||
|
||||
import com.google.gson.*;
|
||||
import ru.gravit.launchserver.auth.permissions.PermissionsHandler;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class PermissionsHandlerAdapter implements JsonSerializer<PermissionsHandler>, JsonDeserializer<PermissionsHandler> {
|
||||
private static final String PROP_NAME = "type";
|
||||
|
||||
@Override
|
||||
public PermissionsHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||||
Class<? extends PermissionsHandler> cls = PermissionsHandler.getHandlerClass(typename);
|
||||
if (cls == null) {
|
||||
LogHelper.error("PermissionsHandler %s not found", typename);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return (PermissionsHandler) context.deserialize(json, cls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(PermissionsHandler src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject jo = context.serialize(src).getAsJsonObject();
|
||||
|
||||
String classPath = PermissionsHandler.getHandlerName(src.getClass());
|
||||
jo.add(PROP_NAME, new JsonPrimitive(classPath));
|
||||
|
||||
return jo;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package ru.gravit.launchserver.config.adapter;
|
||||
|
||||
import com.google.gson.*;
|
||||
import ru.gravit.launchserver.auth.texture.TextureProvider;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class TextureProviderAdapter implements JsonSerializer<TextureProvider>, JsonDeserializer<TextureProvider> {
|
||||
private static final String PROP_NAME = "type";
|
||||
|
||||
@Override
|
||||
public TextureProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||||
Class<? extends TextureProvider> cls = TextureProvider.getProviderClass(typename);
|
||||
if (cls == null) {
|
||||
LogHelper.error("TextureProvider %s not found", typename);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return (TextureProvider) context.deserialize(json, cls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(TextureProvider src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject jo = context.serialize(src).getAsJsonObject();
|
||||
|
||||
String classPath = TextureProvider.getProviderName(src.getClass());
|
||||
jo.add(PROP_NAME, new JsonPrimitive(classPath));
|
||||
|
||||
return jo;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue