MCSM: отправка комманд (need fixed)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
group = 'asys'
|
group = 'asys'
|
||||||
version = '0.8.10-SNAPSHOT'
|
version = '0.8.11-SNAPSHOT'
|
||||||
|
|
||||||
apply plugin: 'osgi'
|
apply plugin: 'osgi'
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package asys.mcsmanager;
|
|||||||
|
|
||||||
import asys.mcsmanager.packets.CS_ConsoleMessage;
|
import asys.mcsmanager.packets.CS_ConsoleMessage;
|
||||||
import asys.mcsmanager.packets.CS_Ping;
|
import asys.mcsmanager.packets.CS_Ping;
|
||||||
|
import asys.mcsmanager.packets.SC_Command;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||||
import org.slf4j.Logger;
|
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(
|
private static final BiMap<Integer, Class<? extends Packet>> pingPackets = ImmutableBiMap.of(
|
||||||
3, CS_Ping.class,
|
3, CS_Ping.class,
|
||||||
4, CS_ConsoleMessage.class
|
4, CS_ConsoleMessage.class,
|
||||||
|
5, SC_Command.class
|
||||||
);
|
);
|
||||||
private static Map<Class<? extends Packet>, IPacketHandler> pingHandlers;
|
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 {
|
protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception {
|
||||||
if (frame instanceof TextWebSocketFrame) {
|
if (frame instanceof TextWebSocketFrame) {
|
||||||
String requestText = ((TextWebSocketFrame)frame).text();
|
String requestText = ((TextWebSocketFrame)frame).text();
|
||||||
logger.debug("{} received {}", ctx.channel(), requestText);
|
if (requestText.startsWith(":")) {
|
||||||
ctx.channel().writeAndFlush(new TextWebSocketFrame("<S>"+requestText));
|
//FIXME убрать костыли
|
||||||
|
manager.sendCommand(null, requestText.substring(1));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warn("unsupport frame type: {}", frame.getClass().getName());
|
logger.warn("unsupport frame type: {}", frame.getClass().getName());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user