diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java index 8402b32b..ab917f10 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java @@ -84,7 +84,7 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand service.registerCommand("serverStatus", new ServerStatusCommand(server)); service.registerCommand("checkInstall", new CheckInstallCommand(server)); service.registerCommand("multi", new MultiCommand(server)); - service.registerCommand("getModulus", new GetModulusCommand(server)); + service.registerCommand("notify", new NotifyCommand(server)); service.registerCommand("component", new ComponentCommand(server)); service.registerCommand("givePermission", new GivePermissionsCommand(server)); service.registerCommand("getPermissions", new GetPermissionsCommand(server)); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java deleted file mode 100644 index f5e06ad4..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/GetModulusCommand.java +++ /dev/null @@ -1,25 +0,0 @@ -package pro.gravit.launchserver.command.service; - -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.command.Command; - -public class GetModulusCommand extends Command { - public GetModulusCommand(LaunchServer server) { - super(server); - } - - @Override - public String getArgsDescription() { - return null; - } - - @Override - public String getUsageDescription() { - return null; - } - - @Override - public void invoke(String... args) { - //LogHelper.info("You publickey modulus: %s", server.publicKey.getModulus().toString(16)); - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/NotifyCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/NotifyCommand.java new file mode 100644 index 00000000..bf14beeb --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/NotifyCommand.java @@ -0,0 +1,31 @@ +package pro.gravit.launchserver.command.service; + +import pro.gravit.launcher.events.NotificationEvent; +import pro.gravit.launcher.request.WebSocketEvent; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; +import pro.gravit.launchserver.socket.WebSocketService; + +public class NotifyCommand extends Command { + public NotifyCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[head] [message]"; + } + + @Override + public String getUsageDescription() { + return "send notification to all connected client"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 2); + NotificationEvent event = new NotificationEvent(args[0], args[1]); + WebSocketService service = server.nettyServerSocketHandler.nettyServer.service; + service.sendObjectAll(event, WebSocketEvent.class); + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/NotificationEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/NotificationEvent.java new file mode 100644 index 00000000..528b7eb1 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/NotificationEvent.java @@ -0,0 +1,18 @@ +package pro.gravit.launcher.events; + +import pro.gravit.launcher.request.WebSocketEvent; + +public class NotificationEvent implements WebSocketEvent { + public final String head; + public final String message; + + public NotificationEvent(String head, String message) { + this.head = head; + this.message = message; + } + + @Override + public String getType() { + return "notification"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index 8aa7efe4..3b4afcbd 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -4,6 +4,7 @@ import com.google.gson.GsonBuilder; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.events.ExceptionEvent; +import pro.gravit.launcher.events.NotificationEvent; import pro.gravit.launcher.events.request.*; import pro.gravit.launcher.hasher.HashedEntry; import pro.gravit.launcher.hasher.HashedEntryAdapter; @@ -107,6 +108,7 @@ public void registerResults() { results.register("exception", ExceptionEvent.class); results.register("register", RegisterRequestEvent.class); results.register("setpassword", SetPasswordRequestEvent.class); + results.register("notification", NotificationEvent.class); } public void registerHandler(EventHandler eventHandler) {