Bridge: выполнение комманд
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
group = 'asys'
|
group = 'asys'
|
||||||
version = '0.5.3-SNAPSHOT'
|
version = '0.6-SNAPSHOT'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven { url 'https://hub.spigotmc.org/nexus/content/groups/public/' }
|
maven { url 'https://hub.spigotmc.org/nexus/content/groups/public/' }
|
||||||
|
|||||||
@@ -26,13 +26,15 @@ public class ClientPacketHandler extends ChannelInboundHandlerAdapter implements
|
|||||||
|
|
||||||
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
|
||||||
);
|
);
|
||||||
|
|
||||||
ClientPacketHandler() {
|
ClientPacketHandler() {
|
||||||
if (handshakeHandlers == null) {
|
if (handshakeHandlers == null) {
|
||||||
handshakeHandlers = ImmutableMap.of(
|
handshakeHandlers = ImmutableMap.of(
|
||||||
SC_HandshakeResult.class, this
|
SC_HandshakeResult.class, this,
|
||||||
|
SC_Command.class, this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,10 +70,17 @@ public class ClientPacketHandler extends ChannelInboundHandlerAdapter implements
|
|||||||
@Override
|
@Override
|
||||||
public void handle(Packet packet, ChannelHandlerContext context) {
|
public void handle(Packet packet, ChannelHandlerContext context) {
|
||||||
BridgePlugin.INSTANCE.getLogger().info("handle : " + packet.getClass().getSimpleName());
|
BridgePlugin.INSTANCE.getLogger().info("handle : " + packet.getClass().getSimpleName());
|
||||||
SC_HandshakeResult pkt = (SC_HandshakeResult) packet;
|
if (packet instanceof SC_HandshakeResult) {
|
||||||
if (pkt.getErrorCode() != 0) {
|
handleHandshakeResult((SC_HandshakeResult) packet, context);
|
||||||
|
} else if (packet instanceof SC_Command) {
|
||||||
|
handleCommand((SC_Command) packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleHandshakeResult(SC_HandshakeResult packet, ChannelHandlerContext context) {
|
||||||
|
if (packet.getErrorCode() != 0) {
|
||||||
BridgePlugin.INSTANCE.getLogger().severe(
|
BridgePlugin.INSTANCE.getLogger().severe(
|
||||||
String.format("Handshake: #%d %s", pkt.getErrorCode(), pkt.getMessage()));
|
String.format("Handshake: #%d %s", packet.getErrorCode(), packet.getMessage()));
|
||||||
BridgePlugin.INSTANCE.setNeedReconnect(false);
|
BridgePlugin.INSTANCE.setNeedReconnect(false);
|
||||||
} else {
|
} else {
|
||||||
context.channel().attr(KNOWN_PACKETS).set(pingPackets);
|
context.channel().attr(KNOWN_PACKETS).set(pingPackets);
|
||||||
@@ -79,4 +88,12 @@ public class ClientPacketHandler extends ChannelInboundHandlerAdapter implements
|
|||||||
BridgePlugin.INSTANCE.startPing(context.channel());
|
BridgePlugin.INSTANCE.startPing(context.channel());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleCommand(SC_Command packet) {
|
||||||
|
BridgePlugin.INSTANCE.getLogger().info("Command: " + packet.getCommand());
|
||||||
|
BridgePlugin.INSTANCE.getServer().dispatchCommand(
|
||||||
|
BridgePlugin.INSTANCE.getServer().getConsoleSender(),
|
||||||
|
packet.getCommand()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user