diff --git a/build.gradle.kts b/build.gradle.kts index 50a04ea..58ccbfe 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -60,8 +60,8 @@ dependencies { implementation(kotlin("stdlib-jdk8")) implementation(kotlin("reflect")) - val vvVer = "4.9.2" - val vbVer = "4.9.1" + val vvVer = "4.9.3-SNAPSHOT" + val vbVer = "4.9.2-SNAPSHOT" val vrVer = "3.0.5" implementation("com.viaversion:viaversion:$vvVer") { isTransitive = false } implementation("com.viaversion:viabackwards:$vbVer") { isTransitive = false } diff --git a/src/main/java/com/viaversion/aas/codec/packet/common/AbstractSingleChat.java b/src/main/java/com/viaversion/aas/codec/packet/common/AbstractSingleChat.java new file mode 100644 index 0000000..4e6320c --- /dev/null +++ b/src/main/java/com/viaversion/aas/codec/packet/common/AbstractSingleChat.java @@ -0,0 +1,64 @@ +package com.viaversion.aas.codec.packet.common; + +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.viaversion.aas.codec.packet.Packet; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; +import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.util.ComponentConverter; +import io.netty.buffer.ByteBuf; +import org.jetbrains.annotations.NotNull; + +public class AbstractSingleChat implements Packet { + private JsonElement msg; + private Tag msgTag; + + public JsonElement getMsg() { + return msg; + } + + public void setMsg(JsonElement msg) { + this.msg = msg; + } + + public Tag getMsgTag() { + return msgTag; + } + + public void setMsgTag(Tag msgTag) { + this.msgTag = msgTag; + } + + public JsonElement getMsgAsJson() { + if (msg != null) return msg; + if (msgTag != null) return JsonParser.parseString(ComponentConverter.tagComponentToJson(this.msgTag).toString()); + return null; + } + + public void setMsgForVersion(JsonElement msg, int protocolVersion) { + if (protocolVersion >= ProtocolVersion.v1_20_3.getVersion()) { + this.msgTag = ComponentConverter.jsonComponentToTag(com.viaversion.viaversion.libs.gson.JsonParser.parseString(msg.toString())); + } else { + this.msg = msg; + } + } + + @Override + public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { + if (protocolVersion < ProtocolVersion.v1_20_3.getVersion()) { + msg = JsonParser.parseString(Type.STRING.read(byteBuf)); + } else { + msgTag = Type.TAG.read(byteBuf); + } + } + + @Override + public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { + if (protocolVersion < ProtocolVersion.v1_20_3.getVersion()) { + Type.STRING.write(byteBuf, msg.toString()); + } + } + + +} \ No newline at end of file diff --git a/src/main/java/com/viaversion/aas/codec/packet/configuration/ConfigurationDisconnect.java b/src/main/java/com/viaversion/aas/codec/packet/configuration/ConfigurationDisconnect.java index 5a748b3..e697639 100644 --- a/src/main/java/com/viaversion/aas/codec/packet/configuration/ConfigurationDisconnect.java +++ b/src/main/java/com/viaversion/aas/codec/packet/configuration/ConfigurationDisconnect.java @@ -1,6 +1,6 @@ package com.viaversion.aas.codec.packet.configuration; -import com.viaversion.aas.codec.packet.common.AbstractSingleJson; +import com.viaversion.aas.codec.packet.common.AbstractSingleChat; -public class ConfigurationDisconnect extends AbstractSingleJson { +public class ConfigurationDisconnect extends AbstractSingleChat { } diff --git a/src/main/java/com/viaversion/aas/codec/packet/configuration/ConfigurationKeepAlive.java b/src/main/java/com/viaversion/aas/codec/packet/configuration/ConfigurationKeepAlive.java new file mode 100644 index 0000000..ce873a4 --- /dev/null +++ b/src/main/java/com/viaversion/aas/codec/packet/configuration/ConfigurationKeepAlive.java @@ -0,0 +1,27 @@ +package com.viaversion.aas.codec.packet.configuration; + +import com.viaversion.aas.codec.packet.Packet; +import io.netty.buffer.ByteBuf; +import org.jetbrains.annotations.NotNull; + +public class ConfigurationKeepAlive implements Packet { + private long id; + + @Override + public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { + this.id = byteBuf.readLong(); + } + + @Override + public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { + byteBuf.writeLong(this.id); + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } +} diff --git a/src/main/java/com/viaversion/aas/codec/packet/play/Kick.java b/src/main/java/com/viaversion/aas/codec/packet/play/Kick.java index 9b4ee3c..f581c98 100644 --- a/src/main/java/com/viaversion/aas/codec/packet/play/Kick.java +++ b/src/main/java/com/viaversion/aas/codec/packet/play/Kick.java @@ -1,6 +1,6 @@ package com.viaversion.aas.codec.packet.play; -import com.viaversion.aas.codec.packet.common.AbstractSingleJson; +import com.viaversion.aas.codec.packet.common.AbstractSingleChat; -public class Kick extends AbstractSingleJson { +public class Kick extends AbstractSingleChat { } diff --git a/src/main/java/com/viaversion/aas/handler/state/ConfigurationState.java b/src/main/java/com/viaversion/aas/handler/state/ConfigurationState.java index 29705f2..5cd49c0 100644 --- a/src/main/java/com/viaversion/aas/handler/state/ConfigurationState.java +++ b/src/main/java/com/viaversion/aas/handler/state/ConfigurationState.java @@ -32,7 +32,7 @@ public class ConfigurationState implements ConnectionState { UtilKt.getMcLogger().debug( "{} disconnected on config: {}", handler.endRemoteAddress.toString(), - packet.getMsg() + packet.getMsgAsJson() ); } @@ -54,7 +54,7 @@ public class ConfigurationState implements ConnectionState { public void disconnect(@NotNull MinecraftHandler handler, @NotNull String msg) { ConnectionState.DefaultImpls.disconnect(this, handler, msg); var packet = new ConfigurationDisconnect(); - packet.setMsg(new JsonPrimitive("[VIAaaS] §c$msg")); + packet.setMsgForVersion(new JsonPrimitive("[VIAaaS] §c$msg"), handler.getData().getFrontVer()); UtilKt.writeFlushClose(handler.getData().getFrontChannel(), packet, false); } diff --git a/src/main/kotlin/com/viaversion/aas/codec/packet/PacketRegistry.kt b/src/main/kotlin/com/viaversion/aas/codec/packet/PacketRegistry.kt index 9700922..e4be1ba 100644 --- a/src/main/kotlin/com/viaversion/aas/codec/packet/PacketRegistry.kt +++ b/src/main/kotlin/com/viaversion/aas/codec/packet/PacketRegistry.kt @@ -4,6 +4,7 @@ import com.google.common.collect.Range import com.google.common.collect.RangeMap import com.google.common.collect.TreeRangeMap import com.viaversion.aas.codec.packet.configuration.ConfigurationDisconnect +import com.viaversion.aas.codec.packet.configuration.ConfigurationKeepAlive import com.viaversion.aas.codec.packet.configuration.ConfigurationPluginMessage import com.viaversion.aas.codec.packet.configuration.FinishConfig import com.viaversion.aas.codec.packet.handshake.Handshake @@ -86,8 +87,10 @@ object PacketRegistry { register(State.CONFIGURATION, Direction.CLIENTBOUND, ::ConfigurationPluginMessage, Range.all(), 0) register(State.CONFIGURATION, Direction.CLIENTBOUND, ::ConfigurationDisconnect, Range.all(), 1) register(State.CONFIGURATION, Direction.CLIENTBOUND, ::FinishConfig, Range.all(), 2) + register(State.CONFIGURATION, Direction.CLIENTBOUND, ::ConfigurationKeepAlive, Range.all(), 3) register(State.CONFIGURATION, Direction.SERVERBOUND, ::ConfigurationPluginMessage, Range.all(), 1) register(State.CONFIGURATION, Direction.SERVERBOUND, ::FinishConfig, Range.all(), 2) + register(State.CONFIGURATION, Direction.SERVERBOUND, ::ConfigurationKeepAlive, Range.all(), 3) register( State.PLAY, Direction.CLIENTBOUND, ::Kick, mapOf( @@ -104,7 +107,7 @@ object PacketRegistry { ProtocolVersion.v1_19_1.singleton to ClientboundPackets1_19_1.DISCONNECT.id, ProtocolVersion.v1_19_3.singleton to ClientboundPackets1_19_3.DISCONNECT.id, ProtocolVersion.v1_19_4..ProtocolVersion.v1_20 to ClientboundPackets1_19_4.DISCONNECT.id, - ProtocolVersion.v1_20_2.singleton to ClientboundPackets1_20_2.DISCONNECT.id + ProtocolVersion.v1_20_2..ProtocolVersion.v1_20_3 to ClientboundPackets1_20_2.DISCONNECT.id ) ) register( @@ -122,19 +125,18 @@ object PacketRegistry { ProtocolVersion.v1_19_1.singleton to ClientboundPackets1_19_1.PLUGIN_MESSAGE.id, ProtocolVersion.v1_19_3.singleton to ClientboundPackets1_19_3.PLUGIN_MESSAGE.id, ProtocolVersion.v1_19_4..ProtocolVersion.v1_20 to ClientboundPackets1_19_4.PLUGIN_MESSAGE.id, - ProtocolVersion.v1_20_2.singleton to ClientboundPackets1_20_2.PLUGIN_MESSAGE.id + ProtocolVersion.v1_20_2..ProtocolVersion.v1_20_3 to ClientboundPackets1_20_2.PLUGIN_MESSAGE.id ) ) register( - State.PLAY, - Direction.CLIENTBOUND, - ::SetPlayCompression, - ProtocolVersion.v1_8.singleton, - ClientboundPackets1_8.SET_COMPRESSION.id + State.PLAY, Direction.CLIENTBOUND, ::SetPlayCompression, + ProtocolVersion.v1_8.singleton, ClientboundPackets1_8.SET_COMPRESSION.id + ) + register( + State.PLAY, Direction.SERVERBOUND, ::ConfigurationAck, mapOf( + ProtocolVersion.v1_20_2..ProtocolVersion.v1_20_3 to ServerboundPackets1_20_2.CONFIGURATION_ACKNOWLEDGED.id + ) ) - register(State.PLAY, Direction.SERVERBOUND, ::ConfigurationAck, mapOf( - ProtocolVersion.v1_20_2.singleton to ServerboundPackets1_20_2.CONFIGURATION_ACKNOWLEDGED.id - )) // todo update this to latest version register( State.PLAY, Direction.SERVERBOUND, ::ServerboundChatCommand, diff --git a/src/main/kotlin/com/viaversion/aas/handler/state/PlayState.kt b/src/main/kotlin/com/viaversion/aas/handler/state/PlayState.kt index fe70ff8..991778b 100644 --- a/src/main/kotlin/com/viaversion/aas/handler/state/PlayState.kt +++ b/src/main/kotlin/com/viaversion/aas/handler/state/PlayState.kt @@ -48,7 +48,7 @@ class PlayState : ConnectionState { mcLogger.debug( "{} disconnected on play: {}", handler.endRemoteAddress.toString(), - packet.msg + packet.msgAsJson ) } @@ -98,7 +98,7 @@ class PlayState : ConnectionState { super.disconnect(handler, msg) writeFlushClose( handler.data.frontChannel, - Kick().also { it.msg = JsonPrimitive("[VIAaaS] §c$msg") }, + Kick().also { it.setMsgForVersion(JsonPrimitive("[VIAaaS] §c$msg"), handler.data.frontVer!!) }, delay = is17(handler) ) }