diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 1b6d8e03..81247f3b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -745,7 +745,6 @@ public LaunchServer(Path dir, boolean testEnv, String[] args) throws IOException LogHelper.debug("Init components"); config.components.forEach((k, v) -> { LogHelper.subDebug("Init component %s", k); - registerObject("component.".concat(k), v); v.init(this); }); LogHelper.debug("Init components successful"); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java index 0d629039..1087e359 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java @@ -6,12 +6,62 @@ import java.util.Map; import pro.gravit.launcher.NeedGarbageCollection; +import pro.gravit.launchserver.Reconfigurable; +import pro.gravit.utils.command.Command; +import pro.gravit.utils.command.SubCommand; +import pro.gravit.utils.helper.LogHelper; -public abstract class AbstractLimiter extends Component implements NeedGarbageCollection { +public abstract class AbstractLimiter extends Component implements NeedGarbageCollection, Reconfigurable { public int rateLimit; public int rateLimitMillis; public List exclude = new ArrayList<>(); + @Override + public Map getCommands() { + Map commands = new HashMap<>(); + commands.put("gc", new SubCommand() { + @Override + public void invoke(String... args) throws Exception { + long size = map.size(); + garbageCollection(); + LogHelper.info("Cleared %d entity", size); + } + }); + commands.put("clear", new SubCommand() { + @Override + public void invoke(String... args) throws Exception { + long size = map.size(); + map.clear(); + LogHelper.info("Cleared %d entity", size); + } + }); + commands.put("addExclude", new SubCommand() { + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 1); + exclude.add(getFromString(args[0])); + } + }); + commands.put("rmExclude", new SubCommand() { + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 1); + exclude.remove(getFromString(args[0])); + } + }); + commands.put("clearExclude", new SubCommand() { + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 1); + exclude.clear(); + } + }); + + return commands; + } + + protected abstract T getFromString(String str); + @Override public void garbageCollection() { long time = System.currentTimeMillis(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/AuthLimiterComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/AuthLimiterComponent.java index 5b3346c3..1e7ca11a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/AuthLimiterComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/AuthLimiterComponent.java @@ -9,7 +9,7 @@ import pro.gravit.launchserver.socket.response.auth.AuthResponse; import pro.gravit.utils.HookException; -public class AuthLimiterComponent extends AbstractLimiter implements NeedGarbageCollection, AutoCloseable { +public class AuthLimiterComponent extends IPLimiter implements NeedGarbageCollection, AutoCloseable { private transient LaunchServer srv; @Override public void preInit(LaunchServer launchServer) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/IPLimiter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/IPLimiter.java new file mode 100644 index 00000000..3f4fd5f0 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/IPLimiter.java @@ -0,0 +1,8 @@ +package pro.gravit.launchserver.components; + +public abstract class IPLimiter extends AbstractLimiter { + @Override + protected String getFromString(String str) { + return str; + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java index 8a6327cd..4fbdd053 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java @@ -8,7 +8,7 @@ import pro.gravit.launchserver.manangers.hook.AuthHookManager; import pro.gravit.utils.HookException; -public class RegLimiterComponent extends AbstractLimiter implements NeedGarbageCollection, AutoCloseable { +public class RegLimiterComponent extends IPLimiter implements NeedGarbageCollection, AutoCloseable { public transient LaunchServer launchServer; public String message;