From cb5535b8ec8e9f8d5791f2ec878db4a40969010c Mon Sep 17 00:00:00 2001 From: Gravita Date: Sun, 20 Dec 2020 15:27:29 +0700 Subject: [PATCH] [FEATURE] FeaturesManager --- .../pro/gravit/launchserver/LaunchServer.java | 2 ++ .../manangers/FeaturesManager.java | 35 +++++++++++++++++++ .../response/management/FeaturesResponse.java | 18 ++++++++++ .../events/request/FeaturesRequestEvent.java | 21 +++++++++++ .../request/management/FeaturesRequest.java | 11 ++++++ 5 files changed, 87 insertions(+) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/manangers/FeaturesManager.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/FeaturesResponse.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/events/request/FeaturesRequestEvent.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/request/management/FeaturesRequest.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 2a7d58b8..b74d8de7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -81,6 +81,7 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab public final ReconfigurableManager reconfigurableManager; public final ConfigManager configManager; public final PingServerManager pingServerManager; + public final FeaturesManager featuresManager; // HWID ban + anti-brutforce public final CertificateManager certificateManager; public final ProguardConf proguardConf; @@ -147,6 +148,7 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La authHookManager = new AuthHookManager(); configManager = new ConfigManager(); pingServerManager = new PingServerManager(this); + featuresManager = new FeaturesManager(this); //Generate or set new Certificate API certificateManager.orgName = config.projectName; /* diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/FeaturesManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/FeaturesManager.java new file mode 100644 index 00000000..da1d15c8 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/FeaturesManager.java @@ -0,0 +1,35 @@ +package pro.gravit.launchserver.manangers; + +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.utils.Version; + +import java.util.HashMap; +import java.util.Map; + +public class FeaturesManager { + private transient LaunchServer server; + private Map map; + + public FeaturesManager(LaunchServer server) { + this.server = server; + map = new HashMap<>(); + addFeatureInfo("version", Version.getVersion().getVersionString()); + + } + + public Map getMap() { + return map; + } + + public String getFeatureInfo(String name) { + return map.get(name); + } + + public String addFeatureInfo(String name, String featureInfo) { + return map.put(name, featureInfo); + } + + public String removeFeatureInfo(String name) { + return map.remove(name); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/FeaturesResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/FeaturesResponse.java new file mode 100644 index 00000000..09eb4118 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/FeaturesResponse.java @@ -0,0 +1,18 @@ +package pro.gravit.launchserver.socket.response.management; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launcher.events.request.FeaturesRequestEvent; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.SimpleResponse; + +public class FeaturesResponse extends SimpleResponse { + @Override + public String getType() { + return "features"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + sendResult(new FeaturesRequestEvent(server.featuresManager.getMap())); + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/FeaturesRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/FeaturesRequestEvent.java new file mode 100644 index 00000000..d6151b19 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/FeaturesRequestEvent.java @@ -0,0 +1,21 @@ +package pro.gravit.launcher.events.request; + +import pro.gravit.launcher.events.RequestEvent; + +import java.util.Map; + +public class FeaturesRequestEvent extends RequestEvent { + public Map features; + + public FeaturesRequestEvent() { + } + + public FeaturesRequestEvent(Map features) { + this.features = features; + } + + @Override + public String getType() { + return "features"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/FeaturesRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/FeaturesRequest.java new file mode 100644 index 00000000..d203cdff --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/FeaturesRequest.java @@ -0,0 +1,11 @@ +package pro.gravit.launcher.request.management; + +import pro.gravit.launcher.events.request.FeaturesRequestEvent; +import pro.gravit.launcher.request.Request; + +public class FeaturesRequest extends Request { + @Override + public String getType() { + return "features"; + } +}