From 9c92ccea77d34856d43549d2e80f7404ec2adda1 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 6 Aug 2023 15:40:15 +1000 Subject: [PATCH] Finish up state switching --- .../api/protocol/AbstractProtocol.java | 16 ++++++++-- .../Protocol1_20_2To1_20.java | 30 +++++++++---------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java index cb575aac3..6eefd2aea 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java @@ -97,13 +97,20 @@ public abstract class AbstractProtocol wrapper.user().getProtocolInfo().setState(State.CONFIGURATION)); } + final ServerboundPacketType finishConfigurationPacket = finishConfigurationPacket(); + if (finishConfigurationPacket != null) { + final int id = finishConfigurationPacket.getId(); + registerServerbound(State.CONFIGURATION, id, id, wrapper -> wrapper.user().getProtocolInfo().setState(State.PLAY)); + } + + // Register the rest of the ids with no handlers if necessary if (unmappedClientboundPacketType != null && mappedClientboundPacketType != null && unmappedClientboundPacketType != mappedClientboundPacketType) { registerPacketIdChanges( @@ -221,6 +228,11 @@ public abstract class AbstractProtocol { - wrapper.user().get(ConfigurationState.class).setBridgePhase(ConfigurationState.BridgePhase.PROFILE_SENT); + wrapper.user().get(ConfigurationState.class).setBridgePhase(BridgePhase.PROFILE_SENT); + + // Set the state according to what the server expects. All packets between now and when the client + // switches to PLAY as well will be discarded after being dealt with. + wrapper.user().getProtocolInfo().setState(State.PLAY); }); registerServerbound(State.LOGIN, ServerboundLoginPackets.LOGIN_ACKNOWLEDGED.getId(), -1, wrapper -> { wrapper.cancel(); final ConfigurationState configurationState = wrapper.user().get(ConfigurationState.class); - configurationState.setBridgePhase(ConfigurationState.BridgePhase.CONFIGURATION); - // TODO: ... WE NEED TO SET THE ACTUAL STATE TO CONFIGURATON FOR PROTOCOLS DOWN THE LINE AAAAAAAAAAAAAAA - wrapper.user().getProtocolInfo().setState(State.PLAY); + configurationState.setBridgePhase(BridgePhase.CONFIGURATION); configurationState.sendQueuedPackets(wrapper.user()); }); cancelServerbound(State.LOGIN, ServerboundLoginPackets.CUSTOM_QUERY_ANSWER.getId()); - // TODO Needs baseprotocol logic or something to set to PLAY from the next version onwards registerServerbound(State.CONFIGURATION, ServerboundConfigurationPackets1_20_2.FINISH_CONFIGURATION.getId(), -1, wrapper -> { wrapper.cancel(); final ConfigurationState configurationState = wrapper.user().get(ConfigurationState.class); - configurationState.setBridgePhase(ConfigurationState.BridgePhase.NONE); + configurationState.setBridgePhase(BridgePhase.NONE); configurationState.sendQueuedPackets(wrapper.user()); configurationState.clear(); }); @@ -120,30 +122,28 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol