From b807dd871af7b0cb3c8ad518cb8a1bbe93bcf4d2 Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 3 May 2019 20:49:00 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=92=D0=BE=D0=B7=D0=BC=D0=BE?= =?UTF-8?q?=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=BE=D1=82=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D1=8F=D1=82=D1=8C=20=D1=81=D0=BE=D0=BE=D0=B1?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=D1=81=D0=B5=D0=BC=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/command/basic/TestCommand.java | 7 +++++++ .../launchserver/websocket/WebSocketService.java | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java index 9ed6b48e..a6c3cf86 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java @@ -1,8 +1,11 @@ package ru.gravit.launchserver.command.basic; +import ru.gravit.launcher.events.PingEvent; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.websocket.NettyServerSocketHandler; +import ru.gravit.launchserver.websocket.WebSocketFrameHandler; +import ru.gravit.launchserver.websocket.WebSocketService; import ru.gravit.utils.helper.CommonHelper; public class TestCommand extends Command { @@ -33,5 +36,9 @@ public void invoke(String... args) throws Exception { if (args[0].equals("stop")) { handler.close(); } + if (args[0].equals("eventAll")) + { + WebSocketFrameHandler.service.sendObjectAll(new PingEvent()); + } } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/WebSocketService.java b/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/WebSocketService.java index e6aad83a..0ece2748 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/WebSocketService.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/websocket/WebSocketService.java @@ -125,6 +125,20 @@ public void sendObject(ChannelHandlerContext ctx, Object obj, Type type) { ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, type))); } + public void sendObjectAll(Object obj) { + for(Channel ch : channels) + { + ch.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, ResultInterface.class))); + } + } + + public void sendObjectAll(Object obj, Type type) { + for(Channel ch : channels) + { + ch.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, type))); + } + } + public void sendObjectAndClose(ChannelHandlerContext ctx, Object obj) { ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, ResultInterface.class))).addListener(ChannelFutureListener.CLOSE); }