diff --git a/src/agent/main/java/org/comroid/mcsd/agent/AgentRunner.java b/src/agent/main/java/org/comroid/mcsd/agent/AgentRunner.java index 2ccbda9b..7c177fcf 100644 --- a/src/agent/main/java/org/comroid/mcsd/agent/AgentRunner.java +++ b/src/agent/main/java/org/comroid/mcsd/agent/AgentRunner.java @@ -105,11 +105,10 @@ public Object status(String[] args, ConsoleController.Connection con) { @Command(usage = " (experimental)") public Object reload(String[] args, ConsoleController.Connection con) { var srv = getServer(args); - srv.requirePermission(con.getUser(), AbstractEntity.Permission.ForceOP); - var tree = manager.tree(srv); - tree.terminate(); - tree.initialize(); - return srv+" modules have been reloaded"; + srv.requirePermission(con.getUser(), AbstractEntity.Permission.Administrate); + var tree = manager.get(srv).orElseThrow(()->new Command.Error("Could not load entry " + srv)); + var load = tree.reloadProtos(); + return load+" modules have been reloaded"; } @Command(usage = " [-na]") diff --git a/src/core/main/java/org/comroid/mcsd/core/ServerManager.java b/src/core/main/java/org/comroid/mcsd/core/ServerManager.java index 729b1c1d..a25c0def 100644 --- a/src/core/main/java/org/comroid/mcsd/core/ServerManager.java +++ b/src/core/main/java/org/comroid/mcsd/core/ServerManager.java @@ -127,15 +127,25 @@ public long cleanupModules() { .count(); } + private Stream streamProtos() { + return Streams.of(moduleRepo.findAllByServerId(server.getId())); + } + + /** + * Reloads all module configurations without restarting anything + */ public long reloadProtos() { - return 0; //todo + return streamProtos() + .filter(tree::containsKey) + .peek(proto -> tree.get(proto).setProto(proto)) + .count(); } /** * Loads all modules that are in DB but are not loaded as a module */ public long refreshModules() { - return Streams.of(moduleRepo.findAllByServerId(server.getId())) + return streamProtos() .filter(not(tree::containsKey)) .>map(proto -> { log.fine("Loading proto " + proto); diff --git a/src/core/main/java/org/comroid/mcsd/core/entity/AbstractEntity.java b/src/core/main/java/org/comroid/mcsd/core/entity/AbstractEntity.java index 820e8054..a1cf7c89 100644 --- a/src/core/main/java/org/comroid/mcsd/core/entity/AbstractEntity.java +++ b/src/core/main/java/org/comroid/mcsd/core/entity/AbstractEntity.java @@ -65,7 +65,7 @@ public final boolean hasAnyPermission(@NotNull User user) { return hasPermission(user, Permission.Any); } - public final boolean hasPermission(@NotNull User user, AbstractEntity.Permission... permissions) { + public boolean hasPermission(@NotNull User user, AbstractEntity.Permission... permissions) { Constraint.Length.min(1, permissions, "permissions").run(); final var mask = this.permissions.getOrDefault(user, 0); return (owner != null && user.getId().equals(owner.getId())) diff --git a/src/core/main/java/org/comroid/mcsd/core/entity/module/ModulePrototype.java b/src/core/main/java/org/comroid/mcsd/core/entity/module/ModulePrototype.java index cde863c3..aa196006 100644 --- a/src/core/main/java/org/comroid/mcsd/core/entity/module/ModulePrototype.java +++ b/src/core/main/java/org/comroid/mcsd/core/entity/module/ModulePrototype.java @@ -24,6 +24,7 @@ import org.comroid.mcsd.core.entity.module.status.UpdateModulePrototype; import org.comroid.mcsd.core.entity.module.status.UptimeModulePrototype; import org.comroid.mcsd.core.entity.server.Server; +import org.comroid.mcsd.core.entity.system.User; import org.comroid.mcsd.core.module.ServerModule; import org.comroid.mcsd.core.module.console.McsdCommandModule; import org.comroid.mcsd.core.module.discord.DiscordModule; @@ -38,6 +39,7 @@ import org.comroid.mcsd.core.module.status.UpdateModule; import org.comroid.mcsd.core.module.status.UptimeModule; import org.comroid.mcsd.core.repo.module.ModuleRepo; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -71,6 +73,11 @@ public , P extends ModulePrototype> T toModule(Server return Polyfill.uncheckedCast(module); } + @Override + public boolean hasPermission(@NotNull User user, Permission... permissions) { + return super.hasPermission(user, permissions) || server.hasPermission(user, permissions); + } + @Getter public enum Type implements Named { // console diff --git a/src/core/main/java/org/comroid/mcsd/core/module/ServerModule.java b/src/core/main/java/org/comroid/mcsd/core/module/ServerModule.java index 9519e24a..d506fd24 100644 --- a/src/core/main/java/org/comroid/mcsd/core/module/ServerModule.java +++ b/src/core/main/java/org/comroid/mcsd/core/module/ServerModule.java @@ -2,8 +2,6 @@ import lombok.AllArgsConstructor; import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; import org.comroid.api.Component; import org.comroid.api.Named; import org.comroid.mcsd.core.ServerManager; @@ -13,7 +11,7 @@ import static org.comroid.mcsd.core.util.ApplicationContextProvider.bean; -@Getter +@Data @AllArgsConstructor public abstract class ServerModule extends Component.Base implements Named { protected final Server server; diff --git a/src/hub/main/java/org/comroid/mcsd/hub/controller/ApiController.java b/src/hub/main/java/org/comroid/mcsd/hub/controller/ApiController.java index 5d91818a..253cf047 100644 --- a/src/hub/main/java/org/comroid/mcsd/hub/controller/ApiController.java +++ b/src/hub/main/java/org/comroid/mcsd/hub/controller/ApiController.java @@ -11,6 +11,7 @@ import org.comroid.mcsd.core.MCSD; import org.comroid.mcsd.core.ServerManager; import org.comroid.mcsd.core.entity.*; +import org.comroid.mcsd.core.entity.module.ModulePrototype; import org.comroid.mcsd.core.entity.server.Server; import org.comroid.mcsd.core.entity.system.*; import org.comroid.mcsd.core.exception.EntityNotFoundException; @@ -34,6 +35,7 @@ import java.time.Instant; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; @Slf4j @Controller @@ -73,6 +75,12 @@ public List servers(HttpSession session) { .toList(); } + @ResponseBody + @GetMapping("/webapp/modules") + public List modules() { + return Stream.of(ModulePrototype.Type.values()).toList(); + } + @ResponseBody @GetMapping("/webapp/server/{id}/status") public StatusMessage fetchServerStatus(@PathVariable("id") UUID serverId) {