[FEATURE] Система уведомлений

This commit is contained in:
Gravit 2019-11-20 20:42:43 +07:00
parent 641001f041
commit 490ba360e7
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
5 changed files with 52 additions and 26 deletions

View file

@ -84,7 +84,7 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand
service.registerCommand("serverStatus", new ServerStatusCommand(server)); service.registerCommand("serverStatus", new ServerStatusCommand(server));
service.registerCommand("checkInstall", new CheckInstallCommand(server)); service.registerCommand("checkInstall", new CheckInstallCommand(server));
service.registerCommand("multi", new MultiCommand(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("component", new ComponentCommand(server));
service.registerCommand("givePermission", new GivePermissionsCommand(server)); service.registerCommand("givePermission", new GivePermissionsCommand(server));
service.registerCommand("getPermissions", new GetPermissionsCommand(server)); service.registerCommand("getPermissions", new GetPermissionsCommand(server));

View file

@ -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));
}
}

View file

@ -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);
}
}

View file

@ -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";
}
}

View file

@ -4,6 +4,7 @@
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import pro.gravit.launcher.Launcher; import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.events.ExceptionEvent; import pro.gravit.launcher.events.ExceptionEvent;
import pro.gravit.launcher.events.NotificationEvent;
import pro.gravit.launcher.events.request.*; import pro.gravit.launcher.events.request.*;
import pro.gravit.launcher.hasher.HashedEntry; import pro.gravit.launcher.hasher.HashedEntry;
import pro.gravit.launcher.hasher.HashedEntryAdapter; import pro.gravit.launcher.hasher.HashedEntryAdapter;
@ -107,6 +108,7 @@ public void registerResults() {
results.register("exception", ExceptionEvent.class); results.register("exception", ExceptionEvent.class);
results.register("register", RegisterRequestEvent.class); results.register("register", RegisterRequestEvent.class);
results.register("setpassword", SetPasswordRequestEvent.class); results.register("setpassword", SetPasswordRequestEvent.class);
results.register("notification", NotificationEvent.class);
} }
public void registerHandler(EventHandler eventHandler) { public void registerHandler(EventHandler eventHandler) {