Bridge: обновление протокола
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
group = 'asys'
|
group = 'asys'
|
||||||
version = '0.3-SNAPSHOT'
|
version = '0.4-SNAPSHOT'
|
||||||
|
|
||||||
task jar(type: Jar, overwrite: true) {
|
task jar(type: Jar, overwrite: true) {
|
||||||
// не собирать jar
|
// не собирать jar
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <dimon550@gmail.com>
|
||||||
|
* 2017-05-23
|
||||||
|
*/
|
||||||
|
package asys.mcsmanager.packets;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public class SC_SetSettings extends Packet {
|
||||||
|
private Boolean onlineMode; // 1
|
||||||
|
|
||||||
|
public SC_SetSettings() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getOnlineMode() {
|
||||||
|
return onlineMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnlineMode(Boolean onlineMode) {
|
||||||
|
this.onlineMode = onlineMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readSelfData(ByteBuf buffer) {
|
||||||
|
final int MAX_PROPERTIES = 1;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while (buffer.readableBytes() > 0 && i < MAX_PROPERTIES) {
|
||||||
|
i++;
|
||||||
|
int j = buffer.readByte();
|
||||||
|
switch (j) {
|
||||||
|
case 1:
|
||||||
|
this.onlineMode = buffer.readBoolean();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unknown param \""+j+"\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeSelfData(ByteBuf buffer) {
|
||||||
|
if (onlineMode != null) {
|
||||||
|
buffer.writeByte(1);
|
||||||
|
buffer.writeBoolean(onlineMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
group = 'asys'
|
group = 'asys'
|
||||||
version = '0.5.5-SNAPSHOT'
|
version = '0.5.6-SNAPSHOT'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven { url 'https://hub.spigotmc.org/nexus/content/groups/public/' }
|
maven { url 'https://hub.spigotmc.org/nexus/content/groups/public/' }
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package asys.bridge.bukkit;
|
|||||||
|
|
||||||
import asys.bridge.client.Client;
|
import asys.bridge.client.Client;
|
||||||
import asys.mcsmanager.packets.CS_Ping;
|
import asys.mcsmanager.packets.CS_Ping;
|
||||||
|
import asys.mcsmanager.packets.SC_SetSettings;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.core.Logger;
|
import org.apache.logging.log4j.core.Logger;
|
||||||
@@ -125,4 +126,11 @@ public class BridgePlugin extends JavaPlugin {
|
|||||||
public void setNeedReconnect(boolean needReconnect) {
|
public void setNeedReconnect(boolean needReconnect) {
|
||||||
this.needReconnect = needReconnect;
|
this.needReconnect = needReconnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSettings(SC_SetSettings packetSettings) {
|
||||||
|
if (packetSettings.getOnlineMode() != null) {
|
||||||
|
spigotServer.setOnlineMode(packetSettings.getOnlineMode());
|
||||||
|
getLogger().info("Change settings: onlineMode");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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_SetSettings.class
|
||||||
);
|
);
|
||||||
|
|
||||||
ClientPacketHandler() {
|
ClientPacketHandler() {
|
||||||
if (handshakeHandlers == null) {
|
if (handshakeHandlers == null) {
|
||||||
handshakeHandlers = ImmutableMap.of(
|
handshakeHandlers = ImmutableMap.of(
|
||||||
SC_HandshakeResult.class, this
|
SC_HandshakeResult.class, this,
|
||||||
|
SC_SetSettings.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_SetSettings) {
|
||||||
|
handleSetSettings((SC_SetSettings) 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,8 @@ public class ClientPacketHandler extends ChannelInboundHandlerAdapter implements
|
|||||||
BridgePlugin.INSTANCE.startPing(context.channel());
|
BridgePlugin.INSTANCE.startPing(context.channel());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleSetSettings(SC_SetSettings packet) {
|
||||||
|
BridgePlugin.INSTANCE.setSettings(packet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user