diff --git a/src/main/java/com/viaversion/aas/codec/packet/login/LoginAck.java b/src/main/java/com/viaversion/aas/codec/packet/login/LoginAck.java new file mode 100644 index 0000000..fdfa962 --- /dev/null +++ b/src/main/java/com/viaversion/aas/codec/packet/login/LoginAck.java @@ -0,0 +1,16 @@ +package com.viaversion.aas.codec.packet.login; + +import com.viaversion.aas.codec.packet.Packet; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import io.netty.buffer.ByteBuf; +import org.jetbrains.annotations.NotNull; + +public class LoginAck implements Packet { + @Override + public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception { + } + + @Override + public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception { + } +} 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 df1d480..6b9d038 100644 --- a/src/main/java/com/viaversion/aas/handler/state/ConfigurationState.java +++ b/src/main/java/com/viaversion/aas/handler/state/ConfigurationState.java @@ -22,7 +22,7 @@ public class ConfigurationState implements ConnectionState { @Override public void handlePacket(@NotNull MinecraftHandler handler, @NotNull ChannelHandlerContext ctx, @NotNull Packet packet) { - if (packet instanceof FinishConfig) handleFinish(handler, (FinishConfig) packet); + if (packet instanceof FinishConfig) handleFinish(handler); if (packet instanceof ConfigurationDisconnect) handleDisconnect(handler, (ConfigurationDisconnect) packet); HandlerUtilKt.forward(handler, ReferenceCountUtil.retain(packet), false); } @@ -36,7 +36,8 @@ public class ConfigurationState implements ConnectionState { ); } - private void handleFinish(MinecraftHandler handler, FinishConfig packet) { + private void handleFinish(MinecraftHandler handler) { + if (handler.getBackEnd()) return; handler.getData().setState(new PlayState()); } 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 fc20b53..26407e8 100644 --- a/src/main/kotlin/com/viaversion/aas/codec/packet/PacketRegistry.kt +++ b/src/main/kotlin/com/viaversion/aas/codec/packet/PacketRegistry.kt @@ -14,7 +14,6 @@ import com.viaversion.aas.codec.packet.status.StatusPing import com.viaversion.aas.codec.packet.status.StatusPong import com.viaversion.aas.codec.packet.status.StatusRequest import com.viaversion.aas.codec.packet.status.StatusResponse -import com.viaversion.aas.protocol.sharewareVersion import com.viaversion.aas.util.StacklessException import com.viaversion.viaversion.api.protocol.packet.Direction import com.viaversion.viaversion.api.protocol.packet.State @@ -56,6 +55,7 @@ object PacketRegistry { register(State.LOGIN, Direction.SERVERBOUND, ::LoginStart, Range.all(), 0) register(State.LOGIN, Direction.SERVERBOUND, ::CryptoResponse, Range.all(), 1) register(State.LOGIN, Direction.SERVERBOUND, ::PluginResponse, Range.atLeast(ProtocolVersion.v1_13), 2) + register(State.LOGIN, Direction.SERVERBOUND, ::LoginAck, Range.atLeast(ProtocolVersion.v1_20_2), 3) register(State.LOGIN, Direction.CLIENTBOUND, ::LoginDisconnect, Range.all(), 0) register(State.LOGIN, Direction.CLIENTBOUND, ::CryptoRequest, Range.all(), 1) diff --git a/src/main/kotlin/com/viaversion/aas/handler/state/LoginState.kt b/src/main/kotlin/com/viaversion/aas/handler/state/LoginState.kt index cc7e109..2969be3 100644 --- a/src/main/kotlin/com/viaversion/aas/handler/state/LoginState.kt +++ b/src/main/kotlin/com/viaversion/aas/handler/state/LoginState.kt @@ -54,10 +54,16 @@ class LoginState : ConnectionState { is LoginSuccess -> handleLoginSuccess(handler, packet) is SetCompression -> handleCompression(handler, packet) is PluginRequest -> forward(handler, packet) + is LoginAck -> handleLoginAck(handler, packet) else -> throw StacklessException("Invalid packet!") } } + private fun handleLoginAck(handler: MinecraftHandler, packet: LoginAck) { + handler.data.state = ConfigurationState() + forward(handler, packet) + } + private fun handleLoginDisconnect(handler: MinecraftHandler, packet: LoginDisconnect) { kickedByServer = true mcLogger.debug("{} disconnected on login: {}", handler.endRemoteAddress.toString(), packet.msg) @@ -90,9 +96,8 @@ class LoginState : ConnectionState { forward(handler, SetCompression().also { it.threshold = threshold }) setCompression(handler.data.frontChannel, threshold) } - handler.data.state = when { - handler.data.frontVer!!.newerThanOrEqualTo(ProtocolVersion.v1_20_2) -> ConfigurationState() - else -> PlayState() + if (handler.data.frontVer!!.olderThan(ProtocolVersion.v1_20_2)) { + handler.data.state = PlayState() } forward(handler, loginSuccess) }