Fix missing server state change

This commit is contained in:
Nassim Jahnke 2023-09-25 20:10:44 +10:00
parent 3997ea70f7
commit 840770a350
2 changed files with 11 additions and 17 deletions

View File

@ -28,9 +28,8 @@ import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.IOException;
import org.checkerframework.checker.nullness.qual.Nullable;
public class NBTType extends Type<CompoundTag> {
@ -42,37 +41,31 @@ public class NBTType extends Type<CompoundTag> {
}
@Override
public CompoundTag read(ByteBuf buffer) throws Exception {
public CompoundTag read(final ByteBuf buffer) throws Exception {
return read(buffer, true);
}
@Override
public void write(ByteBuf buffer, CompoundTag object) throws Exception {
public void write(final ByteBuf buffer, final CompoundTag object) throws Exception {
write(buffer, object, "");
}
public static CompoundTag read(final ByteBuf buffer, final boolean readName) throws Exception {
final int readerIndex = buffer.readerIndex();
final byte b = buffer.readByte();
if (b == 0) {
final byte id = buffer.readByte();
if (id == 0) {
return null;
}
buffer.readerIndex(readerIndex);
final ByteBufInputStream in = new ByteBufInputStream(buffer);
final int id = in.readByte();
if (id != CompoundTag.ID) {
throw new IOException(String.format("Expected root tag to be a CompoundTag, was %s", id));
}
if (readName) {
in.skipBytes(in.readUnsignedShort());
buffer.skipBytes(buffer.readUnsignedShort());
}
final TagLimiter tagLimiter = TagLimiter.create(MAX_NBT_BYTES, MAX_NESTING_LEVEL);
final CompoundTag tag = new CompoundTag();
tag.read(in, tagLimiter);
tag.read(new ByteBufInputStream(buffer), tagLimiter);
return tag;
}

View File

@ -49,9 +49,8 @@ import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.Configur
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.ConfigurationState.BridgePhase;
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.storage.LastResourcePack;
import com.viaversion.viaversion.rewriter.SoundRewriter;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPackets1_19_4, ClientboundPackets1_20_2, ServerboundPackets1_19_4, ServerboundPackets1_20_2> {
@ -120,6 +119,9 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
registerServerbound(State.LOGIN, ServerboundLoginPackets.LOGIN_ACKNOWLEDGED.getId(), -1, wrapper -> {
wrapper.cancel();
// Overwrite the state set in the base protocol to what the server actually keeps sending
wrapper.user().getProtocolInfo().setServerState(State.PLAY);
final ConfigurationState configurationState = wrapper.user().get(ConfigurationState.class);
configurationState.setBridgePhase(BridgePhase.CONFIGURATION);
configurationState.sendQueuedPackets(wrapper.user());
@ -198,7 +200,6 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
return;
}
if (phase == BridgePhase.PROFILE_SENT || phase == BridgePhase.REENTERING_CONFIGURATION) {
// Queue packets sent by the server while we wait for the client to transition to the configuration state
configurationBridge.addPacketToQueue(packetWrapper, true);