diff --git a/src/main/java/com/viaversion/aas/codec/packet/configuration/ConfigurationTransfer.java b/src/main/java/com/viaversion/aas/codec/packet/configuration/ConfigurationTransfer.java new file mode 100644 index 0000000..cbda332 --- /dev/null +++ b/src/main/java/com/viaversion/aas/codec/packet/configuration/ConfigurationTransfer.java @@ -0,0 +1,41 @@ +package com.viaversion.aas.codec.packet.configuration; + +import com.viaversion.aas.codec.packet.Packet; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import com.viaversion.viaversion.api.type.Type; +import io.netty.buffer.ByteBuf; +import org.jetbrains.annotations.NotNull; + +public class ConfigurationTransfer implements Packet { + + private String host; + private int port; + + @Override + public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception { + host = Type.STRING.read(byteBuf); + port = Type.VAR_INT.readPrimitive(byteBuf); + } + + @Override + public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception { + Type.STRING.write(byteBuf, host); + Type.VAR_INT.writePrimitive(byteBuf, port); + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } +} diff --git a/src/main/java/com/viaversion/aas/codec/packet/handshake/Handshake.java b/src/main/java/com/viaversion/aas/codec/packet/handshake/Handshake.java index 5a1b065..48739ae 100644 --- a/src/main/java/com/viaversion/aas/codec/packet/handshake/Handshake.java +++ b/src/main/java/com/viaversion/aas/codec/packet/handshake/Handshake.java @@ -1,6 +1,7 @@ package com.viaversion.aas.codec.packet.handshake; import com.viaversion.aas.codec.packet.Packet; +import com.viaversion.aas.util.IntendedState; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.type.Type; @@ -12,13 +13,18 @@ public class Handshake implements Packet { private String address; private int port; private State nextState; + private IntendedState intendedState; @Override public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception { protocolId = Type.VAR_INT.readPrimitive(byteBuf); address = Type.STRING.read(byteBuf); port = byteBuf.readUnsignedShort(); - nextState = State.values()[Type.VAR_INT.readPrimitive(byteBuf)]; + if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) { + intendedState = IntendedState.values()[Type.VAR_INT.readPrimitive(byteBuf) - 1]; + } else { + nextState = State.values()[Type.VAR_INT.readPrimitive(byteBuf)]; + } } @Override @@ -26,7 +32,11 @@ public class Handshake implements Packet { Type.VAR_INT.writePrimitive(byteBuf, protocolId); Type.STRING.write(byteBuf, address); byteBuf.writeShort(port); - byteBuf.writeByte(nextState.ordinal()); // var int is too small, fits in a byte + if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) { + Type.VAR_INT.writePrimitive(byteBuf, intendedState.ordinal() + 1); + } else { + byteBuf.writeByte(nextState.ordinal()); // var int is too small, fits in a byte + } } public int getProtocolId() { @@ -60,4 +70,12 @@ public class Handshake implements Packet { public void setNextState(State nextState) { this.nextState = nextState; } + + public IntendedState getIntendedState() { + return intendedState; + } + + public void setIntendedState(IntendedState intendedState) { + this.intendedState = intendedState; + } } diff --git a/src/main/java/com/viaversion/aas/codec/packet/login/CryptoRequest.java b/src/main/java/com/viaversion/aas/codec/packet/login/CryptoRequest.java index 5daf562..29486fe 100644 --- a/src/main/java/com/viaversion/aas/codec/packet/login/CryptoRequest.java +++ b/src/main/java/com/viaversion/aas/codec/packet/login/CryptoRequest.java @@ -16,6 +16,7 @@ public class CryptoRequest implements Packet { private String serverId; private PublicKey publicKey; private byte[] nonce; + private boolean authenticate; @Override public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception { @@ -30,6 +31,9 @@ public class CryptoRequest implements Packet { .generatePublic(new X509EncodedKeySpec(UtilKt.readByteArray(byteBuf, byteBuf.readUnsignedShort()))); nonce = UtilKt.readByteArray(byteBuf, byteBuf.readUnsignedShort()); } + if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) { + authenticate = byteBuf.readBoolean(); + } } @Override @@ -47,6 +51,9 @@ public class CryptoRequest implements Packet { byteBuf.writeShort(nonce.length); byteBuf.writeBytes(nonce); } + if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) { + byteBuf.writeBoolean(authenticate); + } } public String getServerId() { @@ -72,4 +79,12 @@ public class CryptoRequest implements Packet { public void setNonce(byte[] nonce) { this.nonce = nonce; } + + public boolean isAuthenticate() { + return authenticate; + } + + public void setAuthenticate(boolean authenticate) { + this.authenticate = authenticate; + } } diff --git a/src/main/java/com/viaversion/aas/util/IntendedState.java b/src/main/java/com/viaversion/aas/util/IntendedState.java new file mode 100644 index 0000000..40a6d5b --- /dev/null +++ b/src/main/java/com/viaversion/aas/util/IntendedState.java @@ -0,0 +1,20 @@ +package com.viaversion.aas.util; + +import com.viaversion.viaversion.api.protocol.packet.State; + +public enum IntendedState { + + STATUS(State.STATUS), + LOGIN(State.LOGIN), + TRANSFER(State.LOGIN); + + private final State state; + + IntendedState(State state) { + this.state = state; + } + + public State getState() { + return state; + } +} 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 2123d0f..cc47818 100644 --- a/src/main/kotlin/com/viaversion/aas/codec/packet/PacketRegistry.kt +++ b/src/main/kotlin/com/viaversion/aas/codec/packet/PacketRegistry.kt @@ -3,10 +3,7 @@ package com.viaversion.aas.codec.packet 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.configuration.* import com.viaversion.aas.codec.packet.handshake.Handshake import com.viaversion.aas.codec.packet.login.* import com.viaversion.aas.codec.packet.play.* @@ -90,6 +87,9 @@ object PacketRegistry { ProtocolVersion.v1_20_2..ProtocolVersion.v1_20_3 to ClientboundConfigurationPackets1_20_2.KEEP_ALIVE.id, ProtocolVersion.v1_20_5.singleton to ClientboundConfigurationPackets1_20_5.KEEP_ALIVE.id )) + register(State.CONFIGURATION, Direction.CLIENTBOUND, ::ConfigurationTransfer, Range.atLeast(ProtocolVersion.v1_20_5), + ClientboundConfigurationPackets1_20_5.TRANSFER.id) + register(State.CONFIGURATION, Direction.SERVERBOUND, ::ConfigurationPluginMessage, mapOf( ProtocolVersion.v1_20_2..ProtocolVersion.v1_20_3 to ServerboundConfigurationPackets1_20_2.CUSTOM_PAYLOAD.id, ProtocolVersion.v1_20_5.singleton to ServerboundConfigurationPackets1_20_5.CUSTOM_PAYLOAD.id diff --git a/src/main/kotlin/com/viaversion/aas/codec/packet/login/LoginSuccess.kt b/src/main/kotlin/com/viaversion/aas/codec/packet/login/LoginSuccess.kt index 4ed4642..6863dfc 100644 --- a/src/main/kotlin/com/viaversion/aas/codec/packet/login/LoginSuccess.kt +++ b/src/main/kotlin/com/viaversion/aas/codec/packet/login/LoginSuccess.kt @@ -13,6 +13,7 @@ class LoginSuccess : Packet { lateinit var id: UUID lateinit var username: String private val properties = mutableListOf() + private var strictErrorHandling: Boolean = false override fun decode(byteBuf: ByteBuf, protocolVersion: ProtocolVersion) { id = when { @@ -34,6 +35,9 @@ class LoginSuccess : Packet { this.properties.add(SignableProperty(name, value, signature)) } } + if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) { + strictErrorHandling = byteBuf.readBoolean() + } } override fun encode(byteBuf: ByteBuf, protocolVersion: ProtocolVersion) { @@ -55,5 +59,8 @@ class LoginSuccess : Packet { Type.OPTIONAL_STRING.write(byteBuf, property.signature) } } + if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) { + byteBuf.writeBoolean(strictErrorHandling) + } } } \ No newline at end of file