MCSM: отправка комманд (need fixed)
This commit is contained in:
@@ -6,6 +6,7 @@ package asys.mcsmanager;
|
||||
|
||||
import asys.mcsmanager.packets.CS_ConsoleMessage;
|
||||
import asys.mcsmanager.packets.CS_Ping;
|
||||
import asys.mcsmanager.packets.SC_Command;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||
import org.slf4j.Logger;
|
||||
@@ -41,6 +42,21 @@ public class Manager {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean sendCommand(String clientId, String command) {
|
||||
/*
|
||||
if (serverChannels.containsKey(clientId)) {
|
||||
serverChannels.get(clientId).writeAndFlush(new SC_Command(command));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
//FIXME временный костыль
|
||||
Channel channel = serverChannels.entrySet().iterator().next().getValue();
|
||||
channel.writeAndFlush(new SC_Command(command));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Дополнить информация о сервере.
|
||||
* Если сервер отсутствует в списке, информация будет потеряна.
|
||||
|
||||
@@ -27,7 +27,8 @@ class ServerPacketHandler extends ChannelInboundHandlerAdapter implements IPacke
|
||||
|
||||
private static final BiMap<Integer, Class<? extends Packet>> pingPackets = ImmutableBiMap.of(
|
||||
3, CS_Ping.class,
|
||||
4, CS_ConsoleMessage.class
|
||||
4, CS_ConsoleMessage.class,
|
||||
5, SC_Command.class
|
||||
);
|
||||
private static Map<Class<? extends Packet>, IPacketHandler> pingHandlers;
|
||||
|
||||
|
||||
@@ -31,8 +31,10 @@ public class FrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
|
||||
protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception {
|
||||
if (frame instanceof TextWebSocketFrame) {
|
||||
String requestText = ((TextWebSocketFrame)frame).text();
|
||||
logger.debug("{} received {}", ctx.channel(), requestText);
|
||||
ctx.channel().writeAndFlush(new TextWebSocketFrame("<S>"+requestText));
|
||||
if (requestText.startsWith(":")) {
|
||||
//FIXME убрать костыли
|
||||
manager.sendCommand(null, requestText.substring(1));
|
||||
}
|
||||
} else {
|
||||
logger.warn("unsupport frame type: {}", frame.getClass().getName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user