mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Разбитие команд лаунчсервера на категории
This commit is contained in:
parent
8192cc50d8
commit
5612776da0
3 changed files with 72 additions and 31 deletions
|
@ -11,44 +11,54 @@
|
||||||
import ru.gravit.launchserver.command.modules.LoadModuleCommand;
|
import ru.gravit.launchserver.command.modules.LoadModuleCommand;
|
||||||
import ru.gravit.launchserver.command.modules.ModulesCommand;
|
import ru.gravit.launchserver.command.modules.ModulesCommand;
|
||||||
import ru.gravit.launchserver.command.service.*;
|
import ru.gravit.launchserver.command.service.*;
|
||||||
|
import ru.gravit.utils.command.BaseCommandCategory;
|
||||||
|
|
||||||
public abstract class CommandHandler extends ru.gravit.utils.command.CommandHandler {
|
public abstract class CommandHandler extends ru.gravit.utils.command.CommandHandler {
|
||||||
public static void registerCommands(ru.gravit.utils.command.CommandHandler handler) {
|
public static void registerCommands(ru.gravit.utils.command.CommandHandler handler) {
|
||||||
LaunchServer server = LaunchServer.server;
|
LaunchServer server = LaunchServer.server;
|
||||||
|
BaseCommandCategory basic = new BaseCommandCategory();
|
||||||
// Register basic commands
|
// Register basic commands
|
||||||
handler.registerCommand("help", new HelpCommand(server));
|
basic.registerCommand("help", new HelpCommand(server));
|
||||||
handler.registerCommand("version", new VersionCommand(server));
|
basic.registerCommand("version", new VersionCommand(server));
|
||||||
handler.registerCommand("build", new BuildCommand(server));
|
basic.registerCommand("build", new BuildCommand(server));
|
||||||
handler.registerCommand("stop", new StopCommand(server));
|
basic.registerCommand("stop", new StopCommand(server));
|
||||||
handler.registerCommand("restart", new RestartCommand(server));
|
basic.registerCommand("restart", new RestartCommand(server));
|
||||||
handler.registerCommand("rebind", new RebindCommand(server));
|
basic.registerCommand("rebind", new RebindCommand(server));
|
||||||
handler.registerCommand("debug", new DebugCommand(server));
|
basic.registerCommand("debug", new DebugCommand(server));
|
||||||
handler.registerCommand("clear", new ClearCommand(server));
|
basic.registerCommand("clear", new ClearCommand(server));
|
||||||
handler.registerCommand("gc", new GCCommand(server));
|
basic.registerCommand("gc", new GCCommand(server));
|
||||||
handler.registerCommand("proguardClean", new ProguardCleanCommand(server));
|
basic.registerCommand("proguardClean", new ProguardCleanCommand(server));
|
||||||
handler.registerCommand("proguardDictRegen", new RegenProguardDictCommand(server));
|
basic.registerCommand("proguardDictRegen", new RegenProguardDictCommand(server));
|
||||||
handler.registerCommand("proguardMappingsRemove", new RemoveMappingsProguardCommand(server));
|
basic.registerCommand("proguardMappingsRemove", new RemoveMappingsProguardCommand(server));
|
||||||
handler.registerCommand("logConnections", new LogConnectionsCommand(server));
|
basic.registerCommand("logConnections", new LogConnectionsCommand(server));
|
||||||
handler.registerCommand("loadModule", new LoadModuleCommand(server));
|
basic.registerCommand("loadModule", new LoadModuleCommand(server));
|
||||||
handler.registerCommand("modules", new ModulesCommand(server));
|
basic.registerCommand("modules", new ModulesCommand(server));
|
||||||
handler.registerCommand("test", new TestCommand(server));
|
basic.registerCommand("test", new TestCommand(server));
|
||||||
|
Category basicCategory = new Category(basic,"basic", "Base LaunchServer commands");
|
||||||
|
handler.registerCategory(basicCategory);
|
||||||
|
|
||||||
// Register sync commands
|
// Register sync commands
|
||||||
handler.registerCommand("indexAsset", new IndexAssetCommand(server));
|
BaseCommandCategory updates = new BaseCommandCategory();
|
||||||
handler.registerCommand("unindexAsset", new UnindexAssetCommand(server));
|
updates.registerCommand("indexAsset", new IndexAssetCommand(server));
|
||||||
handler.registerCommand("downloadAsset", new DownloadAssetCommand(server));
|
updates.registerCommand("unindexAsset", new UnindexAssetCommand(server));
|
||||||
handler.registerCommand("downloadClient", new DownloadClientCommand(server));
|
updates.registerCommand("downloadAsset", new DownloadAssetCommand(server));
|
||||||
handler.registerCommand("syncBinaries", new SyncBinariesCommand(server));
|
updates.registerCommand("downloadClient", new DownloadClientCommand(server));
|
||||||
handler.registerCommand("syncUpdates", new SyncUpdatesCommand(server));
|
updates.registerCommand("syncBinaries", new SyncBinariesCommand(server));
|
||||||
handler.registerCommand("syncProfiles", new SyncProfilesCommand(server));
|
updates.registerCommand("syncUpdates", new SyncUpdatesCommand(server));
|
||||||
|
updates.registerCommand("syncProfiles", new SyncProfilesCommand(server));
|
||||||
|
Category updatesCategory = new Category(updates,"updates", "Update and Sync Management");
|
||||||
|
handler.registerCategory(updatesCategory);
|
||||||
|
|
||||||
// Register auth commands
|
// Register auth commands
|
||||||
handler.registerCommand("auth", new AuthCommand(server));
|
BaseCommandCategory auth = new BaseCommandCategory();
|
||||||
handler.registerCommand("usernameToUUID", new UsernameToUUIDCommand(server));
|
auth.registerCommand("auth", new AuthCommand(server));
|
||||||
handler.registerCommand("uuidToUsername", new UUIDToUsernameCommand(server));
|
auth.registerCommand("usernameToUUID", new UsernameToUUIDCommand(server));
|
||||||
handler.registerCommand("ban", new BanCommand(server));
|
auth.registerCommand("uuidToUsername", new UUIDToUsernameCommand(server));
|
||||||
handler.registerCommand("unban", new UnbanCommand(server));
|
auth.registerCommand("ban", new BanCommand(server));
|
||||||
handler.registerCommand("getHWID", new GetHWIDCommand(server));
|
auth.registerCommand("unban", new UnbanCommand(server));
|
||||||
|
auth.registerCommand("getHWID", new GetHWIDCommand(server));
|
||||||
|
Category authCategory = new Category(auth,"auth", "User Management");
|
||||||
|
handler.registerCategory(authCategory);
|
||||||
|
|
||||||
//Register dump commands
|
//Register dump commands
|
||||||
handler.registerCommand("dumpSessions", new DumpSessionsCommand(server));
|
handler.registerCommand("dumpSessions", new DumpSessionsCommand(server));
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import ru.gravit.launchserver.auth.AuthProviderPair;
|
import ru.gravit.launchserver.auth.AuthProviderPair;
|
||||||
import ru.gravit.launchserver.auth.handler.CachedAuthHandler;
|
import ru.gravit.launchserver.auth.handler.CachedAuthHandler;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
import ru.gravit.utils.command.CommandHandler;
|
||||||
import ru.gravit.utils.helper.JVMHelper;
|
import ru.gravit.utils.helper.JVMHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
@ -33,7 +34,12 @@ public void invoke(String... args) {
|
||||||
long days = (uptime / 60 / 60 / 24);
|
long days = (uptime / 60 / 60 / 24);
|
||||||
LogHelper.info("Uptime: %d days %d hours %d minutes %d seconds", days, hour, min, second);
|
LogHelper.info("Uptime: %d days %d hours %d minutes %d seconds", days, hour, min, second);
|
||||||
LogHelper.info("Uptime (double): %f", (double) JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000);
|
LogHelper.info("Uptime (double): %f", (double) JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000);
|
||||||
LogHelper.info("Sessions: %d | Modules: %d | Commands: %d", server.sessionManager.getSessions().size(), server.modulesManager.modules.size(), server.commandHandler.commandsMap().size());
|
int commands = server.commandHandler.getBaseCategory().commandsMap().size();
|
||||||
|
for(CommandHandler.Category category : server.commandHandler.getCategories())
|
||||||
|
{
|
||||||
|
commands += category.category.commandsMap().size();
|
||||||
|
}
|
||||||
|
LogHelper.info("Sessions: %d | Modules: %d | Commands: %d(%d categories)", server.sessionManager.getSessions().size(), server.modulesManager.modules.size(), commands, server.commandHandler.getCategories().size() + 1);
|
||||||
for (AuthProviderPair pair : server.config.auth) {
|
for (AuthProviderPair pair : server.config.auth) {
|
||||||
if (pair.handler instanceof CachedAuthHandler) {
|
if (pair.handler instanceof CachedAuthHandler) {
|
||||||
LogHelper.info("AuthHandler %s: EntryCache: %d | usernameCache: %d", pair.name, ((CachedAuthHandler) pair.handler).getEntryCache().size(), ((CachedAuthHandler) pair.handler).getUsernamesCache().size());
|
LogHelper.info("AuthHandler %s: EntryCache: %d | usernameCache: %d", pair.name, ((CachedAuthHandler) pair.handler).getEntryCache().size(), ((CachedAuthHandler) pair.handler).getUsernamesCache().size());
|
||||||
|
|
|
@ -12,11 +12,22 @@ public abstract class CommandHandler implements Runnable {
|
||||||
private final List<Category> categories = new ArrayList<>();
|
private final List<Category> categories = new ArrayList<>();
|
||||||
private final CommandCategory baseCategory = new BaseCommandCategory();
|
private final CommandCategory baseCategory = new BaseCommandCategory();
|
||||||
|
|
||||||
public class Category
|
public static class Category
|
||||||
{
|
{
|
||||||
public CommandCategory category;
|
public CommandCategory category;
|
||||||
public String name;
|
public String name;
|
||||||
public String description;
|
public String description;
|
||||||
|
|
||||||
|
public Category(CommandCategory category, String name) {
|
||||||
|
this.category = category;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Category(CommandCategory category, String name, String description) {
|
||||||
|
this.category = category;
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void eval(String line, boolean bell) {
|
public void eval(String line, boolean bell) {
|
||||||
|
@ -93,6 +104,20 @@ public void registerCommand(String name, Command command) {
|
||||||
baseCategory.registerCommand(name, command);
|
baseCategory.registerCommand(name, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void registerCategory(Category category)
|
||||||
|
{
|
||||||
|
categories.add(category);
|
||||||
|
}
|
||||||
|
public boolean unregisterCategory(Category category)
|
||||||
|
{
|
||||||
|
return categories.remove(category);
|
||||||
|
}
|
||||||
|
public Category findCategory(String name)
|
||||||
|
{
|
||||||
|
for(Category category : categories) if(category.name.equals(name)) return category;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public Command unregisterCommand(String name) {
|
public Command unregisterCommand(String name) {
|
||||||
return baseCategory.unregisterCommand(name);
|
return baseCategory.unregisterCommand(name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue