fixed configuration state on old servers

This commit is contained in:
creeper123123321 2024-03-07 11:26:17 -03:00
parent 15e77588c9
commit ba15f5459e
4 changed files with 28 additions and 6 deletions

View File

@ -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 {
}
}

View File

@ -22,7 +22,7 @@ public class ConfigurationState implements ConnectionState {
@Override @Override
public void handlePacket(@NotNull MinecraftHandler handler, @NotNull ChannelHandlerContext ctx, @NotNull Packet packet) { 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); if (packet instanceof ConfigurationDisconnect) handleDisconnect(handler, (ConfigurationDisconnect) packet);
HandlerUtilKt.forward(handler, ReferenceCountUtil.retain(packet), false); 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()); handler.getData().setState(new PlayState());
} }

View File

@ -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.StatusPong
import com.viaversion.aas.codec.packet.status.StatusRequest import com.viaversion.aas.codec.packet.status.StatusRequest
import com.viaversion.aas.codec.packet.status.StatusResponse import com.viaversion.aas.codec.packet.status.StatusResponse
import com.viaversion.aas.protocol.sharewareVersion
import com.viaversion.aas.util.StacklessException import com.viaversion.aas.util.StacklessException
import com.viaversion.viaversion.api.protocol.packet.Direction import com.viaversion.viaversion.api.protocol.packet.Direction
import com.viaversion.viaversion.api.protocol.packet.State 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, ::LoginStart, Range.all(), 0)
register(State.LOGIN, Direction.SERVERBOUND, ::CryptoResponse, Range.all(), 1) 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, ::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, ::LoginDisconnect, Range.all(), 0)
register(State.LOGIN, Direction.CLIENTBOUND, ::CryptoRequest, Range.all(), 1) register(State.LOGIN, Direction.CLIENTBOUND, ::CryptoRequest, Range.all(), 1)

View File

@ -54,10 +54,16 @@ class LoginState : ConnectionState {
is LoginSuccess -> handleLoginSuccess(handler, packet) is LoginSuccess -> handleLoginSuccess(handler, packet)
is SetCompression -> handleCompression(handler, packet) is SetCompression -> handleCompression(handler, packet)
is PluginRequest -> forward(handler, packet) is PluginRequest -> forward(handler, packet)
is LoginAck -> handleLoginAck(handler, packet)
else -> throw StacklessException("Invalid 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) { private fun handleLoginDisconnect(handler: MinecraftHandler, packet: LoginDisconnect) {
kickedByServer = true kickedByServer = true
mcLogger.debug("{} disconnected on login: {}", handler.endRemoteAddress.toString(), packet.msg) mcLogger.debug("{} disconnected on login: {}", handler.endRemoteAddress.toString(), packet.msg)
@ -90,9 +96,8 @@ class LoginState : ConnectionState {
forward(handler, SetCompression().also { it.threshold = threshold }) forward(handler, SetCompression().also { it.threshold = threshold })
setCompression(handler.data.frontChannel, threshold) setCompression(handler.data.frontChannel, threshold)
} }
handler.data.state = when { if (handler.data.frontVer!!.olderThan(ProtocolVersion.v1_20_2)) {
handler.data.frontVer!!.newerThanOrEqualTo(ProtocolVersion.v1_20_2) -> ConfigurationState() handler.data.state = PlayState()
else -> PlayState()
} }
forward(handler, loginSuccess) forward(handler, loginSuccess)
} }