mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Команды AbstractLimiter - gc,clear,addExclude,rmExclude, clearExclude
This commit is contained in:
parent
82e3ae797c
commit
248450373a
5 changed files with 61 additions and 4 deletions
|
@ -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");
|
||||
|
|
|
@ -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<T> extends Component implements NeedGarbageCollection {
|
||||
public abstract class AbstractLimiter<T> extends Component implements NeedGarbageCollection, Reconfigurable {
|
||||
public int rateLimit;
|
||||
public int rateLimitMillis;
|
||||
public List<T> exclude = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Map<String, Command> getCommands() {
|
||||
Map<String, Command> 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();
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import pro.gravit.launchserver.socket.response.auth.AuthResponse;
|
||||
import pro.gravit.utils.HookException;
|
||||
|
||||
public class AuthLimiterComponent extends AbstractLimiter<String> implements NeedGarbageCollection, AutoCloseable {
|
||||
public class AuthLimiterComponent extends IPLimiter implements NeedGarbageCollection, AutoCloseable {
|
||||
private transient LaunchServer srv;
|
||||
@Override
|
||||
public void preInit(LaunchServer launchServer) {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package pro.gravit.launchserver.components;
|
||||
|
||||
public abstract class IPLimiter extends AbstractLimiter<String> {
|
||||
@Override
|
||||
protected String getFromString(String str) {
|
||||
return str;
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
import pro.gravit.launchserver.manangers.hook.AuthHookManager;
|
||||
import pro.gravit.utils.HookException;
|
||||
|
||||
public class RegLimiterComponent extends AbstractLimiter<String> implements NeedGarbageCollection, AutoCloseable {
|
||||
public class RegLimiterComponent extends IPLimiter implements NeedGarbageCollection, AutoCloseable {
|
||||
|
||||
public transient LaunchServer launchServer;
|
||||
public String message;
|
||||
|
|
Loading…
Reference in a new issue