From 511d5461197759fdb5e8495919fa2c684fa72790 Mon Sep 17 00:00:00 2001 From: Pasqual K Date: Fri, 22 May 2020 09:02:21 +0200 Subject: [PATCH 001/219] Begin of delete of controller and client system --- .github/README.md | 39 +- .../listener/ProcessInclusionHandler.java | 16 +- .../application/ReformCloudApplication.java | 11 +- .../listener/ProcessInclusionHandler.java | 16 +- .../defaults/DefaultPermissionManagement.java | 9 +- .../listener/ProcessInclusionHandler.java | 16 +- .../listener/ProcessInclusionHandler.java | 16 +- .../reformcloud2/web/WebApplication.java | 20 +- .../executor/api/ExecutorType.java | 25 +- .../executor/api/client/Client.java | 46 -- .../api/client/process/ProcessManager.java | 89 ---- .../common/api/console/ConsoleSyncAPI.java | 2 +- .../api/common/network/NetworkUtil.java | 2 - .../process/running/SharedRunningProcess.java | 2 +- .../executor/api/controller/Controller.java | 45 -- .../controller/process/ProcessManager.java | 177 ------- reformcloud2-executor/pom.xml | 5 +- .../executor/ExecutorChooser.java | 66 --- .../APIBungeePacketOutPlayerServerSwitch.java | 2 +- .../APIPacketOutRequestIngameMessages.java | 2 +- ...IPacketOutRequestIngameMessagesResult.java | 2 +- .../executor/client/ClientExecutor.java | 370 ------------- .../executor/client/ClientLauncher.java | 38 -- .../executor/client/config/ClientConfig.java | 73 --- .../client/config/ClientConnectionConfig.java | 48 -- .../client/config/ClientExecutorConfig.java | 136 ----- .../executor/client/dump/ClientDumpUtil.java | 85 --- .../channel/ClientNetworkChannelReader.java | 44 -- .../packet/ControllerPacketCopyProcess.java | 86 --- ...ControllerPacketExecuteProcessCommand.java | 76 --- .../ControllerPacketProcessDisconnected.java | 71 --- .../ControllerPacketStartPreparedProcess.java | 77 --- .../packet/ControllerPacketStartProcess.java | 82 --- .../packet/ControllerPacketStopProcess.java | 89 ---- .../packet/ControllerPacketToggleScreen.java | 81 --- .../executor/client/process/ProcessQueue.java | 127 ----- .../process/basic/DefaultProcessManager.java | 83 --- .../process/basic/DefaultRunningProcess.java | 59 --- .../RunningProcessPreparedListener.java | 42 -- .../RunningProcessScreenListener.java | 62 --- .../RunningProcessStoppedListener.java | 43 -- .../controller/ControllerExecutor.java | 488 ------------------ .../controller/ControllerLauncher.java | 38 -- .../executor/controller/api/GeneralAPI.java | 145 ------ .../api/console/ConsoleAPIImplementation.java | 96 ---- .../database/DatabaseAPIImplementation.java | 334 ------------ .../api/group/GroupAPIImplementation.java | 323 ------------ .../ChannelMessageAPIImplementation.java | 134 ----- .../api/player/PlayerAPIImplementation.java | 246 --------- .../api/process/ProcessAPIImplementation.java | 393 -------------- .../controller/commands/CommandClients.java | 238 --------- .../controller/config/ControllerConfig.java | 62 --- .../config/ControllerExecutorConfig.java | 248 --------- .../ControllerNetworkChannelReader.java | 44 -- .../ControllerNetworkSuccessHandler.java | 57 -- .../packet/ClientPacketAddScreenLine.java | 80 --- .../ClientPacketNotifyRuntimeUpdate.java | 70 --- .../packet/ClientPacketProcessPrepared.java | 89 ---- .../packet/ClientPacketProcessRegistered.java | 84 --- .../packet/ClientPacketProcessStopped.java | 86 --- .../ClientPacketProcessWatchdogStopped.java | 69 --- .../packet/ClientPacketScreenEnabled.java | 87 ---- .../handler/PacketInAPILogoutPlayer.java | 66 --- .../PacketInAPIPlayerCommandExecute.java | 57 -- .../handler/PacketInAPIPlayerLoggedIn.java | 62 --- .../PacketInAPIServerSwitchPlayer.java | 62 --- .../controller/process/ClientManager.java | 97 ---- .../process/DefaultProcessManager.java | 450 ---------------- .../process/startup/AutoStartupHandler.java | 121 ----- .../reformcloud2/runner/Runner.java | 6 +- .../commands/CheckForUpdatesCommand.java | 2 +- .../commands/CheckIfDevModeCommand.java | 2 +- .../commands/CheckIfSnapshotApplyCommand.java | 2 +- .../runner/commands/SetupCommand.java | 48 -- .../runner/commands/WriteEnvCommand.java | 9 - .../runner/setup/RunnerExecutorSetup.java | 86 --- .../reformcloud2/runner/util/RunnerUtils.java | 8 +- .../runner/variables/EnvSetVariable.java | 2 +- .../variables/SetupRequiredVariable.java | 2 +- .../src/main/resources/global.reformscript | 2 - 80 files changed, 38 insertions(+), 6837 deletions(-) delete mode 100644 reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/client/Client.java delete mode 100644 reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/client/process/ProcessManager.java delete mode 100644 reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/controller/Controller.java delete mode 100644 reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/controller/process/ProcessManager.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/ExecutorChooser.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/ClientExecutor.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/ClientLauncher.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/config/ClientConfig.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/config/ClientConnectionConfig.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/config/ClientExecutorConfig.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/dump/ClientDumpUtil.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/channel/ClientNetworkChannelReader.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketCopyProcess.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketExecuteProcessCommand.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketProcessDisconnected.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketStartPreparedProcess.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketStartProcess.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketStopProcess.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketToggleScreen.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/ProcessQueue.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/basic/DefaultProcessManager.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/basic/DefaultRunningProcess.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/listeners/RunningProcessPreparedListener.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/listeners/RunningProcessScreenListener.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/listeners/RunningProcessStoppedListener.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/ControllerExecutor.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/ControllerLauncher.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/GeneralAPI.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/console/ConsoleAPIImplementation.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/database/DatabaseAPIImplementation.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/group/GroupAPIImplementation.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/message/ChannelMessageAPIImplementation.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/player/PlayerAPIImplementation.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/process/ProcessAPIImplementation.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/commands/CommandClients.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/config/ControllerConfig.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/config/ControllerExecutorConfig.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/network/channel/ControllerNetworkChannelReader.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/network/channel/ControllerNetworkSuccessHandler.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/network/packet/ClientPacketAddScreenLine.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/network/packet/ClientPacketNotifyRuntimeUpdate.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/network/packet/ClientPacketProcessPrepared.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/network/packet/ClientPacketProcessRegistered.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/network/packet/ClientPacketProcessStopped.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/network/packet/ClientPacketProcessWatchdogStopped.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/network/packet/ClientPacketScreenEnabled.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/network/packet/handler/PacketInAPILogoutPlayer.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/network/packet/handler/PacketInAPIPlayerCommandExecute.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/network/packet/handler/PacketInAPIPlayerLoggedIn.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/network/packet/handler/PacketInAPIServerSwitchPlayer.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/process/ClientManager.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/process/DefaultProcessManager.java delete mode 100644 reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/process/startup/AutoStartupHandler.java delete mode 100644 reformcloud2-runner/src/main/java/systems/reformcloud/reformcloud2/runner/commands/SetupCommand.java delete mode 100644 reformcloud2-runner/src/main/java/systems/reformcloud/reformcloud2/runner/setup/RunnerExecutorSetup.java diff --git a/.github/README.md b/.github/README.md index 9bc1c21cd..4fb63af06 100644 --- a/.github/README.md +++ b/.github/README.md @@ -4,8 +4,8 @@ ReformCloud is a cloud system programmed and optimized for all sizes of networks. The cloud system provides a huge api to access all internal functions, group, processes etc. It's made -for **synchronized as well as asynchronous programming** and is integrated into the main executors **Node, -Controller and Client** but as well into the apis for **Velocity / BungeeCord / Spigot / Sponge / Nukkit etc**. +for **synchronized as well as asynchronous programming** and is integrated into the main executor **Node** + but as well into the apis for **Velocity / BungeeCord / Spigot / Sponge / Nukkit etc**. So the development work to integrate something like a private server system into the cloud is not that much work and get be made easily by every developer who spends 5 minutes to read **the documentation of the api**. ReformCloud is basically just an application to start and manage the minecraft servers and proxies. @@ -64,41 +64,6 @@ java -XX:+UseG1GC -XX:MaxGCPauseMillis=50 -XX:CompileThreshold=100 -Xmx512m -Xms The runner is now going to download the needed libraries for the runtime, so **make sure you have an internet connection** during the first startup! -When you start the system the first time it will asked you which installation you want to do: -``` -Please choose an executor: ["controller", "client", "node" (recommended)] -``` - -**Controller (Master)**: Manages all processes and clients (Wrapper), exists only once in the network - -**Client (Wrapper)**: Is like a slave for the controller and starts the processes, can exists multiple -times in a network setup - -**Node**: This is the ***recommended*** installation, basically it brings the features of the controller/client -into one system and can also exists multiple times in a network structure, called "cluster". - - -# Basic installation -## Controller - -The controller will aks two questions: - 1) Which ip address (or domain) the controller is running on. If the controller is local you can simply - provide 127.0.0.1. If you have more than one server and you would like to run multiple Clients with the - controller, provide the public ip address of the server. (On Linux: `ip -a`, on Windows: `ipconfig`). - - 2) The next thing will be the default group installation. There are multiple default things you can choose - from. Every installation type will create a proxy and lobby group with the version you choose - (Excluded `nothing`: as the name says, it will install nothing). - -## Client - -The client will ask five questions: - 1) The client needs the connection key to connect to the controller. The key is located in `CONTROLLER_DIR/reformcloud/.bin/connection.json`. - 2) After this the client needs the host on which the servers and proxies should get bound to - 3) Then you have to provide the maximum amount of memory the client is allowed to use - 4) Next, the client will ask for the controller ip or domain name, provide the same as in the controller setup - 5) Finally the client asks for the network port of the controller (default `2008`) - ## Node The node will ask six questions: diff --git a/reformcloud2-applications/reformcloud2-default-application-commands/src/main/java/systems/reformcloud/reformcloud2/commands/application/listener/ProcessInclusionHandler.java b/reformcloud2-applications/reformcloud2-default-application-commands/src/main/java/systems/reformcloud/reformcloud2/commands/application/listener/ProcessInclusionHandler.java index 58edb5202..04c3ba2ed 100644 --- a/reformcloud2-applications/reformcloud2-default-application-commands/src/main/java/systems/reformcloud/reformcloud2/commands/application/listener/ProcessInclusionHandler.java +++ b/reformcloud2-applications/reformcloud2-default-application-commands/src/main/java/systems/reformcloud/reformcloud2/commands/application/listener/ProcessInclusionHandler.java @@ -26,28 +26,16 @@ import org.jetbrains.annotations.NotNull; import systems.reformcloud.reformcloud2.commands.application.ReformCloudApplication; -import systems.reformcloud.reformcloud2.executor.api.ExecutorType; -import systems.reformcloud.reformcloud2.executor.api.common.ExecutorAPI; import systems.reformcloud.reformcloud2.executor.api.common.event.handler.Listener; import systems.reformcloud.reformcloud2.executor.api.common.process.ProcessInformation; import systems.reformcloud.reformcloud2.executor.api.common.process.api.ProcessInclusion; -import systems.reformcloud.reformcloud2.executor.api.common.process.event.ProcessInformationConfigureEvent; import systems.reformcloud.reformcloud2.executor.api.common.process.running.events.RunningProcessPrepareEvent; public final class ProcessInclusionHandler { @Listener - public void handle(final ProcessInformationConfigureEvent event) { - if (ExecutorAPI.getInstance().getType().equals(ExecutorType.CONTROLLER)) { - this.includeSelfFile(event.getInformation()); - } - } - - @Listener - public void handle(final RunningProcessPrepareEvent event) { - if (ExecutorAPI.getInstance().getType().equals(ExecutorType.NODE)) { - this.includeSelfFile(event.getRunningProcess().getProcessInformation()); - } + public void handle(final @NotNull RunningProcessPrepareEvent event) { + this.includeSelfFile(event.getRunningProcess().getProcessInformation()); } private void includeSelfFile(@NotNull ProcessInformation processInformation) { diff --git a/reformcloud2-applications/reformcloud2-default-application-permissions/src/main/java/systems/reformcloud/reformcloud2/permissions/application/ReformCloudApplication.java b/reformcloud2-applications/reformcloud2-default-application-permissions/src/main/java/systems/reformcloud/reformcloud2/permissions/application/ReformCloudApplication.java index 3aed4aa0a..d67311201 100644 --- a/reformcloud2-applications/reformcloud2-default-application-permissions/src/main/java/systems/reformcloud/reformcloud2/permissions/application/ReformCloudApplication.java +++ b/reformcloud2-applications/reformcloud2-default-application-permissions/src/main/java/systems/reformcloud/reformcloud2/permissions/application/ReformCloudApplication.java @@ -25,12 +25,9 @@ package systems.reformcloud.reformcloud2.permissions.application; import org.jetbrains.annotations.Nullable; -import systems.reformcloud.reformcloud2.executor.api.ExecutorType; import systems.reformcloud.reformcloud2.executor.api.common.ExecutorAPI; import systems.reformcloud.reformcloud2.executor.api.common.application.api.Application; import systems.reformcloud.reformcloud2.executor.api.common.application.updater.ApplicationUpdateRepository; -import systems.reformcloud.reformcloud2.executor.api.common.commands.manager.CommandManager; -import systems.reformcloud.reformcloud2.executor.controller.ControllerExecutor; import systems.reformcloud.reformcloud2.executor.node.NodeExecutor; import systems.reformcloud.reformcloud2.permissions.PermissionManagement; import systems.reformcloud.reformcloud2.permissions.application.command.CommandPerms; @@ -62,7 +59,7 @@ public void onLoad() { public void onEnable() { PermissionManagement.setup(); PacketHelper.addPacketHandler(); - this.getCommandManager().register(new CommandPerms()); + NodeExecutor.getInstance().getCommandManager().register(new CommandPerms()); } @Nullable @@ -70,10 +67,4 @@ public void onEnable() { public ApplicationUpdateRepository getUpdateRepository() { return REPOSITORY; } - - private CommandManager getCommandManager() { - return ExecutorAPI.getInstance().getType().equals(ExecutorType.CONTROLLER) - ? ControllerExecutor.getInstance().getCommandManager() - : NodeExecutor.getInstance().getCommandManager(); - } } diff --git a/reformcloud2-applications/reformcloud2-default-application-permissions/src/main/java/systems/reformcloud/reformcloud2/permissions/application/listener/ProcessInclusionHandler.java b/reformcloud2-applications/reformcloud2-default-application-permissions/src/main/java/systems/reformcloud/reformcloud2/permissions/application/listener/ProcessInclusionHandler.java index 227c377d6..509794aab 100644 --- a/reformcloud2-applications/reformcloud2-default-application-permissions/src/main/java/systems/reformcloud/reformcloud2/permissions/application/listener/ProcessInclusionHandler.java +++ b/reformcloud2-applications/reformcloud2-default-application-permissions/src/main/java/systems/reformcloud/reformcloud2/permissions/application/listener/ProcessInclusionHandler.java @@ -25,29 +25,17 @@ package systems.reformcloud.reformcloud2.permissions.application.listener; import org.jetbrains.annotations.NotNull; -import systems.reformcloud.reformcloud2.executor.api.ExecutorType; -import systems.reformcloud.reformcloud2.executor.api.common.ExecutorAPI; import systems.reformcloud.reformcloud2.executor.api.common.event.handler.Listener; import systems.reformcloud.reformcloud2.executor.api.common.process.ProcessInformation; import systems.reformcloud.reformcloud2.executor.api.common.process.api.ProcessInclusion; -import systems.reformcloud.reformcloud2.executor.api.common.process.event.ProcessInformationConfigureEvent; import systems.reformcloud.reformcloud2.executor.api.common.process.running.events.RunningProcessPrepareEvent; import systems.reformcloud.reformcloud2.permissions.application.ReformCloudApplication; public final class ProcessInclusionHandler { @Listener - public void handle(final ProcessInformationConfigureEvent event) { - if (ExecutorAPI.getInstance().getType().equals(ExecutorType.CONTROLLER)) { - this.includeSelfFile(event.getInformation()); - } - } - - @Listener - public void handle(final RunningProcessPrepareEvent event) { - if (ExecutorAPI.getInstance().getType().equals(ExecutorType.NODE)) { - this.includeSelfFile(event.getRunningProcess().getProcessInformation()); - } + public void handle(final @NotNull RunningProcessPrepareEvent event) { + this.includeSelfFile(event.getRunningProcess().getProcessInformation()); } private void includeSelfFile(@NotNull ProcessInformation processInformation) { diff --git a/reformcloud2-applications/reformcloud2-default-application-permissions/src/main/java/systems/reformcloud/reformcloud2/permissions/defaults/DefaultPermissionManagement.java b/reformcloud2-applications/reformcloud2-default-application-permissions/src/main/java/systems/reformcloud/reformcloud2/permissions/defaults/DefaultPermissionManagement.java index 913f67bb8..cf4b5c456 100644 --- a/reformcloud2-applications/reformcloud2-default-application-permissions/src/main/java/systems/reformcloud/reformcloud2/permissions/defaults/DefaultPermissionManagement.java +++ b/reformcloud2-applications/reformcloud2-default-application-permissions/src/main/java/systems/reformcloud/reformcloud2/permissions/defaults/DefaultPermissionManagement.java @@ -56,8 +56,7 @@ public class DefaultPermissionManagement extends PermissionManagement { public static final String PERMISSION_GROUP_TABLE = "reformcloud_internal_db_perm_group"; public static final String PERMISSION_PLAYER_TABLE = "reformcloud_internal_db_perm_player"; public static final String PERMISSION_NAME_TO_UNIQUE_ID_TABLE = "reformcloud_internal_db_perm_name_uuid"; - private static final boolean CONTROLLER_OR_NODE = ExecutorAPI.getInstance().getType().equals(ExecutorType.CONTROLLER) - || ExecutorAPI.getInstance().getType().equals(ExecutorType.NODE); + private static final boolean NODE = ExecutorAPI.getInstance().getType().equals(ExecutorType.NODE); private final Map nameToGroupCache = new ConcurrentHashMap<>(); private final Map uniqueIdToUserCache = new ConcurrentHashMap<>(); @@ -81,7 +80,7 @@ public DefaultPermissionManagement() { public void updateGroup(@NotNull PermissionGroup permissionGroup) { this.nameToGroupCache.put(permissionGroup.getName(), permissionGroup); - if (CONTROLLER_OR_NODE) { + if (NODE) { ExecutorAPI.getInstance() .getSyncAPI() .getDatabaseSyncAPI() @@ -131,7 +130,7 @@ public PermissionGroup createGroup(@NotNull String name) { return group; } - if (CONTROLLER_OR_NODE) { + if (NODE) { ExecutorAPI.getInstance() .getSyncAPI() .getDatabaseSyncAPI() @@ -158,7 +157,7 @@ public Collection getDefaultGroups() { @Override public void deleteGroup(@NotNull String name) { this.getPermissionGroup(name).ifPresent(permissionGroup -> { - if (CONTROLLER_OR_NODE) { + if (NODE) { ExecutorAPI.getInstance() .getSyncAPI() .getDatabaseSyncAPI() diff --git a/reformcloud2-applications/reformcloud2-default-application-proxy/src/main/java/systems/reformcloud/reformcloud2/proxy/application/listener/ProcessInclusionHandler.java b/reformcloud2-applications/reformcloud2-default-application-proxy/src/main/java/systems/reformcloud/reformcloud2/proxy/application/listener/ProcessInclusionHandler.java index 328119504..e0b688b79 100644 --- a/reformcloud2-applications/reformcloud2-default-application-proxy/src/main/java/systems/reformcloud/reformcloud2/proxy/application/listener/ProcessInclusionHandler.java +++ b/reformcloud2-applications/reformcloud2-default-application-proxy/src/main/java/systems/reformcloud/reformcloud2/proxy/application/listener/ProcessInclusionHandler.java @@ -25,29 +25,17 @@ package systems.reformcloud.reformcloud2.proxy.application.listener; import org.jetbrains.annotations.NotNull; -import systems.reformcloud.reformcloud2.executor.api.ExecutorType; -import systems.reformcloud.reformcloud2.executor.api.common.ExecutorAPI; import systems.reformcloud.reformcloud2.executor.api.common.event.handler.Listener; import systems.reformcloud.reformcloud2.executor.api.common.process.ProcessInformation; import systems.reformcloud.reformcloud2.executor.api.common.process.api.ProcessInclusion; -import systems.reformcloud.reformcloud2.executor.api.common.process.event.ProcessInformationConfigureEvent; import systems.reformcloud.reformcloud2.executor.api.common.process.running.events.RunningProcessPrepareEvent; import systems.reformcloud.reformcloud2.proxy.application.ProxyApplication; public final class ProcessInclusionHandler { @Listener - public void handle(final ProcessInformationConfigureEvent event) { - if (ExecutorAPI.getInstance().getType().equals(ExecutorType.CONTROLLER)) { - this.includeSelfFile(event.getInformation()); - } - } - - @Listener - public void handle(final RunningProcessPrepareEvent event) { - if (ExecutorAPI.getInstance().getType().equals(ExecutorType.NODE)) { - this.includeSelfFile(event.getRunningProcess().getProcessInformation()); - } + public void handle(final @NotNull RunningProcessPrepareEvent event) { + this.includeSelfFile(event.getRunningProcess().getProcessInformation()); } private void includeSelfFile(@NotNull ProcessInformation processInformation) { diff --git a/reformcloud2-applications/reformcloud2-default-application-signs/src/main/java/systems/reformcloud/reformcloud2/signs/application/listener/ProcessInclusionHandler.java b/reformcloud2-applications/reformcloud2-default-application-signs/src/main/java/systems/reformcloud/reformcloud2/signs/application/listener/ProcessInclusionHandler.java index 45a82cc1f..10791f3d1 100644 --- a/reformcloud2-applications/reformcloud2-default-application-signs/src/main/java/systems/reformcloud/reformcloud2/signs/application/listener/ProcessInclusionHandler.java +++ b/reformcloud2-applications/reformcloud2-default-application-signs/src/main/java/systems/reformcloud/reformcloud2/signs/application/listener/ProcessInclusionHandler.java @@ -25,29 +25,17 @@ package systems.reformcloud.reformcloud2.signs.application.listener; import org.jetbrains.annotations.NotNull; -import systems.reformcloud.reformcloud2.executor.api.ExecutorType; -import systems.reformcloud.reformcloud2.executor.api.common.ExecutorAPI; import systems.reformcloud.reformcloud2.executor.api.common.event.handler.Listener; import systems.reformcloud.reformcloud2.executor.api.common.process.ProcessInformation; import systems.reformcloud.reformcloud2.executor.api.common.process.api.ProcessInclusion; -import systems.reformcloud.reformcloud2.executor.api.common.process.event.ProcessInformationConfigureEvent; import systems.reformcloud.reformcloud2.executor.api.common.process.running.events.RunningProcessPrepareEvent; import systems.reformcloud.reformcloud2.signs.application.ReformCloudApplication; public final class ProcessInclusionHandler { @Listener - public void handle(final ProcessInformationConfigureEvent event) { - if (ExecutorAPI.getInstance().getType().equals(ExecutorType.CONTROLLER)) { - this.includeSelfFile(event.getInformation()); - } - } - - @Listener - public void handle(final RunningProcessPrepareEvent event) { - if (ExecutorAPI.getInstance().getType().equals(ExecutorType.NODE)) { - this.includeSelfFile(event.getRunningProcess().getProcessInformation()); - } + public void handle(final @NotNull RunningProcessPrepareEvent event) { + this.includeSelfFile(event.getRunningProcess().getProcessInformation()); } private void includeSelfFile(@NotNull ProcessInformation processInformation) { diff --git a/reformcloud2-applications/reformcloud2-default-application-web/src/main/java/systems/reformcloud/reformcloud2/web/WebApplication.java b/reformcloud2-applications/reformcloud2-default-application-web/src/main/java/systems/reformcloud/reformcloud2/web/WebApplication.java index ebe1b8a4d..c5dd3cd7b 100644 --- a/reformcloud2-applications/reformcloud2-default-application-web/src/main/java/systems/reformcloud/reformcloud2/web/WebApplication.java +++ b/reformcloud2-applications/reformcloud2-default-application-web/src/main/java/systems/reformcloud/reformcloud2/web/WebApplication.java @@ -24,13 +24,7 @@ */ package systems.reformcloud.reformcloud2.web; -import org.jetbrains.annotations.Nullable; -import systems.reformcloud.reformcloud2.executor.api.ExecutorType; -import systems.reformcloud.reformcloud2.executor.api.common.ExecutorAPI; import systems.reformcloud.reformcloud2.executor.api.common.application.api.Application; -import systems.reformcloud.reformcloud2.executor.api.common.application.updater.ApplicationUpdateRepository; -import systems.reformcloud.reformcloud2.executor.api.common.restapi.request.RequestListenerHandler; -import systems.reformcloud.reformcloud2.executor.controller.ControllerExecutor; import systems.reformcloud.reformcloud2.executor.node.NodeExecutor; import systems.reformcloud.reformcloud2.web.commands.WebCommand; import systems.reformcloud.reformcloud2.web.tokens.TokenDatabase; @@ -40,21 +34,9 @@ public class WebApplication extends Application { public static final WebCommand WEB_COMMAND = new WebCommand(); - public static RequestListenerHandler getListener() { - return ExecutorAPI.getInstance().getType().equals(ExecutorType.NODE) - ? NodeExecutor.getInstance().getRequestListenerHandler() - : ControllerExecutor.getInstance().getRequestListenerHandler(); - } - @Override public void onLoad() { TokenDatabase.load(); - getListener().setAuth(new TokenWebServerAuth()); - } - - @Nullable - @Override - public ApplicationUpdateRepository getUpdateRepository() { - return null; + NodeExecutor.getInstance().getRequestListenerHandler().setAuth(new TokenWebServerAuth()); } } diff --git a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/ExecutorType.java b/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/ExecutorType.java index ee52b99c2..17ca1d738 100644 --- a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/ExecutorType.java +++ b/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/ExecutorType.java @@ -29,15 +29,11 @@ public enum ExecutorType { - CONTROLLER(1, true), + NODE(1), - CLIENT(2, true), + API(2), - NODE(4, true), - - API(3, true), - - UNKNOWN(-1, false); + UNKNOWN(-1); private static final Map BY_ID = new HashMap<>(); @@ -48,25 +44,12 @@ public enum ExecutorType { } private final int id; - private final boolean supported; - ExecutorType(int id, boolean supported) { + ExecutorType(int id) { this.id = id; - this.supported = supported; - } - - /* ============================== */ - - public static ExecutorType getByID(int id) { - return BY_ID.getOrDefault(id, UNKNOWN); } public int getId() { return this.id; } - - public boolean isSupported() { - return this.supported; - } - } diff --git a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/client/Client.java b/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/client/Client.java deleted file mode 100644 index c049eb290..000000000 --- a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/client/Client.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.api.client; - -import systems.reformcloud.reformcloud2.executor.api.common.ExecutorAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.basic.ExternalAPIImplementation; -import systems.reformcloud.reformcloud2.executor.api.common.commands.manager.CommandManager; -import systems.reformcloud.reformcloud2.executor.api.common.network.client.NetworkClient; -import systems.reformcloud.reformcloud2.executor.api.common.utility.runtime.ReloadableRuntime; - -public abstract class Client extends ExternalAPIImplementation implements ReloadableRuntime { - - public static Client getInstance() { - return (Client) ExecutorAPI.getInstance(); - } - - protected abstract void bootstrap(); - - public abstract void shutdown(); - - public abstract CommandManager getCommandManager(); - - public abstract NetworkClient getNetworkClient(); -} diff --git a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/client/process/ProcessManager.java b/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/client/process/ProcessManager.java deleted file mode 100644 index 24d453917..000000000 --- a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/client/process/ProcessManager.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.api.client.process; - -import org.jetbrains.annotations.NotNull; -import systems.reformcloud.reformcloud2.executor.api.common.process.running.RunningProcess; -import systems.reformcloud.reformcloud2.executor.api.common.utility.optional.ReferencedOptional; - -import java.util.Collection; -import java.util.UUID; - -public interface ProcessManager { - - /** - * Registers the new process in the client - * - * @param runningProcess The process which should get registered - */ - void registerProcess(@NotNull RunningProcess runningProcess); - - /** - * Unregisters a process by the name - * - * @param name The name of the process which should get unregistered - */ - void unregisterProcess(@NotNull String name); - - /** - * Gets a specific process which is started in the client by the unique id - * - * @param uniqueID The unique id of the process - * @return An optional which contains the running or is empty when no process can get found with the unique id - * @see ReferencedOptional#isEmpty() - * @see ReferencedOptional#isPresent() - */ - @NotNull - ReferencedOptional getProcess(@NotNull UUID uniqueID); - - /** - * Gets a specific process which is started in the client by the name - * - * @param name The name of the process - * @return An optional which contains the running or is empty when no process can get found with the name - * @see ReferencedOptional#isEmpty() - * @see ReferencedOptional#isPresent() - */ - @NotNull - ReferencedOptional getProcess(String name); - - /** - * @return All processes which are registered in the client - */ - @NotNull - Collection getAll(); - - /** - * Handles the disconnect of a network channel from a process - * - * @param uuid The unique id of the process which is disconnected - */ - void onProcessDisconnect(@NotNull UUID uuid); - - /** - * Stops all currently running processes - */ - void stopAll(); -} diff --git a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/common/api/console/ConsoleSyncAPI.java b/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/common/api/console/ConsoleSyncAPI.java index 402a890d2..4a882be5a 100644 --- a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/common/api/console/ConsoleSyncAPI.java +++ b/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/common/api/console/ConsoleSyncAPI.java @@ -47,7 +47,7 @@ public interface ConsoleSyncAPI { String dispatchCommandAndGetResult(@NotNull String commandLine); /** - * Executes a command in the controller/node console + * Executes a command in the node console * * @param commandLine The command line which should be executed * @return The full result of messages sent by the console command diff --git a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/common/network/NetworkUtil.java b/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/common/network/NetworkUtil.java index 4bdf4f647..f57bbee90 100644 --- a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/common/network/NetworkUtil.java +++ b/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/common/network/NetworkUtil.java @@ -50,9 +50,7 @@ public final class NetworkUtil { /* ============================= */ public static final int NODE_TO_NODE_BUS = 20000; public static final int NODE_TO_NODE_QUERY_BUS = 25000; - public static final int CONTROLLER_INFORMATION_BUS = 2000; public static final int EVENT_BUS = 3000; - public static final int CONTROLLER_QUERY_BUS = 4000; public static final int PLAYER_INFORMATION_BUS = 5000; public static final int EXTERNAL_BUS = 50000; public static final int MESSAGING_BUS = 60000; diff --git a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/common/process/running/SharedRunningProcess.java b/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/common/process/running/SharedRunningProcess.java index 829688db1..9cb742537 100644 --- a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/common/process/running/SharedRunningProcess.java +++ b/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/common/process/running/SharedRunningProcess.java @@ -238,7 +238,7 @@ private boolean bootstrap0() { "-DIReallyKnowWhatIAmDoingISwear=true", "-Djline.terminal=jline.UnsupportedTerminal", "-Dreformcloud.runner.version=" + System.getProperty("reformcloud.runner.version"), - "-Dreformcloud.executor.type=3", + "-Dreformcloud.executor.type=2", "-Dreformcloud.lib.path=" + LIB_PATH, "-Dreformcloud.process.path=" + new File("reformcloud/files/" + Version.format( this.startupInformation.getProcessDetail().getTemplate().getVersion() diff --git a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/controller/Controller.java b/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/controller/Controller.java deleted file mode 100644 index 31bb544e3..000000000 --- a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/controller/Controller.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.api.controller; - -import systems.reformcloud.reformcloud2.executor.api.common.ExecutorAPI; -import systems.reformcloud.reformcloud2.executor.api.common.commands.manager.CommandManager; -import systems.reformcloud.reformcloud2.executor.api.common.network.server.NetworkServer; -import systems.reformcloud.reformcloud2.executor.api.common.utility.runtime.ReloadableRuntime; - -public abstract class Controller extends ExecutorAPI implements ReloadableRuntime { - - public static Controller getInstance() { - return (Controller) ExecutorAPI.getInstance(); - } - - protected abstract void bootstrap(); - - public abstract void shutdown() throws Exception; - - public abstract NetworkServer getNetworkServer(); - - public abstract CommandManager getCommandManager(); -} diff --git a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/controller/process/ProcessManager.java b/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/controller/process/ProcessManager.java deleted file mode 100644 index 599c3bc0c..000000000 --- a/reformcloud2-executor-api/src/main/java/systems/reformcloud/reformcloud2/executor/api/controller/process/ProcessManager.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.api.controller.process; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import systems.reformcloud.reformcloud2.executor.api.common.process.ProcessInformation; -import systems.reformcloud.reformcloud2.executor.api.common.process.api.ProcessConfiguration; -import systems.reformcloud.reformcloud2.executor.api.common.utility.update.Updateable; - -import java.util.List; -import java.util.UUID; - -public interface ProcessManager extends Iterable, Updateable { - - /** - * Gets all currently running processes - *

- * - * @return All running processes - */ - List getAllProcesses(); - - /** - * Gets all running processes of a specific group - *

- * - * @param group The name of the group - * @return A list which contains all process information about the running process - * @see ProcessInformation - */ - List getProcesses(String group); - - /** - * Gets the current online and waiting process count of a specific group - *

- * - * @param group The name of the group which should be filtered (required to be non-null) - * @return The online and waiting process count of an specific group - */ - Long getOnlineAndWaitingProcessCount(String group); - - /** - * Gets the current waiting process count of a specific group - *

- * - * @param group The name of the group which should be filtered (required to be non-null) - * @return The online and waiting process count of an specific group - */ - Integer getWaitingProcesses(String group); - - /** - * Gets a specific process by the name - *

- * - * @param name The name of the process - * @return The filtered process information or {@code null} if the process does not exists - * @see ProcessInformation - * @see #getProcess(UUID) - */ - @Nullable - ProcessInformation getProcess(String name); - - /** - * Gets a specific process by the process uniqueID - *

- * - * @param uniqueID The unique id of the process - * @return The current process information or {@code null} if the process does not exists - * @see ProcessInformation - * @see #getProcess(String) - */ - @Nullable - ProcessInformation getProcess(UUID uniqueID); - - /** - * Starts a process of the specified group and filters automatically the best template - *

- * - * @param processConfiguration The configuration of the process - * @return The process information about the created process - */ - @Nullable - ProcessInformation startProcess(@NotNull ProcessConfiguration processConfiguration); - - /** - * Starts a prepared process - * - * @param processInformation The information of the prepared process - * @return The process information after the start call - */ - @NotNull - ProcessInformation startProcess(@NotNull ProcessInformation processInformation); - - /** - * Prepares a process with the given template name and the json configuration as extra data for the process object - *

- * - * @param processConfiguration The configuration of the process which should get crated - * @return The process information of the created process - * @see ProcessInformation - */ - @Nullable - ProcessInformation prepareProcess(@NotNull ProcessConfiguration processConfiguration); - - /** - * Stops a specific process and returns the last known process information - *

- * - * @param name The name of the running process which is required to be non-null - * @return The last known process information or {@code null} if the process is unknown - * @see ProcessInformation - * @see #stopProcess(UUID) - */ - @Nullable - ProcessInformation stopProcess(String name); - - /** - * Stops a specific process and returns the last known process information - *

- * - * @param uniqueID The unique process id which is required to be non-null - * @return The last known process information or {@code null} if the process is unknown - * @see #stopProcess(String) - */ - @Nullable - ProcessInformation stopProcess(UUID uniqueID); - - /** - * This method will be called when a client disconnects, to remove all running processes and - * let the cloud move them to the next client - *

- * - * @param clientName The name of the client which is disconnected - * @see #onChannelClose(String) - */ - void onClientDisconnect(String clientName); - - /** - * This method gets called when a channel closes - *

- * - * @param name The name of the channel sender - * @see #onClientDisconnect(String) - */ - void onChannelClose(String name); - - /** - * Unregisters a specific by the given uuid - *

- * - * @param uniqueID The uniqueID of the process information which will be used to identify the process - */ - void unregisterProcess(UUID uniqueID); -} diff --git a/reformcloud2-executor/pom.xml b/reformcloud2-executor/pom.xml index 158914d06..aafdb4eac 100644 --- a/reformcloud2-executor/pom.xml +++ b/reformcloud2-executor/pom.xml @@ -187,12 +187,11 @@ - - systems.reformcloud.reformcloud2.executor.ExecutorChooser + systems.reformcloud.reformcloud2.executor.node.NodeLauncher ${project.version} ${project.version} - + ${describe} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/ExecutorChooser.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/ExecutorChooser.java deleted file mode 100644 index 30b50b50e..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/ExecutorChooser.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor; - -import systems.reformcloud.reformcloud2.executor.api.ExecutorType; -import systems.reformcloud.reformcloud2.executor.client.ClientLauncher; -import systems.reformcloud.reformcloud2.executor.controller.ControllerLauncher; -import systems.reformcloud.reformcloud2.executor.node.NodeLauncher; - -public final class ExecutorChooser { - - public static synchronized void main(String[] args) { - ExecutorType executor = ExecutorType.getByID(toID(System.getProperty("reformcloud.executor.type", "-1"))); - if (!executor.isSupported()) { - throw new RuntimeException("Unsupported executor used!"); - } - - switch (executor) { - case CONTROLLER: { - ControllerLauncher.main(args); - break; - } - - case CLIENT: { - ClientLauncher.main(args); - break; - } - - case NODE: { - NodeLauncher.main(args); - break; - } - } - } - - private static Integer toID(String convert) { - try { - return Integer.parseInt(convert); - } catch (final Throwable throwable) { - //May cause if system variable is not set properly - return -1; - } - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/api/network/packets/out/APIBungeePacketOutPlayerServerSwitch.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/api/network/packets/out/APIBungeePacketOutPlayerServerSwitch.java index 826de028a..24ff5a87b 100644 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/api/network/packets/out/APIBungeePacketOutPlayerServerSwitch.java +++ b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/api/network/packets/out/APIBungeePacketOutPlayerServerSwitch.java @@ -55,7 +55,7 @@ public APIBungeePacketOutPlayerServerSwitch(UUID playerUniqueID, String original @Override public int getId() { - return NetworkUtil.CONTROLLER_INFORMATION_BUS + 12; + return NetworkUtil.PLAYER_INFORMATION_BUS + 1; } @Override diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/api/network/packets/out/APIPacketOutRequestIngameMessages.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/api/network/packets/out/APIPacketOutRequestIngameMessages.java index 8786e8aef..778ccb35d 100644 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/api/network/packets/out/APIPacketOutRequestIngameMessages.java +++ b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/api/network/packets/out/APIPacketOutRequestIngameMessages.java @@ -42,7 +42,7 @@ public APIPacketOutRequestIngameMessages() { @Override public int getId() { - return NetworkUtil.CONTROLLER_QUERY_BUS + 2; + return NetworkUtil.EXTERNAL_BUS + 10; } @Override diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/api/network/packets/out/APIPacketOutRequestIngameMessagesResult.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/api/network/packets/out/APIPacketOutRequestIngameMessagesResult.java index 404fd9464..f8f4f8d0a 100644 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/api/network/packets/out/APIPacketOutRequestIngameMessagesResult.java +++ b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/api/network/packets/out/APIPacketOutRequestIngameMessagesResult.java @@ -47,7 +47,7 @@ public IngameMessages getIngameMessages() { @Override public int getId() { - return NetworkUtil.CONTROLLER_QUERY_BUS + 1; + return NetworkUtil.EXTERNAL_BUS + 11; } @Override diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/ClientExecutor.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/ClientExecutor.java deleted file mode 100644 index b4d27d47f..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/ClientExecutor.java +++ /dev/null @@ -1,370 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client; - -import org.jetbrains.annotations.NotNull; -import org.reflections.Reflections; -import systems.reformcloud.reformcloud2.executor.api.ExecutorType; -import systems.reformcloud.reformcloud2.executor.api.client.Client; -import systems.reformcloud.reformcloud2.executor.api.client.process.ProcessManager; -import systems.reformcloud.reformcloud2.executor.api.common.ExecutorAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.basic.events.ExternalEventBusHandler; -import systems.reformcloud.reformcloud2.executor.api.common.application.ApplicationLoader; -import systems.reformcloud.reformcloud2.executor.api.common.application.basic.DefaultApplicationLoader; -import systems.reformcloud.reformcloud2.executor.api.common.client.basic.DefaultClientRuntimeInformation; -import systems.reformcloud.reformcloud2.executor.api.common.commands.AllowedCommandSources; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.ConsoleCommandSource; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.commands.dump.CommandDump; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.commands.shared.CommandClear; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.commands.shared.CommandHelp; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.commands.shared.CommandReload; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.commands.shared.CommandStop; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.manager.DefaultCommandManager; -import systems.reformcloud.reformcloud2.executor.api.common.commands.manager.CommandManager; -import systems.reformcloud.reformcloud2.executor.api.common.commands.source.CommandSource; -import systems.reformcloud.reformcloud2.executor.api.common.configuration.JsonConfiguration; -import systems.reformcloud.reformcloud2.executor.api.common.event.EventManager; -import systems.reformcloud.reformcloud2.executor.api.common.event.basic.DefaultEventManager; -import systems.reformcloud.reformcloud2.executor.api.common.groups.template.backend.TemplateBackendManager; -import systems.reformcloud.reformcloud2.executor.api.common.language.LanguageManager; -import systems.reformcloud.reformcloud2.executor.api.common.logger.LoggerBase; -import systems.reformcloud.reformcloud2.executor.api.common.logger.coloured.ColouredLoggerHandler; -import systems.reformcloud.reformcloud2.executor.api.common.logger.other.DefaultLoggerHandler; -import systems.reformcloud.reformcloud2.executor.api.common.network.challenge.shared.ClientChallengeAuthHandler; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.manager.DefaultChannelManager; -import systems.reformcloud.reformcloud2.executor.api.common.network.client.DefaultNetworkClient; -import systems.reformcloud.reformcloud2.executor.api.common.network.client.NetworkClient; -import systems.reformcloud.reformcloud2.executor.api.common.network.packet.Packet; -import systems.reformcloud.reformcloud2.executor.api.common.network.packet.defaults.DefaultPacketHandler; -import systems.reformcloud.reformcloud2.executor.api.common.network.packet.handler.PacketHandler; -import systems.reformcloud.reformcloud2.executor.api.common.utility.system.SystemHelper; -import systems.reformcloud.reformcloud2.executor.api.common.utility.thread.AbsoluteThread; -import systems.reformcloud.reformcloud2.executor.client.config.ClientConfig; -import systems.reformcloud.reformcloud2.executor.client.config.ClientExecutorConfig; -import systems.reformcloud.reformcloud2.executor.client.dump.ClientDumpUtil; -import systems.reformcloud.reformcloud2.executor.client.network.channel.ClientNetworkChannelReader; -import systems.reformcloud.reformcloud2.executor.client.process.ProcessQueue; -import systems.reformcloud.reformcloud2.executor.client.process.basic.DefaultProcessManager; -import systems.reformcloud.reformcloud2.executor.client.process.listeners.RunningProcessPreparedListener; -import systems.reformcloud.reformcloud2.executor.client.process.listeners.RunningProcessScreenListener; -import systems.reformcloud.reformcloud2.executor.client.process.listeners.RunningProcessStoppedListener; -import systems.reformcloud.reformcloud2.executor.controller.network.packet.ClientPacketNotifyRuntimeUpdate; - -import java.io.IOException; -import java.nio.file.Paths; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -public final class ClientExecutor extends Client { - - private static final AtomicBoolean GLOBAL_CONNECTION_STATUS = new AtomicBoolean(false); - private static ClientExecutor instance; - private static volatile boolean running = false; - private final CommandManager commandManager = new DefaultCommandManager(); - private final CommandSource console = new ConsoleCommandSource(this.commandManager); - private final NetworkClient networkClient = new DefaultNetworkClient(); - private final PacketHandler packetHandler = new DefaultPacketHandler(); - private final ProcessManager processManager = new DefaultProcessManager(); - private final ProcessQueue processQueue = new ProcessQueue(); - private final ApplicationLoader applicationLoader = new DefaultApplicationLoader(); - private LoggerBase loggerBase; - private ClientConfig clientConfig; - private DefaultClientRuntimeInformation clientRuntimeInformation; - private ClientExecutorConfig clientExecutorConfig; - - ClientExecutor() { - ExecutorAPI.setInstance(this); - super.type = ExecutorType.CLIENT; - super.loadPacketHandlers(); - - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - try { - this.shutdown(); - } catch (final Exception ex) { - ex.printStackTrace(); - } - })); - - this.bootstrap(); - } - - public static ClientExecutor getInstance() { - return instance; - } - - @Override - protected void bootstrap() { - long current = System.currentTimeMillis(); - instance = this; - - SystemHelper.deleteDirectory(Paths.get("reformcloud/temp")); - - try { - if (Boolean.getBoolean("reformcloud.disable.colours")) { - this.loggerBase = new DefaultLoggerHandler(this.commandManager); - } else { - this.loggerBase = new ColouredLoggerHandler(this.commandManager); - } - } catch (final IOException ex) { - ex.printStackTrace(); - } - - new ExternalEventBusHandler( - this.packetHandler, new DefaultEventManager() - ); - - ExecutorAPI.getInstance().getEventManager().registerListener(new RunningProcessPreparedListener()); - ExecutorAPI.getInstance().getEventManager().registerListener(new RunningProcessStoppedListener()); - ExecutorAPI.getInstance().getEventManager().registerListener(new RunningProcessScreenListener()); - - this.clientExecutorConfig = new ClientExecutorConfig(); - this.clientConfig = this.clientExecutorConfig.getClientConfig(); - this.clientRuntimeInformation = new DefaultClientRuntimeInformation( - this.clientConfig.getStartHost(), - this.clientConfig.getMaxMemory(), - this.clientConfig.getMaxProcesses(), - this.clientConfig.getName(), - this.clientConfig.getUniqueID() - ); - - this.applicationLoader.detectApplications(); - this.applicationLoader.installApplications(); - - TemplateBackendManager.registerDefaults(); - - this.registerNetworkHandlers(); - this.registerDefaultCommands(); - - this.applicationLoader.loadApplications(); - - this.doConnect(); - - this.applicationLoader.enableApplications(); - - running = true; - System.out.println(LanguageManager.get("startup-done", Long.toString(System.currentTimeMillis() - current))); - this.runConsole(); - } - - private void registerNetworkHandlers() { - new Reflections("systems.reformcloud.reformcloud2.executor.client.network.packet") - .getSubTypesOf(Packet.class) - .forEach(this.packetHandler::registerHandler); - } - - private void registerDefaultCommands() { - this.commandManager - .register(new CommandDump(new ClientDumpUtil())) - .register(CommandStop.class) - .register(new CommandReload(this)) - .register(new CommandClear(this.loggerBase)) - .register(new CommandHelp(this.commandManager)); - } - - @Override - public void reload() { - this.applicationLoader.disableApplications(); - - this.clientExecutorConfig = new ClientExecutorConfig(); - this.clientConfig = this.clientExecutorConfig.getClientConfig(); - this.clientRuntimeInformation = new DefaultClientRuntimeInformation( - this.clientConfig.getStartHost(), - this.clientConfig.getMaxMemory(), - this.clientConfig.getMaxProcesses(), - this.clientConfig.getName(), - this.clientConfig.getUniqueID() - ); - this.packetHandler.clearHandlers(); - this.packetHandler.getQueryHandler().clearQueries(); - this.commandManager.unregisterAll(); - - this.registerDefaultCommands(); - this.registerNetworkHandlers(); - - this.applicationLoader.detectApplications(); - this.applicationLoader.installApplications(); - this.applicationLoader.loadApplications(); - this.applicationLoader.enableApplications(); - - this.notifyUpdate(); - } - - @Override - public void shutdown() { - this.processQueue.interrupt(); - - this.packetHandler.clearHandlers(); - this.packetHandler.getQueryHandler().clearQueries(); - this.networkClient.disconnect(); - - this.processManager.stopAll(); - - SystemHelper.deleteDirectory(Paths.get("reformcloud/temp")); - - this.applicationLoader.disableApplications(); - } - - @Override - public CommandManager getCommandManager() { - return this.commandManager; - } - - @Override - public NetworkClient getNetworkClient() { - return this.networkClient; - } - - @Override - protected PacketHandler packetHandler() { - return this.packetHandler; - } - - @NotNull - @Override - public PacketHandler getPacketHandler() { - return this.packetHandler; - } - - public LoggerBase getLoggerBase() { - return this.loggerBase; - } - - public ProcessManager getProcessManager() { - return this.processManager; - } - - public ClientConfig getClientConfig() { - return this.clientConfig; - } - - public ClientExecutorConfig getClientExecutorConfig() { - return this.clientExecutorConfig; - } - - @NotNull - public EventManager getEventManager() { - return ExternalEventBusHandler.getInstance().getEventManager(); - } - - private void runConsole() { - String line; - - while (!Thread.currentThread().isInterrupted()) { - try { - line = this.loggerBase.readLine(); - while (!line.trim().isEmpty() && running) { - this.commandManager.dispatchCommand(this.console, AllowedCommandSources.ALL, line, System.out::println); - - line = this.loggerBase.readLine(); - } - } catch (final Throwable throwable) { - throwable.printStackTrace(); - } - } - } - - private void notifyUpdate() { - DefaultChannelManager.INSTANCE.get("Controller").ifPresent(packetSender -> { - DefaultClientRuntimeInformation information = new DefaultClientRuntimeInformation( - this.clientConfig.getStartHost(), - this.clientConfig.getMaxMemory(), - this.clientConfig.getMaxProcesses(), - this.clientConfig.getName(), - this.clientConfig.getUniqueID() - ); - - packetSender.sendPacket(new ClientPacketNotifyRuntimeUpdate(information)); - }); - } - - private void doConnect() { - if (GLOBAL_CONNECTION_STATUS.get()) { - // All connections are already open and ready ( prevents abuse ) - return; - } - - AtomicInteger atomicInteger = new AtomicInteger(1); - boolean isConnected = false; - while (atomicInteger.get() <= 10) { - System.out.println(LanguageManager.get( - "network-client-try-connect", - this.clientExecutorConfig.getClientConnectionConfig().getHost(), - Integer.toString(this.clientExecutorConfig.getClientConnectionConfig().getPort()), - atomicInteger.getAndIncrement() - )); - isConnected = this.tryConnect(); - if (isConnected) { - break; - } - - AbsoluteThread.sleep(TimeUnit.MILLISECONDS, 100); - } - - if (isConnected) { - System.out.println(LanguageManager.get( - "network-client-connect-success", - this.clientExecutorConfig.getClientConnectionConfig().getHost(), - Integer.toString(this.clientExecutorConfig.getClientConnectionConfig().getPort()), - atomicInteger.get() - )); - GLOBAL_CONNECTION_STATUS.set(true); - } else { - System.out.println(LanguageManager.get( - "network-client-connection-refused", - this.clientExecutorConfig.getClientConnectionConfig().getHost(), - Integer.toString(this.clientExecutorConfig.getClientConnectionConfig().getPort()) - )); - AbsoluteThread.sleep(TimeUnit.SECONDS, 1); - System.exit(-1); - } - } - - private boolean tryConnect() { - return this.networkClient.connect( - this.clientExecutorConfig.getClientConnectionConfig().getHost(), - this.clientExecutorConfig.getClientConnectionConfig().getPort(), - () -> new ClientNetworkChannelReader(), - new ClientChallengeAuthHandler( - this.clientExecutorConfig.getConnectionKey(), - this.clientConfig.getName(), - () -> new JsonConfiguration().add("info", this.clientRuntimeInformation), - context -> { - } // unused here - ) - ); - } - - public void handleDisconnect() { - this.processManager.stopAll(); - AbsoluteThread.sleep(TimeUnit.MILLISECONDS, 100); - - if (GLOBAL_CONNECTION_STATUS.get()) { - GLOBAL_CONNECTION_STATUS.set(false); - System.out.println(LanguageManager.get("network-client-connection-lost")); - this.doConnect(); - } - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/ClientLauncher.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/ClientLauncher.java deleted file mode 100644 index b40d261b9..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/ClientLauncher.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client; - -import systems.reformcloud.reformcloud2.executor.api.common.dependency.DependencyLoader; -import systems.reformcloud.reformcloud2.executor.api.common.language.loading.LanguageWorker; - -public final class ClientLauncher { - - public static synchronized void main(String[] args) { - LanguageWorker.doLoad(); - DependencyLoader.doLoad(); - - new ClientExecutor(); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/config/ClientConfig.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/config/ClientConfig.java deleted file mode 100644 index 566958360..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/config/ClientConfig.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.config; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.UUID; - -public final class ClientConfig { - - public static final Path PATH = Paths.get("reformcloud/config.json"); - private final int maxMemory; - private final int maxProcesses; - private final double maxCpu; - private final String startHost; - private final String name; - private final UUID uniqueID; - - public ClientConfig(int maxMemory, int maxProcesses, double maxCpu, String startHost) { - this.maxMemory = maxMemory; - this.maxProcesses = maxProcesses; - this.maxCpu = maxCpu; - this.startHost = startHost; - this.name = "Client-" + UUID.randomUUID().toString().split("-")[0]; - this.uniqueID = UUID.randomUUID(); - } - - public int getMaxMemory() { - return this.maxMemory; - } - - public int getMaxProcesses() { - return this.maxProcesses; - } - - public double getMaxCpu() { - return this.maxCpu; - } - - public String getStartHost() { - return this.startHost; - } - - public String getName() { - return this.name; - } - - public UUID getUniqueID() { - return this.uniqueID; - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/config/ClientConnectionConfig.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/config/ClientConnectionConfig.java deleted file mode 100644 index e25bfedcf..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/config/ClientConnectionConfig.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.config; - -import java.nio.file.Path; -import java.nio.file.Paths; - -public final class ClientConnectionConfig { - - public static final Path PATH = Paths.get("reformcloud/connection.json"); - private final String host; - private final int port; - - public ClientConnectionConfig(String host, int port) { - this.host = host; - this.port = port; - } - - public String getHost() { - return this.host; - } - - public int getPort() { - return this.port; - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/config/ClientExecutorConfig.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/config/ClientExecutorConfig.java deleted file mode 100644 index 57680fd11..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/config/ClientExecutorConfig.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.config; - -import com.google.gson.reflect.TypeToken; -import systems.reformcloud.reformcloud2.executor.api.common.CommonHelper; -import systems.reformcloud.reformcloud2.executor.api.common.configuration.JsonConfiguration; -import systems.reformcloud.reformcloud2.executor.api.common.logger.setup.Setup; -import systems.reformcloud.reformcloud2.executor.api.common.logger.setup.basic.DefaultSetup; -import systems.reformcloud.reformcloud2.executor.api.common.logger.setup.basic.DefaultSetupQuestion; -import systems.reformcloud.reformcloud2.executor.client.ClientExecutor; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collection; -import java.util.concurrent.atomic.AtomicReference; - -import static systems.reformcloud.reformcloud2.executor.api.common.utility.list.Streams.newCollection; -import static systems.reformcloud.reformcloud2.executor.api.common.utility.system.SystemHelper.createDirectory; - -public final class ClientExecutorConfig { - - private static final Collection PATHS = newCollection( - s -> Paths.get(s), - "reformcloud/temp", - "reformcloud/static", - "reformcloud/applications", - "reformcloud/templates", - "reformcloud/files", - "reformcloud/files/.connection" - ); - private final Setup setup = new DefaultSetup(); - private final ClientConfig clientConfig; - - private final ClientConnectionConfig clientConnectionConfig; - - private final String connectionKey; - - public ClientExecutorConfig() { - this.createDirectories(); - if (!Files.exists(ClientConfig.PATH) || !Files.exists(ClientConnectionConfig.PATH)) { - this.firstSetup(); - } - - this.clientConfig = JsonConfiguration.read(ClientConfig.PATH).get("config", new TypeToken() { - }); - this.clientConnectionConfig = JsonConfiguration.read(ClientConnectionConfig.PATH).get("config", new TypeToken() { - }); - this.connectionKey = JsonConfiguration.read("reformcloud/files/.connection/connection.json").getString("key"); - } - - private void firstSetup() { - AtomicReference startHost = new AtomicReference<>(); - AtomicReference controllerHost = new AtomicReference<>(); - this.setup.addQuestion(new DefaultSetupQuestion("Please copy the connection key into the console (controller/reformcloud/.bin/connection.json)", - "Please copy the real key", - s -> true, - s -> new JsonConfiguration().add("key", s).write("reformcloud/files/.connection/connection.json")) - ).addQuestion(new DefaultSetupQuestion("Please write the start host or domain name", - "Please write an ip address or domain name", - s -> CommonHelper.getIpAddress(s.trim()) != null, - s -> startHost.set(CommonHelper.getIpAddress(s.trim()))) - ).addQuestion(new DefaultSetupQuestion("Please enter the max memory of the client", "Please write a number bigger than 128", - s -> { - try { - int i = Integer.parseInt(s); - return i > 128; - } catch (final Throwable throwable) { - return false; - } - }, - s -> new JsonConfiguration() - .add("config", new ClientConfig(Integer.parseInt(s), -1, 99.0, startHost.get())) - .write(ClientConfig.PATH)) - ).addQuestion(new DefaultSetupQuestion("Please write the ip address or domain name of the controller", - "Please write the real ip or domain ;)", - s -> CommonHelper.getIpAddress(s.trim()) != null, - s -> controllerHost.set(CommonHelper.getIpAddress(s.trim()))) - ).addQuestion(new DefaultSetupQuestion("Please write the controller network port (default: 2008)", "The port must be bigger than 0", - s -> { - try { - int i = Integer.parseInt(s); - return i > 0; - } catch (final Throwable throwable) { - return false; - } - }, - s -> new JsonConfiguration() - .add("config", new ClientConnectionConfig(controllerHost.get(), Integer.parseInt(s))) - .write(ClientConnectionConfig.PATH)) - ).startSetup(ClientExecutor.getInstance().getLoggerBase()); - } - - private void createDirectories() { - PATHS.forEach(path -> { - if (!Files.exists(path)) { - createDirectory(path); - } - }); - } - - public String getConnectionKey() { - return this.connectionKey; - } - - public ClientConnectionConfig getClientConnectionConfig() { - return this.clientConnectionConfig; - } - - public ClientConfig getClientConfig() { - return this.clientConfig; - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/dump/ClientDumpUtil.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/dump/ClientDumpUtil.java deleted file mode 100644 index cd3003071..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/dump/ClientDumpUtil.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.dump; - -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.commands.dump.DumpUtil; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.commands.dump.basic.DefaultDumpUtil; -import systems.reformcloud.reformcloud2.executor.api.common.process.ProcessInformation; -import systems.reformcloud.reformcloud2.executor.api.common.process.running.RunningProcess; -import systems.reformcloud.reformcloud2.executor.client.ClientExecutor; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Collection; - -public class ClientDumpUtil implements DumpUtil { - - private static final DumpUtil PARENT = new DefaultDumpUtil(); - - private static final DateFormat DATE_FORMAT = new SimpleDateFormat(); - - private static void dumpProcessInfos(StringBuilder stringBuilder) { - Collection nodeProcesses = ClientExecutor.getInstance().getProcessManager().getAll(); - stringBuilder.append("--- Registered Client Processes (").append(nodeProcesses.size()).append(") ---"); - stringBuilder.append("\n"); - - if (nodeProcesses.size() > 0) { - nodeProcesses.forEach(e -> { - ProcessInformation processInformation = e.getProcessInformation(); - stringBuilder - .append("Name: ") - .append(processInformation.getProcessDetail().getName()) - .append("\n") - .append("UniqueID: ") - .append(processInformation.getProcessDetail().getProcessUniqueID()) - .append("\n") - .append("Startup Time: ") - .append(e.getStartupTime() == -1 ? "unknown" : DATE_FORMAT.format(e.getStartupTime())); - if (e.getStartupTime() != -1) { - stringBuilder - .append(" (") - .append(System.currentTimeMillis() - e.getStartupTime()) - .append("ms (") - .append((System.currentTimeMillis() - e.getStartupTime()) / 60) - .append("s) ago"); - } - - stringBuilder - .append("\n") - .append("Running: ") - .append(e.isAlive()) - .append("\n\n"); - }); - } else { - stringBuilder.append("No processes are registered on the current client").append("\n\n"); - } - } - - @Override - public void appendCurrentDump(StringBuilder stringBuilder) { - PARENT.appendCurrentDump(stringBuilder); - dumpProcessInfos(stringBuilder); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/channel/ClientNetworkChannelReader.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/channel/ClientNetworkChannelReader.java deleted file mode 100644 index 2cc71c11a..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/channel/ClientNetworkChannelReader.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.network.channel; - -import io.netty.channel.ChannelHandlerContext; -import org.jetbrains.annotations.NotNull; -import systems.reformcloud.reformcloud2.executor.api.common.language.LanguageManager; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.manager.DefaultChannelManager; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.shared.SharedNetworkChannelReader; -import systems.reformcloud.reformcloud2.executor.client.ClientExecutor; - -public class ClientNetworkChannelReader extends SharedNetworkChannelReader { - - @Override - public void channelInactive(@NotNull ChannelHandlerContext context) { - if (this.packetSender != null) { - DefaultChannelManager.INSTANCE.unregisterChannel(this.packetSender); - System.out.println(LanguageManager.get("network-channel-disconnected", this.packetSender.getName())); - ClientExecutor.getInstance().handleDisconnect(); - } - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketCopyProcess.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketCopyProcess.java deleted file mode 100644 index 9a56c9e9b..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketCopyProcess.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.network.packet; - -import io.netty.channel.ChannelHandlerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import systems.reformcloud.reformcloud2.executor.api.common.network.NetworkUtil; -import systems.reformcloud.reformcloud2.executor.api.common.network.challenge.ChallengeAuthHandler; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.NetworkChannelReader; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.PacketSender; -import systems.reformcloud.reformcloud2.executor.api.common.network.data.ProtocolBuffer; -import systems.reformcloud.reformcloud2.executor.api.common.network.handler.ChannelReaderHelper; -import systems.reformcloud.reformcloud2.executor.api.common.network.packet.Packet; -import systems.reformcloud.reformcloud2.executor.client.ClientExecutor; - -import java.util.UUID; - -public class ControllerPacketCopyProcess extends Packet { - - private UUID processUniqueID; - private String targetTemplate; - private String targetTemplateStorage; - private String targetTemplateGroup; - - public ControllerPacketCopyProcess() { - } - - public ControllerPacketCopyProcess(UUID processUniqueID, String targetTemplate, String targetTemplateStorage, String targetTemplateGroup) { - this.processUniqueID = processUniqueID; - this.targetTemplate = targetTemplate; - this.targetTemplateStorage = targetTemplateStorage; - this.targetTemplateGroup = targetTemplateGroup; - } - - @Override - public int getId() { - return NetworkUtil.CONTROLLER_INFORMATION_BUS + 8; - } - - @Override - public void handlePacketReceive(@NotNull NetworkChannelReader reader, @NotNull ChallengeAuthHandler authHandler, @NotNull ChannelReaderHelper parent, @Nullable PacketSender sender, @NotNull ChannelHandlerContext channel) { - ClientExecutor.getInstance() - .getProcessManager() - .getProcess(this.processUniqueID) - .ifPresent(e -> e.copy(this.targetTemplate, this.targetTemplateStorage, this.targetTemplateGroup)); - } - - @Override - public void write(@NotNull ProtocolBuffer buffer) { - buffer.writeUniqueId(this.processUniqueID); - buffer.writeString(this.targetTemplate); - buffer.writeString(this.targetTemplateStorage); - buffer.writeString(this.targetTemplateGroup); - } - - @Override - public void read(@NotNull ProtocolBuffer buffer) { - this.processUniqueID = buffer.readUniqueId(); - this.targetTemplate = buffer.readString(); - this.targetTemplateStorage = buffer.readString(); - this.targetTemplateGroup = buffer.readString(); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketExecuteProcessCommand.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketExecuteProcessCommand.java deleted file mode 100644 index 094344ab4..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketExecuteProcessCommand.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.network.packet; - -import io.netty.channel.ChannelHandlerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import systems.reformcloud.reformcloud2.executor.api.common.network.NetworkUtil; -import systems.reformcloud.reformcloud2.executor.api.common.network.challenge.ChallengeAuthHandler; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.NetworkChannelReader; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.PacketSender; -import systems.reformcloud.reformcloud2.executor.api.common.network.data.ProtocolBuffer; -import systems.reformcloud.reformcloud2.executor.api.common.network.handler.ChannelReaderHelper; -import systems.reformcloud.reformcloud2.executor.api.common.network.packet.Packet; -import systems.reformcloud.reformcloud2.executor.client.ClientExecutor; - -public class ControllerPacketExecuteProcessCommand extends Packet { - - private String processName; - private String command; - - public ControllerPacketExecuteProcessCommand() { - } - - public ControllerPacketExecuteProcessCommand(String processName, String command) { - this.processName = processName; - this.command = command; - } - - @Override - public int getId() { - return NetworkUtil.CONTROLLER_INFORMATION_BUS + 20; - } - - @Override - public void handlePacketReceive(@NotNull NetworkChannelReader reader, @NotNull ChallengeAuthHandler authHandler, @NotNull ChannelReaderHelper parent, @Nullable PacketSender sender, @NotNull ChannelHandlerContext channel) { - ClientExecutor.getInstance() - .getProcessManager() - .getProcess(this.processName) - .ifPresent(runningProcess -> runningProcess.sendCommand(this.command)); - } - - @Override - public void write(@NotNull ProtocolBuffer buffer) { - buffer.writeString(this.processName); - buffer.writeString(this.command); - } - - @Override - public void read(@NotNull ProtocolBuffer buffer) { - this.processName = buffer.readString(); - this.command = buffer.readString(); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketProcessDisconnected.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketProcessDisconnected.java deleted file mode 100644 index 9e5679740..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketProcessDisconnected.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.network.packet; - -import io.netty.channel.ChannelHandlerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import systems.reformcloud.reformcloud2.executor.api.common.network.NetworkUtil; -import systems.reformcloud.reformcloud2.executor.api.common.network.challenge.ChallengeAuthHandler; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.NetworkChannelReader; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.PacketSender; -import systems.reformcloud.reformcloud2.executor.api.common.network.data.ProtocolBuffer; -import systems.reformcloud.reformcloud2.executor.api.common.network.handler.ChannelReaderHelper; -import systems.reformcloud.reformcloud2.executor.api.common.network.packet.Packet; -import systems.reformcloud.reformcloud2.executor.client.ClientExecutor; - -import java.util.UUID; - -public class ControllerPacketProcessDisconnected extends Packet { - - private UUID processUniqueID; - - public ControllerPacketProcessDisconnected() { - } - - public ControllerPacketProcessDisconnected(UUID processUniqueID) { - this.processUniqueID = processUniqueID; - } - - @Override - public int getId() { - return NetworkUtil.CONTROLLER_INFORMATION_BUS + 7; - } - - @Override - public void handlePacketReceive(@NotNull NetworkChannelReader reader, @NotNull ChallengeAuthHandler authHandler, @NotNull ChannelReaderHelper parent, @Nullable PacketSender sender, @NotNull ChannelHandlerContext channel) { - ClientExecutor.getInstance().getProcessManager().onProcessDisconnect(this.processUniqueID); - } - - @Override - public void write(@NotNull ProtocolBuffer buffer) { - buffer.writeUniqueId(this.processUniqueID); - } - - @Override - public void read(@NotNull ProtocolBuffer buffer) { - this.processUniqueID = buffer.readUniqueId(); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketStartPreparedProcess.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketStartPreparedProcess.java deleted file mode 100644 index faf987ae5..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketStartPreparedProcess.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.network.packet; - -import io.netty.channel.ChannelHandlerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import systems.reformcloud.reformcloud2.executor.api.common.network.NetworkUtil; -import systems.reformcloud.reformcloud2.executor.api.common.network.challenge.ChallengeAuthHandler; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.NetworkChannelReader; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.PacketSender; -import systems.reformcloud.reformcloud2.executor.api.common.network.data.ProtocolBuffer; -import systems.reformcloud.reformcloud2.executor.api.common.network.handler.ChannelReaderHelper; -import systems.reformcloud.reformcloud2.executor.api.common.network.packet.Packet; -import systems.reformcloud.reformcloud2.executor.api.common.process.ProcessInformation; -import systems.reformcloud.reformcloud2.executor.api.common.process.ProcessState; -import systems.reformcloud.reformcloud2.executor.client.ClientExecutor; -import systems.reformcloud.reformcloud2.executor.client.process.ProcessQueue; - -public class ControllerPacketStartPreparedProcess extends Packet { - - private ProcessInformation processInformation; - - public ControllerPacketStartPreparedProcess() { - } - - public ControllerPacketStartPreparedProcess(ProcessInformation processInformation) { - this.processInformation = processInformation; - } - - @Override - public int getId() { - return NetworkUtil.CONTROLLER_INFORMATION_BUS + 14; - } - - @Override - public void handlePacketReceive(@NotNull NetworkChannelReader reader, @NotNull ChallengeAuthHandler authHandler, @NotNull ChannelReaderHelper parent, @Nullable PacketSender sender, @NotNull ChannelHandlerContext channel) { - if (this.processInformation.getProcessDetail().getProcessState().equals(ProcessState.PREPARED)) { - ClientExecutor.getInstance() - .getProcessManager() - .getProcess(this.processInformation.getProcessDetail().getProcessUniqueID()) - .ifPresent(ProcessQueue::queue); - } - } - - @Override - public void write(@NotNull ProtocolBuffer buffer) { - buffer.writeObject(this.processInformation); - } - - @Override - public void read(@NotNull ProtocolBuffer buffer) { - this.processInformation = buffer.readObject(ProcessInformation.class); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketStartProcess.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketStartProcess.java deleted file mode 100644 index b0ff89e2c..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketStartProcess.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.network.packet; - -import io.netty.channel.ChannelHandlerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import systems.reformcloud.reformcloud2.executor.api.common.network.NetworkUtil; -import systems.reformcloud.reformcloud2.executor.api.common.network.challenge.ChallengeAuthHandler; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.NetworkChannelReader; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.PacketSender; -import systems.reformcloud.reformcloud2.executor.api.common.network.data.ProtocolBuffer; -import systems.reformcloud.reformcloud2.executor.api.common.network.handler.ChannelReaderHelper; -import systems.reformcloud.reformcloud2.executor.api.common.network.packet.Packet; -import systems.reformcloud.reformcloud2.executor.api.common.process.ProcessInformation; -import systems.reformcloud.reformcloud2.executor.api.common.process.running.RunningProcess; -import systems.reformcloud.reformcloud2.executor.client.ClientExecutor; -import systems.reformcloud.reformcloud2.executor.client.process.ProcessQueue; -import systems.reformcloud.reformcloud2.executor.client.process.basic.DefaultRunningProcess; - -public class ControllerPacketStartProcess extends Packet { - - private ProcessInformation processInformation; - private boolean start; - - public ControllerPacketStartProcess() { - } - - public ControllerPacketStartProcess(ProcessInformation processInformation, boolean start) { - this.processInformation = processInformation; - this.start = start; - } - - @Override - public int getId() { - return NetworkUtil.CONTROLLER_INFORMATION_BUS + 2; - } - - @Override - public void handlePacketReceive(@NotNull NetworkChannelReader reader, @NotNull ChallengeAuthHandler authHandler, @NotNull ChannelReaderHelper parent, @Nullable PacketSender sender, @NotNull ChannelHandlerContext channel) { - if (this.start) { - ProcessQueue.queue(this.processInformation); - } else { - RunningProcess process = new DefaultRunningProcess(this.processInformation); - process.prepare().onComplete(e -> ClientExecutor.getInstance().getProcessManager().registerProcess(process)); - } - } - - @Override - public void write(@NotNull ProtocolBuffer buffer) { - buffer.writeObject(this.processInformation); - buffer.writeBoolean(this.start); - } - - @Override - public void read(@NotNull ProtocolBuffer buffer) { - this.processInformation = buffer.readObject(ProcessInformation.class); - this.start = buffer.readBoolean(); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketStopProcess.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketStopProcess.java deleted file mode 100644 index fd05a5f38..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketStopProcess.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.network.packet; - -import io.netty.channel.ChannelHandlerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import systems.reformcloud.reformcloud2.executor.api.common.network.NetworkUtil; -import systems.reformcloud.reformcloud2.executor.api.common.network.challenge.ChallengeAuthHandler; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.NetworkChannelReader; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.PacketSender; -import systems.reformcloud.reformcloud2.executor.api.common.network.data.ProtocolBuffer; -import systems.reformcloud.reformcloud2.executor.api.common.network.handler.ChannelReaderHelper; -import systems.reformcloud.reformcloud2.executor.api.common.network.packet.Packet; -import systems.reformcloud.reformcloud2.executor.api.common.process.ProcessInformation; -import systems.reformcloud.reformcloud2.executor.api.common.process.running.RunningProcess; -import systems.reformcloud.reformcloud2.executor.client.ClientExecutor; -import systems.reformcloud.reformcloud2.executor.client.process.ProcessQueue; -import systems.reformcloud.reformcloud2.executor.controller.network.packet.ClientPacketProcessStopped; - -import java.util.UUID; - -public class ControllerPacketStopProcess extends Packet { - - private UUID processUniqueID; - - public ControllerPacketStopProcess() { - } - - public ControllerPacketStopProcess(UUID processUniqueID) { - this.processUniqueID = processUniqueID; - } - - @Override - public int getId() { - return NetworkUtil.CONTROLLER_INFORMATION_BUS + 3; - } - - @Override - public void handlePacketReceive(@NotNull NetworkChannelReader reader, @NotNull ChallengeAuthHandler authHandler, @NotNull ChannelReaderHelper parent, @Nullable PacketSender sender, @NotNull ChannelHandlerContext channel) { - if (sender == null) { - return; - } - - // Check if process is currently queued - if yes remove it from queue and send the success packet - ProcessInformation queued = ProcessQueue.removeFromQueue(this.processUniqueID); - if (queued != null) { - sender.sendPacket(new ClientPacketProcessStopped( - queued.getProcessDetail().getProcessUniqueID(), - queued.getProcessDetail().getName() - )); - return; - } - - ClientExecutor.getInstance().getProcessManager().getProcess(this.processUniqueID).ifPresent(RunningProcess::shutdown); - } - - @Override - public void write(@NotNull ProtocolBuffer buffer) { - buffer.writeUniqueId(this.processUniqueID); - } - - @Override - public void read(@NotNull ProtocolBuffer buffer) { - this.processUniqueID = buffer.readUniqueId(); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketToggleScreen.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketToggleScreen.java deleted file mode 100644 index 25ed7d863..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/network/packet/ControllerPacketToggleScreen.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.network.packet; - -import io.netty.channel.ChannelHandlerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import systems.reformcloud.reformcloud2.executor.api.common.network.NetworkUtil; -import systems.reformcloud.reformcloud2.executor.api.common.network.challenge.ChallengeAuthHandler; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.NetworkChannelReader; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.PacketSender; -import systems.reformcloud.reformcloud2.executor.api.common.network.data.ProtocolBuffer; -import systems.reformcloud.reformcloud2.executor.api.common.network.handler.ChannelReaderHelper; -import systems.reformcloud.reformcloud2.executor.api.common.network.packet.Packet; -import systems.reformcloud.reformcloud2.executor.api.common.process.running.manager.SharedRunningProcessManager; - -import java.util.UUID; - -public class ControllerPacketToggleScreen extends Packet { - - private UUID processUniqueID; - - public ControllerPacketToggleScreen() { - } - - public ControllerPacketToggleScreen(UUID processUniqueID) { - this.processUniqueID = processUniqueID; - } - - @Override - public int getId() { - return NetworkUtil.CONTROLLER_INFORMATION_BUS + 10; - } - - @Override - public void handlePacketReceive(@NotNull NetworkChannelReader reader, @NotNull ChallengeAuthHandler authHandler, @NotNull ChannelReaderHelper parent, @Nullable PacketSender sender, @NotNull ChannelHandlerContext channel) { - if (sender == null) { - return; - } - - SharedRunningProcessManager.getProcessByUniqueId(this.processUniqueID).ifPresent(runningProcess -> { - if (runningProcess.getProcessScreen().isEnabledFor(sender.getName())) { - runningProcess.getProcessScreen().disableScreen(sender.getName()); - } else { - runningProcess.getProcessScreen().enableScreen(sender.getName()); - } - }); - } - - @Override - public void write(@NotNull ProtocolBuffer buffer) { - buffer.writeUniqueId(this.processUniqueID); - } - - @Override - public void read(@NotNull ProtocolBuffer buffer) { - this.processUniqueID = buffer.readUniqueId(); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/ProcessQueue.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/ProcessQueue.java deleted file mode 100644 index d297ce270..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/ProcessQueue.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.process; - -import systems.reformcloud.reformcloud2.executor.api.common.CommonHelper; -import systems.reformcloud.reformcloud2.executor.api.common.language.LanguageManager; -import systems.reformcloud.reformcloud2.executor.api.common.process.ProcessInformation; -import systems.reformcloud.reformcloud2.executor.api.common.process.running.RunningProcess; -import systems.reformcloud.reformcloud2.executor.api.common.utility.list.Streams; -import systems.reformcloud.reformcloud2.executor.api.common.utility.thread.AbsoluteThread; -import systems.reformcloud.reformcloud2.executor.client.ClientExecutor; -import systems.reformcloud.reformcloud2.executor.client.process.basic.DefaultRunningProcess; - -import java.util.UUID; -import java.util.concurrent.BlockingDeque; -import java.util.concurrent.LinkedBlockingDeque; - -public final class ProcessQueue extends AbsoluteThread { - - private static final BlockingDeque QUEUE = new LinkedBlockingDeque<>(); - - public ProcessQueue() { - this.enableDaemon().updatePriority(Thread.MIN_PRIORITY).start(); - } - - public static void queue(ProcessInformation information) { - RunningProcess runningProcess = new DefaultRunningProcess(information); - System.out.println(LanguageManager.get( - "client-process-now-in-queue", - runningProcess.getProcessInformation().getProcessDetail().getName(), - QUEUE.size() + 1 - )); - - runningProcess.prepare().onComplete(e -> { - runningProcess.handleEnqueue(); - QUEUE.offerLast(runningProcess); - }); - } - - /* ============== */ - - public static void queue(RunningProcess process) { - System.out.println(LanguageManager.get( - "client-process-now-in-queue", - process.getProcessInformation().getProcessDetail().getName(), - QUEUE.size() + 1 - )); - process.handleEnqueue(); - QUEUE.offerLast(process); - } - - public static ProcessInformation removeFromQueue(UUID uuid) { - synchronized (QUEUE) { - RunningProcess process = Streams.filterToReference(QUEUE, e -> e.getProcessInformation().getProcessDetail().getProcessUniqueID().equals(uuid)).orNothing(); - if (process == null) { - return null; - } - - QUEUE.remove(process); - return process.getProcessInformation(); - } - } - - private static boolean isStartupNowLogic() { - if (ClientExecutor.getInstance().getClientConfig().getMaxCpu() <= 0D) { - return true; - } - - return CommonHelper.cpuUsageSystem() <= ClientExecutor.getInstance().getClientConfig().getMaxCpu(); - } - - @Override - public void run() { - while (!Thread.currentThread().isInterrupted()) { - try { - RunningProcess process = QUEUE.takeFirst(); - - if (isStartupNowLogic()) { - System.out.println(LanguageManager.get( - "client-process-start", - process.getProcessInformation().getProcessDetail().getName() - )); - - if (process.bootstrap()) { - ClientExecutor.getInstance().getProcessManager().registerProcess(process); - System.out.println(LanguageManager.get( - "client-process-start-done", - process.getProcessInformation().getProcessDetail().getName() - )); - } else { - QUEUE.offerLast(process); - System.out.println(LanguageManager.get( - "client-process-start-failed", - process.getProcessInformation().getProcessDetail().getName(), - QUEUE.size() - )); - } - } else { - QUEUE.add(process); - } - } catch (final InterruptedException ignored) { - } - } - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/basic/DefaultProcessManager.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/basic/DefaultProcessManager.java deleted file mode 100644 index 1ff2b5bf7..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/basic/DefaultProcessManager.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.process.basic; - -import org.jetbrains.annotations.NotNull; -import systems.reformcloud.reformcloud2.executor.api.client.process.ProcessManager; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.manager.DefaultChannelManager; -import systems.reformcloud.reformcloud2.executor.api.common.process.running.RunningProcess; -import systems.reformcloud.reformcloud2.executor.api.common.process.running.manager.SharedRunningProcessManager; -import systems.reformcloud.reformcloud2.executor.api.common.utility.optional.ReferencedOptional; -import systems.reformcloud.reformcloud2.executor.controller.network.packet.ClientPacketProcessRegistered; - -import java.util.Collection; -import java.util.UUID; - -public final class DefaultProcessManager implements ProcessManager { - - @Override - public void registerProcess(@NotNull RunningProcess runningProcess) { - SharedRunningProcessManager.registerRunningProcess(runningProcess); - - DefaultChannelManager.INSTANCE.get("Controller").ifPresent(packetSender -> packetSender.sendPacket(new ClientPacketProcessRegistered( - runningProcess.getProcessInformation().getProcessDetail().getProcessUniqueID(), - runningProcess.getProcessInformation().getProcessDetail().getName() - ))); - } - - @Override - public void unregisterProcess(@NotNull String name) { - SharedRunningProcessManager.getProcessByName(name) - .ifPresent(e -> SharedRunningProcessManager.unregisterProcess(e.getProcessInformation().getProcessDetail().getProcessUniqueID())); - } - - @NotNull - @Override - public ReferencedOptional getProcess(@NotNull UUID uniqueID) { - return SharedRunningProcessManager.getProcessByUniqueId(uniqueID); - } - - @NotNull - @Override - public ReferencedOptional getProcess(String name) { - return SharedRunningProcessManager.getProcessByName(name); - } - - @NotNull - @Override - public Collection getAll() { - return SharedRunningProcessManager.getAllProcesses(); - } - - @Override - public void onProcessDisconnect(@NotNull UUID uuid) { - this.getProcess(uuid).ifPresent(RunningProcess::shutdown); - } - - @Override - public void stopAll() { - SharedRunningProcessManager.shutdownAll(); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/basic/DefaultRunningProcess.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/basic/DefaultRunningProcess.java deleted file mode 100644 index 3daafc044..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/basic/DefaultRunningProcess.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.process.basic; - -import org.jetbrains.annotations.NotNull; -import systems.reformcloud.reformcloud2.executor.api.common.process.ProcessInformation; -import systems.reformcloud.reformcloud2.executor.api.common.process.running.SharedRunningProcess; -import systems.reformcloud.reformcloud2.executor.api.common.process.running.env.EnvironmentBuilder; -import systems.reformcloud.reformcloud2.executor.api.common.utility.list.Duo; -import systems.reformcloud.reformcloud2.executor.client.ClientExecutor; - -public final class DefaultRunningProcess extends SharedRunningProcess { - - public DefaultRunningProcess(@NotNull ProcessInformation processInformation) { - super(processInformation); - } - - @Override - public void chooseStartupEnvironmentAndPrepare() { - EnvironmentBuilder.constructEnvFor(this); - } - - @NotNull - @Override - public Duo getAvailableConnectionHost() { - return new Duo<>( - ClientExecutor.getInstance().getClientExecutorConfig().getClientConnectionConfig().getHost(), - ClientExecutor.getInstance().getClientExecutorConfig().getClientConnectionConfig().getPort() - ); - } - - @NotNull - @Override - public String getConnectionKey() { - return ClientExecutor.getInstance().getClientExecutorConfig().getConnectionKey(); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/listeners/RunningProcessPreparedListener.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/listeners/RunningProcessPreparedListener.java deleted file mode 100644 index b42fa6059..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/listeners/RunningProcessPreparedListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.process.listeners; - -import systems.reformcloud.reformcloud2.executor.api.common.event.handler.Listener; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.manager.DefaultChannelManager; -import systems.reformcloud.reformcloud2.executor.api.common.process.running.events.RunningProcessPrepareEvent; -import systems.reformcloud.reformcloud2.executor.controller.network.packet.ClientPacketProcessPrepared; - -public class RunningProcessPreparedListener { - - @Listener - public void handle(final RunningProcessPrepareEvent event) { - DefaultChannelManager.INSTANCE.get("Controller").ifPresent(packetSender -> packetSender.sendPacket(new ClientPacketProcessPrepared( - event.getRunningProcess().getProcessInformation().getProcessDetail().getName(), - event.getRunningProcess().getProcessInformation().getProcessDetail().getProcessUniqueID(), - event.getRunningProcess().getProcessInformation().getProcessDetail().getTemplate().getName() - ))); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/listeners/RunningProcessScreenListener.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/listeners/RunningProcessScreenListener.java deleted file mode 100644 index 03118216e..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/listeners/RunningProcessScreenListener.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.process.listeners; - -import systems.reformcloud.reformcloud2.executor.api.common.event.handler.Listener; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.PacketSender; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.manager.DefaultChannelManager; -import systems.reformcloud.reformcloud2.executor.api.common.process.running.events.ProcessScreenEnabledEvent; -import systems.reformcloud.reformcloud2.executor.api.common.process.running.events.ProcessScreenEntryCachedEvent; -import systems.reformcloud.reformcloud2.executor.api.common.utility.optional.ReferencedOptional; -import systems.reformcloud.reformcloud2.executor.controller.network.packet.ClientPacketAddScreenLine; -import systems.reformcloud.reformcloud2.executor.controller.network.packet.ClientPacketScreenEnabled; - -public class RunningProcessScreenListener { - - @Listener - public void handle(final ProcessScreenEntryCachedEvent event) { - for (String receiver : event.getRunningProcessScreen().getReceivers()) { - ReferencedOptional referencedOptional = DefaultChannelManager.INSTANCE.get(receiver); - if (referencedOptional.isEmpty()) { - continue; - } - - referencedOptional.get().sendPacket(new ClientPacketAddScreenLine( - event.getRunningProcessScreen().getTargetProcess().getProcessInformation().getProcessDetail().getProcessUniqueID(), - event.getCachedLogLine() - )); - } - } - - @Listener - public void handle(final ProcessScreenEnabledEvent event) { - DefaultChannelManager.INSTANCE - .get(event.getEnabledFor()) - .ifPresent(sender -> sender.sendPacket(new ClientPacketScreenEnabled( - event.getRunningProcessScreen().getTargetProcess().getProcessInformation().getProcessDetail().getProcessUniqueID(), - event.getRunningProcessScreen().getLastLogLines() - ))); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/listeners/RunningProcessStoppedListener.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/listeners/RunningProcessStoppedListener.java deleted file mode 100644 index 5866d9870..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/client/process/listeners/RunningProcessStoppedListener.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.client.process.listeners; - -import systems.reformcloud.reformcloud2.executor.api.common.event.handler.Listener; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.manager.DefaultChannelManager; -import systems.reformcloud.reformcloud2.executor.api.common.process.running.events.RunningProcessStoppedEvent; -import systems.reformcloud.reformcloud2.executor.client.ClientExecutor; -import systems.reformcloud.reformcloud2.executor.controller.network.packet.ClientPacketProcessStopped; - -public class RunningProcessStoppedListener { - - @Listener - public void handle(final RunningProcessStoppedEvent event) { - ClientExecutor.getInstance().getProcessManager().unregisterProcess(event.getRunningProcess().getProcessInformation().getProcessDetail().getName()); - DefaultChannelManager.INSTANCE.get("Controller").ifPresent(packetSender -> packetSender.sendPacket(new ClientPacketProcessStopped( - event.getRunningProcess().getProcessInformation().getProcessDetail().getProcessUniqueID(), - event.getRunningProcess().getProcessInformation().getProcessDetail().getName() - ))); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/ControllerExecutor.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/ControllerExecutor.java deleted file mode 100644 index 2840a43f2..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/ControllerExecutor.java +++ /dev/null @@ -1,488 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.controller; - -import org.jetbrains.annotations.NotNull; -import org.reflections.Reflections; -import systems.reformcloud.reformcloud2.executor.api.ExecutorType; -import systems.reformcloud.reformcloud2.executor.api.common.ExecutorAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.AsyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.SyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.basic.packets.api.PacketAPIProcessCopyByName; -import systems.reformcloud.reformcloud2.executor.api.common.api.basic.packets.api.PacketAPIProcessCopyByUniqueID; -import systems.reformcloud.reformcloud2.executor.api.common.application.ApplicationLoader; -import systems.reformcloud.reformcloud2.executor.api.common.application.basic.DefaultApplicationLoader; -import systems.reformcloud.reformcloud2.executor.api.common.client.ClientRuntimeInformation; -import systems.reformcloud.reformcloud2.executor.api.common.commands.AllowedCommandSources; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.ConsoleCommandSource; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.commands.*; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.commands.dump.CommandDump; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.commands.dump.basic.DefaultDumpUtil; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.commands.shared.CommandClear; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.commands.shared.CommandHelp; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.commands.shared.CommandReload; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.commands.shared.CommandStop; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.manager.DefaultCommandManager; -import systems.reformcloud.reformcloud2.executor.api.common.commands.manager.CommandManager; -import systems.reformcloud.reformcloud2.executor.api.common.commands.source.CommandSource; -import systems.reformcloud.reformcloud2.executor.api.common.configuration.JsonConfiguration; -import systems.reformcloud.reformcloud2.executor.api.common.database.Database; -import systems.reformcloud.reformcloud2.executor.api.common.database.basic.drivers.file.FileDatabase; -import systems.reformcloud.reformcloud2.executor.api.common.database.basic.drivers.h2.H2Database; -import systems.reformcloud.reformcloud2.executor.api.common.database.basic.drivers.mongo.MongoDatabase; -import systems.reformcloud.reformcloud2.executor.api.common.database.basic.drivers.mysql.MySQLDatabase; -import systems.reformcloud.reformcloud2.executor.api.common.database.basic.drivers.rethinkdb.RethinkDBDatabase; -import systems.reformcloud.reformcloud2.executor.api.common.database.config.DatabaseConfig; -import systems.reformcloud.reformcloud2.executor.api.common.event.EventManager; -import systems.reformcloud.reformcloud2.executor.api.common.event.basic.DefaultEventManager; -import systems.reformcloud.reformcloud2.executor.api.common.groups.task.OnlinePercentCheckerTask; -import systems.reformcloud.reformcloud2.executor.api.common.language.LanguageManager; -import systems.reformcloud.reformcloud2.executor.api.common.language.loading.LanguageWorker; -import systems.reformcloud.reformcloud2.executor.api.common.logger.LoggerBase; -import systems.reformcloud.reformcloud2.executor.api.common.logger.coloured.ColouredLoggerHandler; -import systems.reformcloud.reformcloud2.executor.api.common.logger.other.DefaultLoggerHandler; -import systems.reformcloud.reformcloud2.executor.api.common.network.challenge.packet.client.PacketOutClientChallengeRequest; -import systems.reformcloud.reformcloud2.executor.api.common.network.challenge.packet.client.PacketOutClientChallengeResponse; -import systems.reformcloud.reformcloud2.executor.api.common.network.challenge.shared.ServerChallengeAuthHandler; -import systems.reformcloud.reformcloud2.executor.api.common.network.challenge.shared.SharedChallengeProvider; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.PacketSender; -import systems.reformcloud.reformcloud2.executor.api.common.network.channel.manager.DefaultChannelManager; -import systems.reformcloud.reformcloud2.executor.api.common.network.packet.Packet; -import systems.reformcloud.reformcloud2.executor.api.common.network.packet.defaults.DefaultPacketHandler; -import systems.reformcloud.reformcloud2.executor.api.common.network.packet.handler.PacketHandler; -import systems.reformcloud.reformcloud2.executor.api.common.network.server.DefaultNetworkServer; -import systems.reformcloud.reformcloud2.executor.api.common.network.server.NetworkServer; -import systems.reformcloud.reformcloud2.executor.api.common.restapi.auth.basic.DefaultWebServerAuth; -import systems.reformcloud.reformcloud2.executor.api.common.restapi.http.server.DefaultWebServer; -import systems.reformcloud.reformcloud2.executor.api.common.restapi.http.server.WebServer; -import systems.reformcloud.reformcloud2.executor.api.common.restapi.request.RequestListenerHandler; -import systems.reformcloud.reformcloud2.executor.api.common.restapi.request.defaults.DefaultRequestListenerHandler; -import systems.reformcloud.reformcloud2.executor.api.common.restapi.user.WebUser; -import systems.reformcloud.reformcloud2.executor.api.common.utility.StringUtil; -import systems.reformcloud.reformcloud2.executor.api.common.utility.optional.ReferencedOptional; -import systems.reformcloud.reformcloud2.executor.api.controller.Controller; -import systems.reformcloud.reformcloud2.executor.api.controller.process.ProcessManager; -import systems.reformcloud.reformcloud2.executor.client.network.packet.ControllerPacketToggleScreen; -import systems.reformcloud.reformcloud2.executor.controller.api.GeneralAPI; -import systems.reformcloud.reformcloud2.executor.controller.api.console.ConsoleAPIImplementation; -import systems.reformcloud.reformcloud2.executor.controller.api.database.DatabaseAPIImplementation; -import systems.reformcloud.reformcloud2.executor.controller.api.group.GroupAPIImplementation; -import systems.reformcloud.reformcloud2.executor.controller.api.message.ChannelMessageAPIImplementation; -import systems.reformcloud.reformcloud2.executor.controller.api.player.PlayerAPIImplementation; -import systems.reformcloud.reformcloud2.executor.controller.api.process.ProcessAPIImplementation; -import systems.reformcloud.reformcloud2.executor.controller.commands.CommandClients; -import systems.reformcloud.reformcloud2.executor.controller.config.ControllerConfig; -import systems.reformcloud.reformcloud2.executor.controller.config.ControllerExecutorConfig; -import systems.reformcloud.reformcloud2.executor.controller.network.channel.ControllerNetworkChannelReader; -import systems.reformcloud.reformcloud2.executor.controller.network.channel.ControllerNetworkSuccessHandler; -import systems.reformcloud.reformcloud2.executor.controller.network.packet.handler.PacketInAPILogoutPlayer; -import systems.reformcloud.reformcloud2.executor.controller.network.packet.handler.PacketInAPIPlayerCommandExecute; -import systems.reformcloud.reformcloud2.executor.controller.network.packet.handler.PacketInAPIPlayerLoggedIn; -import systems.reformcloud.reformcloud2.executor.controller.network.packet.handler.PacketInAPIServerSwitchPlayer; -import systems.reformcloud.reformcloud2.executor.controller.process.ClientManager; -import systems.reformcloud.reformcloud2.executor.controller.process.DefaultProcessManager; -import systems.reformcloud.reformcloud2.executor.controller.process.startup.AutoStartupHandler; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.Collections; - -public final class ControllerExecutor extends Controller { - - private static ControllerExecutor instance; - - private static volatile boolean running = false; - private final CommandManager commandManager = new DefaultCommandManager(); - private final CommandSource console = new ConsoleCommandSource(this.commandManager); - private final ApplicationLoader applicationLoader = new DefaultApplicationLoader(); - private final NetworkServer networkServer = new DefaultNetworkServer(); - private final WebServer webServer = new DefaultWebServer(); - private final PacketHandler packetHandler = new DefaultPacketHandler(); - private final ProcessManager processManager = new DefaultProcessManager(); - private final DatabaseConfig databaseConfig = new DatabaseConfig(); - private final EventManager eventManager = new DefaultEventManager(); - private LoggerBase loggerBase; - private AutoStartupHandler autoStartupHandler; - private ControllerExecutorConfig controllerExecutorConfig; - private ControllerConfig controllerConfig; - private Database database; - private RequestListenerHandler requestListenerHandler; - private SyncAPI syncAPI; - private AsyncAPI asyncAPI; - - ControllerExecutor() { - ExecutorAPI.setInstance(this); - super.type = ExecutorType.CONTROLLER; - - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - try { - this.shutdown(); - } catch (final Exception ex) { - ex.printStackTrace(); - } - }, "Shutdown-Hook")); - - this.bootstrap(); - } - - @NotNull - public static ControllerExecutor getInstance() { - if (instance == null) { - return (ControllerExecutor) Controller.getInstance(); - } - - return instance; - } - - @Override - protected void bootstrap() { - long current = System.currentTimeMillis(); - instance = this; - - try { - if (Boolean.getBoolean("reformcloud.disable.colours")) { - this.loggerBase = new DefaultLoggerHandler(this.commandManager); - } else { - this.loggerBase = new ColouredLoggerHandler(this.commandManager); - } - } catch (final IOException ex) { - ex.printStackTrace(); - } - - this.controllerExecutorConfig = new ControllerExecutorConfig(); - this.databaseConfig.load(); - - switch (this.databaseConfig.getType()) { - case FILE: { - this.database = new FileDatabase(); - this.databaseConfig.connect(this.database); - break; - } - - case H2: { - this.database = new H2Database(); - this.databaseConfig.connect(this.database); - break; - } - - case MONGO: { - this.database = new MongoDatabase(); - this.databaseConfig.connect(this.database); - break; - } - - case MYSQL: { - this.database = new MySQLDatabase(); - this.databaseConfig.connect(this.database); - break; - } - - case RETHINK_DB: { - this.database = new RethinkDBDatabase(); - this.databaseConfig.connect(this.database); - break; - } - } - - GeneralAPI generalAPI = new GeneralAPI( - new ConsoleAPIImplementation(this.commandManager), - new DatabaseAPIImplementation(this.database), - new GroupAPIImplementation(), - new PlayerAPIImplementation(this.processManager), - new ProcessAPIImplementation(this.processManager), - new ChannelMessageAPIImplementation() - ); - this.syncAPI = generalAPI; - this.asyncAPI = generalAPI; - - this.requestListenerHandler = new DefaultRequestListenerHandler(new DefaultWebServerAuth(this.getSyncAPI().getDatabaseSyncAPI())); - - this.applicationLoader.detectApplications(); - this.applicationLoader.installApplications(); - - this.controllerConfig = this.controllerExecutorConfig.getControllerConfig(); - this.controllerConfig.getNetworkListener().forEach(e -> e.forEach((host, port) -> ControllerExecutor.this.networkServer.bind( - host, - port, - () -> new ControllerNetworkChannelReader(), - new ServerChallengeAuthHandler(new SharedChallengeProvider(this.controllerExecutorConfig.getConnectionKey()), new ControllerNetworkSuccessHandler()) - ))); - - this.applicationLoader.loadApplications(); - - this.autoStartupHandler = new AutoStartupHandler(); - this.sendGroups(); - this.loadCommands(); - this.loadPacketHandlers(); - - this.getSyncAPI().getDatabaseSyncAPI().createDatabase("internal_users"); - if (this.controllerExecutorConfig.isFirstStartup()) { - final String token = StringUtil.generateString(2); - WebUser webUser = new WebUser("admin", token, Collections.singletonList("*")); - this.getSyncAPI().getDatabaseSyncAPI().insert("internal_users", webUser.getName(), "", new JsonConfiguration().add("user", webUser)); - - System.out.println(LanguageManager.get("setup-created-default-user", webUser.getName(), token)); - } - - this.controllerExecutorConfig.getControllerConfig().getHttpNetworkListener().forEach(map -> map.forEach((host, port) -> { - this.webServer.add(host, port, this.requestListenerHandler); - }) - ); - - this.applicationLoader.enableApplications(); - - if (Files.exists(Paths.get("reformcloud/.client"))) { - try { - Process process = new ProcessBuilder() - .command(Arrays.asList("java", "-jar", "runner.jar").toArray(new String[0])) - .directory(new File("reformcloud/.client")) - .start(); - ClientManager.INSTANCE.setProcess(process); - } catch (final IOException ex) { - ex.printStackTrace(); - } - } - - OnlinePercentCheckerTask.start(); - - running = true; - System.out.println(LanguageManager.get("startup-done", Long.toString(System.currentTimeMillis() - current))); - this.runConsole(); - } - - @Override - public void reload() { - final long current = System.currentTimeMillis(); - System.out.println(LanguageManager.get("runtime-try-reload")); - - OnlinePercentCheckerTask.stop(); // To update the config of the auto start, too - - this.applicationLoader.disableApplications(); - - this.commandManager.unregisterAll(); - this.packetHandler.clearHandlers(); - this.packetHandler.getQueryHandler().clearQueries(); //Unsafe? May produce exception if query is sent but not handled after reload - - this.controllerExecutorConfig.getProcessGroups().clear(); - this.controllerExecutorConfig.getMainGroups().clear(); - - this.applicationLoader.detectApplications(); - this.applicationLoader.installApplications(); - - LanguageWorker.doReload(); //Reloads the language files - - this.controllerExecutorConfig = new ControllerExecutorConfig(); - - this.autoStartupHandler.update(); //Update the automatic startup handler to re-sort the groups per priority - - this.controllerConfig = this.controllerExecutorConfig.getControllerConfig(); - - this.applicationLoader.loadApplications(); - - this.sendGroups(); - this.loadCommands(); - this.loadPacketHandlers(); - - OnlinePercentCheckerTask.start(); - - this.applicationLoader.enableApplications(); - System.out.println(LanguageManager.get("runtime-reload-done", Long.toString(System.currentTimeMillis() - current))); - } - - @Override - public void shutdown() throws Exception { - if (running) { - running = false; - } else { - return; - } - - System.out.println(LanguageManager.get("runtime-try-shutdown")); - - OnlinePercentCheckerTask.stop(); - - this.networkServer.closeAll(); //Close network first that all channels now that the controller is disconnecting - this.webServer.close(); - ClientManager.INSTANCE.onShutdown(); - - this.loggerBase.close(); - this.autoStartupHandler.interrupt(); - this.applicationLoader.disableApplications(); - } - - public ControllerExecutorConfig getControllerExecutorConfig() { - return this.controllerExecutorConfig; - } - - @NotNull - @Override - public SyncAPI getSyncAPI() { - return this.syncAPI; - } - - @NotNull - @Override - public AsyncAPI getAsyncAPI() { - return this.asyncAPI; - } - - @Override - public NetworkServer getNetworkServer() { - return this.networkServer; - } - - @NotNull - @Override - public PacketHandler getPacketHandler() { - return this.packetHandler; - } - - @Override - public CommandManager getCommandManager() { - return this.commandManager; - } - - public RequestListenerHandler getRequestListenerHandler() { - return this.requestListenerHandler; - } - - public LoggerBase getLoggerBase() { - return this.loggerBase; - } - - public ProcessManager getProcessManager() { - return this.processManager; - } - - public ControllerConfig getControllerConfig() { - return this.controllerConfig; - } - - public AutoStartupHandler getAutoStartupHandler() { - return this.autoStartupHandler; - } - - public Database getDatabase() { - return this.database; - } - - @NotNull - @Override - public EventManager getEventManager() { - return this.eventManager; - } - - @Override - public boolean isReady() { - return true; - } - - private void runConsole() { - String line; - - while (!Thread.currentThread().isInterrupted()) { - try { - line = this.loggerBase.readLine(); - while (!line.trim().isEmpty() && running) { - this.commandManager.dispatchCommand(this.console, AllowedCommandSources.ALL, line, System.out::println); - - line = this.loggerBase.readLine(); - } - } catch (final Throwable throwable) { - throwable.printStackTrace(); - } - } - } - - private void sendGroups() { - this.controllerExecutorConfig.getMainGroups().forEach(mainGroup -> System.out.println(LanguageManager.get("loading-main-group", mainGroup.getName()))); - this.controllerExecutorConfig.getProcessGroups().forEach(processGroup -> System.out.println(LanguageManager.get("loading-process-group", processGroup.getName()))); - } - - private void loadCommands() { - this.commandManager - .register(new CommandProcess(target -> { - ReferencedOptional optional = DefaultChannelManager.INSTANCE.get(target.getProcessDetail().getParentName()); - optional.ifPresent(packetSender -> packetSender.sendPacket(new ControllerPacketToggleScreen(target.getProcessDetail().getProcessUniqueID()))); - return optional.isPresent(); - })) - .register(new CommandClients()) - .register(new CommandPlayers()) - .register(new CommandGroup()) - .register(new CommandDump(new DefaultDumpUtil())) - .register(new CommandLaunch()) - .register(new CommandStop()) - .register(new CommandCreate()) - .register(new CommandReload(this)) - .register(new CommandClear(this.loggerBase)) - .register(new CommandHelp(this.commandManager)); - } - - private void loadPacketHandlers() { - new Reflections("systems.reformcloud.reformcloud2.executor.api.common.api.basic.packets.api") - .getSubTypesOf(Packet.class) - .forEach(e -> { - if (e.getSimpleName().equals("PacketAPIProcessCopy") || e.getSimpleName().equals("QueryResultPacket")) { - return; - } - - this.packetHandler.registerHandler(e); - }); - - // Copy api - this.packetHandler.registerHandler(PacketAPIProcessCopyByName.class); - this.packetHandler.registerHandler(PacketAPIProcessCopyByUniqueID.class); - - new Reflections("systems.reformcloud.reformcloud2.executor.controller.network.packet") - .getSubTypesOf(Packet.class) - .forEach(this.packetHandler::registerHandler); - - // API -> Controller handler - this.packetHandler.registerHandler(PacketInAPILogoutPlayer.class); - this.packetHandler.registerHandler(PacketInAPIPlayerCommandExecute.class); - this.packetHandler.registerHandler(PacketInAPIPlayerLoggedIn.class); - this.packetHandler.registerHandler(PacketInAPIServerSwitchPlayer.class); - - // Auth - this.packetHandler.registerHandler(PacketOutClientChallengeRequest.class); - this.packetHandler.registerHandler(PacketOutClientChallengeResponse.class); - } - - public void handleChannelDisconnect(PacketSender packetSender) { - ClientRuntimeInformation clientRuntimeInformation = ClientManager.INSTANCE.getClientRuntimeInformation() - .stream() - .filter(e -> e.getName().equals(packetSender.getName())) - .findFirst() - .orElse(null); - if (clientRuntimeInformation != null) { - ClientManager.INSTANCE.disconnectClient(clientRuntimeInformation.getName()); - } else { - this.processManager.onChannelClose(packetSender.getName()); - } - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/ControllerLauncher.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/ControllerLauncher.java deleted file mode 100644 index 27bbdb6ad..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/ControllerLauncher.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.controller; - -import systems.reformcloud.reformcloud2.executor.api.common.dependency.DependencyLoader; -import systems.reformcloud.reformcloud2.executor.api.common.language.loading.LanguageWorker; - -public final class ControllerLauncher { - - public static synchronized void main(String[] args) { - LanguageWorker.doLoad(); - DependencyLoader.doLoad(); - - new ControllerExecutor(); - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/GeneralAPI.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/GeneralAPI.java deleted file mode 100644 index b531a90fe..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/GeneralAPI.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.controller.api; - -import org.jetbrains.annotations.NotNull; -import systems.reformcloud.reformcloud2.executor.api.common.api.AsyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.SyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.console.ConsoleAsyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.console.ConsoleSyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.database.DatabaseAsyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.database.DatabaseSyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.group.GroupAsyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.group.GroupSyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.messaging.MessageAsyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.messaging.MessageSyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.player.PlayerAsyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.player.PlayerSyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.process.ProcessAsyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.process.ProcessSyncAPI; -import systems.reformcloud.reformcloud2.executor.controller.api.console.ConsoleAPIImplementation; -import systems.reformcloud.reformcloud2.executor.controller.api.database.DatabaseAPIImplementation; -import systems.reformcloud.reformcloud2.executor.controller.api.group.GroupAPIImplementation; -import systems.reformcloud.reformcloud2.executor.controller.api.message.ChannelMessageAPIImplementation; -import systems.reformcloud.reformcloud2.executor.controller.api.player.PlayerAPIImplementation; -import systems.reformcloud.reformcloud2.executor.controller.api.process.ProcessAPIImplementation; - -public class GeneralAPI implements SyncAPI, AsyncAPI { - - private final ConsoleAPIImplementation consoleAPI; - private final DatabaseAPIImplementation databaseAPI; - private final GroupAPIImplementation groupAPI; - private final PlayerAPIImplementation playerAPI; - private final ProcessAPIImplementation processAPI; - private final ChannelMessageAPIImplementation channelAPI; - - public GeneralAPI( - ConsoleAPIImplementation consoleAPI, - DatabaseAPIImplementation databaseAPI, - GroupAPIImplementation groupAPI, - PlayerAPIImplementation playerAPI, - ProcessAPIImplementation processAPI, - ChannelMessageAPIImplementation channelAPI - ) { - this.consoleAPI = consoleAPI; - this.databaseAPI = databaseAPI; - this.groupAPI = groupAPI; - this.playerAPI = playerAPI; - this.processAPI = processAPI; - this.channelAPI = channelAPI; - } - - @NotNull - @Override - public ProcessAsyncAPI getProcessAsyncAPI() { - return this.processAPI; - } - - @NotNull - @Override - public GroupAsyncAPI getGroupAsyncAPI() { - return this.groupAPI; - } - - @NotNull - @Override - public ConsoleAsyncAPI getConsoleAsyncAPI() { - return this.consoleAPI; - } - - @NotNull - @Override - public PlayerAsyncAPI getPlayerAsyncAPI() { - return this.playerAPI; - } - - @NotNull - @Override - public DatabaseAsyncAPI getDatabaseAsyncAPI() { - return this.databaseAPI; - } - - @NotNull - @Override - public MessageAsyncAPI getMessageAsyncAPI() { - return this.channelAPI; - } - - @NotNull - @Override - public ProcessSyncAPI getProcessSyncAPI() { - return this.processAPI; - } - - @NotNull - @Override - public GroupSyncAPI getGroupSyncAPI() { - return this.groupAPI; - } - - @NotNull - @Override - public ConsoleSyncAPI getConsoleSyncAPI() { - return this.consoleAPI; - } - - @NotNull - @Override - public PlayerSyncAPI getPlayerSyncAPI() { - return this.playerAPI; - } - - @NotNull - @Override - public DatabaseSyncAPI getDatabaseSyncAPI() { - return this.databaseAPI; - } - - @NotNull - @Override - public MessageSyncAPI getMessageSyncAPI() { - return this.channelAPI; - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/console/ConsoleAPIImplementation.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/console/ConsoleAPIImplementation.java deleted file mode 100644 index 67830f3da..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/console/ConsoleAPIImplementation.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.controller.api.console; - -import org.jetbrains.annotations.NotNull; -import systems.reformcloud.reformcloud2.executor.api.common.api.console.ConsoleAsyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.console.ConsoleSyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.commands.AllowedCommandSources; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.ConsoleCommandSource; -import systems.reformcloud.reformcloud2.executor.api.common.commands.basic.source.MemoryCachedCommandSource; -import systems.reformcloud.reformcloud2.executor.api.common.commands.manager.CommandManager; -import systems.reformcloud.reformcloud2.executor.api.common.commands.source.CommandSource; -import systems.reformcloud.reformcloud2.executor.api.common.utility.task.Task; -import systems.reformcloud.reformcloud2.executor.api.common.utility.task.defaults.DefaultTask; -import systems.reformcloud.reformcloud2.executor.controller.ControllerExecutor; - -import java.util.ArrayList; -import java.util.Collection; - -public class ConsoleAPIImplementation implements ConsoleSyncAPI, ConsoleAsyncAPI { - - private final CommandManager commandManager; - private final CommandSource console; - - public ConsoleAPIImplementation(CommandManager commandManager) { - this.commandManager = commandManager; - this.console = new ConsoleCommandSource(commandManager); - } - - @NotNull - @Override - public Task dispatchCommandAndGetResultAsync(@NotNull String commandLine) { - Task task = new DefaultTask<>(); - Task.EXECUTOR.execute(() -> { - this.commandManager.dispatchCommand(this.console, AllowedCommandSources.ALL, commandLine, s -> { - }); - task.complete("Success"); - }); - return task; - } - - @NotNull - @Override - public Task> dispatchConsoleCommandAndGetResultAsync(@NotNull String commandLine) { - return Task.supply(() -> { - Collection result = new ArrayList<>(); - CommandSource source = new MemoryCachedCommandSource(result, ControllerExecutor.getInstance().getCommandManager()); - - ControllerExecutor.getInstance().getCommandManager().dispatchCommand( - source, - AllowedCommandSources.ALL, - commandLine, - message -> result.add(message) - ); - return result; - }); - } - - @Override - public String dispatchCommandAndGetResult(@NotNull String commandLine) { - return this.dispatchCommandAndGetResultAsync(commandLine).getUninterruptedly(); - } - - @NotNull - @Override - public Collection dispatchConsoleCommandAndGetResult(@NotNull String commandLine) { - Collection result = this.dispatchConsoleCommandAndGetResultAsync(commandLine).getUninterruptedly(); - return result == null ? new ArrayList<>() : result; - } - - public final CommandSource getConsole() { - return this.console; - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/database/DatabaseAPIImplementation.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/database/DatabaseAPIImplementation.java deleted file mode 100644 index 9562b8238..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/database/DatabaseAPIImplementation.java +++ /dev/null @@ -1,334 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.controller.api.database; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import systems.reformcloud.reformcloud2.executor.api.common.api.database.DatabaseAsyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.database.DatabaseSyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.configuration.JsonConfiguration; -import systems.reformcloud.reformcloud2.executor.api.common.database.Database; -import systems.reformcloud.reformcloud2.executor.api.common.database.DatabaseReader; -import systems.reformcloud.reformcloud2.executor.api.common.utility.list.Streams; -import systems.reformcloud.reformcloud2.executor.api.common.utility.task.Task; -import systems.reformcloud.reformcloud2.executor.api.common.utility.task.defaults.DefaultTask; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Objects; -import java.util.concurrent.TimeUnit; -import java.util.function.Function; -import java.util.stream.Collectors; - -public class DatabaseAPIImplementation implements DatabaseAsyncAPI, DatabaseSyncAPI { - - private final Database database; - - public DatabaseAPIImplementation(Database parent) { - this.database = parent; - } - - @NotNull - @Override - public Task findAsync(@NotNull String table, @NotNull String key, String identifier) { - Task task = new DefaultTask<>(); - Task.EXECUTOR.execute(() -> { - DatabaseReader databaseReader = this.database.createForTable(table); - if (databaseReader == null) { - task.complete(null); - return; - } - - JsonConfiguration result = databaseReader.find(key).getUninterruptedly(); - if (result != null) { - task.complete(result); - } else if (identifier != null) { - task.complete(databaseReader.findIfAbsent(identifier).getUninterruptedly()); - } else { - task.complete(null); - } - }); - return task; - } - - @NotNull - @Override - public Task findAsync(@NotNull String table, @NotNull String key, String identifier, @NotNull Function function) { - Task task = new DefaultTask<>(); - Task.EXECUTOR.execute(() -> { - JsonConfiguration jsonConfiguration = this.findAsync(table, key, identifier).getUninterruptedly(); - if (jsonConfiguration != null) { - task.complete(function.apply(jsonConfiguration)); - } else { - task.complete(null); - } - }); - return task; - } - - @NotNull - @Override - public Task> getCompleteDatabaseAsync(@NotNull String table) { - return Task.supply(() -> { - DatabaseReader reader = this.database.createForTable(table); - return reader == null ? new ArrayList<>() : Streams.fromIterator(reader.iterator()); - }); - } - - @NotNull - @Override - public Task> getCompleteDatabaseAsync(@NotNull String table, @NotNull Function mapper) { - return Task.supply(() -> this.getCompleteDatabase(table).stream().map(mapper).filter(Objects::nonNull).collect(Collectors.toList())); - } - - @NotNull - @Override - public Task insertAsync(@NotNull String table, @NotNull String key, String identifier, @NotNull JsonConfiguration data) { - Task task = new DefaultTask<>(); - Task.EXECUTOR.execute(() -> { - DatabaseReader databaseReader = this.database.createForTable(table); - if (databaseReader == null) { - task.complete(null); - return; - } - - databaseReader.insert(key, identifier, data).awaitUninterruptedly(); - task.complete(null); - }); - return task; - } - - @NotNull - @Override - public Task updateAsync(@NotNull String table, @NotNull String key, @NotNull JsonConfiguration newData) { - DatabaseReader databaseReader = this.database.createForTable(table); - if (databaseReader == null) { - return Task.completedTask(false); - } - - return databaseReader.update(key, newData); - } - - @NotNull - @Override - public Task updateIfAbsentAsync(@NotNull String table, @NotNull String identifier, @NotNull JsonConfiguration newData) { - DatabaseReader databaseReader = this.database.createForTable(table); - if (databaseReader == null) { - return Task.completedTask(null); - } - - return databaseReader.updateIfAbsent(identifier, newData); - } - - @NotNull - @Override - public Task updateAsync(@NotNull String table, @Nullable String key, @Nullable String identifier, @NotNull JsonConfiguration newData) { - return Task.supply(() -> { - DatabaseReader reader = this.database.createForTable(table); - if (reader == null) { - return null; - } - - if (key != null) { - Boolean success = reader.update(key, newData).getUninterruptedly(TimeUnit.SECONDS, 5); - if (success != null && success) { - return null; - } - } - - if (identifier != null) { - reader.updateIfAbsent(identifier, newData); - } - - return null; - }); - } - - @NotNull - @Override - public Task removeAsync(@NotNull String table, @NotNull String key) { - DatabaseReader databaseReader = this.database.createForTable(table); - if (databaseReader == null) { - return Task.completedTask(null); - } - - return databaseReader.remove(key); - } - - @NotNull - @Override - public Task removeIfAbsentAsync(@NotNull String table, @NotNull String identifier) { - DatabaseReader databaseReader = this.database.createForTable(table); - if (databaseReader == null) { - return Task.completedTask(null); - } - - return databaseReader.removeIfAbsent(identifier); - } - - @NotNull - @Override - public Task removeAsync(@NotNull String table, @Nullable String key, @Nullable String identifier) { - return Task.supply(() -> { - DatabaseReader reader = this.database.createForTable(table); - if (reader == null) { - return null; - } - - if (key != null) { - reader.remove(key); - } - - if (identifier != null) { - reader.removeIfAbsent(identifier); - } - - return null; - }); - } - - @NotNull - @Override - public Task createDatabaseAsync(@NotNull String name) { - Task task = new DefaultTask<>(); - Task.EXECUTOR.execute(() -> task.complete(this.database.createDatabase(name))); - return task; - } - - @NotNull - @Override - public Task deleteDatabaseAsync(@NotNull String name) { - Task task = new DefaultTask<>(); - Task.EXECUTOR.execute(() -> task.complete(this.database.deleteDatabase(name))); - return task; - } - - @NotNull - @Override - public Task containsAsync(@NotNull String table, @NotNull String key) { - DatabaseReader databaseReader = this.database.createForTable(table); - if (databaseReader == null) { - return Task.completedTask(null); - } - - return databaseReader.contains(key); - } - - @NotNull - @Override - public Task sizeAsync(@NotNull String table) { - DatabaseReader databaseReader = this.database.createForTable(table); - if (databaseReader == null) { - return Task.completedTask(null); - } - - return databaseReader.size(); - } - - @Override - public JsonConfiguration find(@NotNull String table, @NotNull String key, String identifier) { - return this.findAsync(table, key, identifier).getUninterruptedly(); - } - - @Override - public T find(@NotNull String table, @NotNull String key, String identifier, @NotNull Function function) { - return this.findAsync(table, key, identifier, function).getUninterruptedly(); - } - - @NotNull - @Override - public Collection getCompleteDatabase(@NotNull String table) { - Collection result = this.getCompleteDatabaseAsync(table).getUninterruptedly(); - return result == null ? new ArrayList<>() : result; - } - - @NotNull - @Override - public Collection getCompleteDatabase(@NotNull String table, @NotNull Function mapper) { - Collection result = this.getCompleteDatabaseAsync(table, mapper).getUninterruptedly(); - return result == null ? new ArrayList<>() : result; - } - - @Override - public void insert(@NotNull String table, @NotNull String key, String identifier, @NotNull JsonConfiguration data) { - this.insertAsync(table, key, identifier, data).awaitUninterruptedly(); - } - - @Override - public boolean update(@NotNull String table, @NotNull String key, @NotNull JsonConfiguration newData) { - Boolean result = this.updateAsync(table, key, newData).getUninterruptedly(); - return result == null ? false : result; - } - - @Override - public boolean updateIfAbsent(@NotNull String table, @NotNull String identifier, @NotNull JsonConfiguration newData) { - Boolean result = this.updateIfAbsentAsync(table, identifier, newData).getUninterruptedly(); - return result == null ? false : result; - } - - @Override - public void update(@NotNull String table, @Nullable String key, @Nullable String identifier, @NotNull JsonConfiguration newData) { - this.updateAsync(table, key, identifier, newData).awaitUninterruptedly(); - } - - @Override - public void remove(@NotNull String table, @NotNull String key) { - this.removeAsync(table, key).awaitUninterruptedly(); - } - - @Override - public void removeIfAbsent(@NotNull String table, @NotNull String identifier) { - this.removeIfAbsentAsync(table, identifier).awaitUninterruptedly(); - } - - @Override - public void remove(@NotNull String table, @Nullable String key, @Nullable String identifier) { - this.removeAsync(table, key, identifier).awaitUninterruptedly(); - } - - @Override - public boolean createDatabase(@NotNull String name) { - Boolean result = this.createDatabaseAsync(name).getUninterruptedly(); - return result == null ? false : result; - } - - @Override - public boolean deleteDatabase(@NotNull String name) { - Boolean result = this.deleteDatabaseAsync(name).getUninterruptedly(); - return result == null ? false : result; - } - - @Override - public boolean contains(@NotNull String table, @NotNull String key) { - Boolean result = this.containsAsync(table, key).getUninterruptedly(); - return result == null ? false : result; - } - - @Override - public int size(@NotNull String table) { - Integer result = this.sizeAsync(table).getUninterruptedly(); - return result == null ? 0 : result; - } -} diff --git a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/group/GroupAPIImplementation.java b/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/group/GroupAPIImplementation.java deleted file mode 100644 index 7b6ff3117..000000000 --- a/reformcloud2-executor/src/main/java/systems/reformcloud/reformcloud2/executor/controller/api/group/GroupAPIImplementation.java +++ /dev/null @@ -1,323 +0,0 @@ -/* - * MIT License - * - * Copyright (c) ReformCloud-Team - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package systems.reformcloud.reformcloud2.executor.controller.api.group; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import systems.reformcloud.reformcloud2.executor.api.common.api.group.GroupAsyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.api.group.GroupSyncAPI; -import systems.reformcloud.reformcloud2.executor.api.common.base.Conditions; -import systems.reformcloud.reformcloud2.executor.api.common.groups.MainGroup; -import systems.reformcloud.reformcloud2.executor.api.common.groups.ProcessGroup; -import systems.reformcloud.reformcloud2.executor.api.common.groups.template.Template; -import systems.reformcloud.reformcloud2.executor.api.common.groups.utils.PlayerAccessConfiguration; -import systems.reformcloud.reformcloud2.executor.api.common.groups.utils.StartupConfiguration; -import systems.reformcloud.reformcloud2.executor.api.common.utility.list.Streams; -import systems.reformcloud.reformcloud2.executor.api.common.utility.task.Task; -import systems.reformcloud.reformcloud2.executor.api.common.utility.task.defaults.DefaultTask; -import systems.reformcloud.reformcloud2.executor.controller.ControllerExecutor; -import systems.reformcloud.reformcloud2.executor.controller.config.ControllerExecutorConfig; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class GroupAPIImplementation implements GroupAsyncAPI, GroupSyncAPI { - - private final ControllerExecutorConfig controllerExecutorConfig = ControllerExecutor.getInstance().getControllerExecutorConfig(); - - @NotNull - @Override - public Task createMainGroupAsync(@NotNull String name) { - return this.createMainGroupAsync(name, new ArrayList<>()); - } - - @NotNull - @Override - public Task createMainGroupAsync(@NotNull String name, @NotNull List subgroups) { - Task task = new DefaultTask<>(); - Task.EXECUTOR.execute(() -> { - MainGroup mainGroup = new MainGroup(name, subgroups); - task.complete(this.controllerExecutorConfig.createMainGroup(mainGroup)); - }); - return task; - } - - @NotNull - @Override - public Task createProcessGroupAsync(@NotNull String name) { - return this.createProcessGroupAsync(name, new ArrayList<>()); - } - - @NotNull - @Override - public Task createProcessGroupAsync(@NotNull String name, @NotNull List