Skip to content

Commit

Permalink
Fixed join issue on enchanted.gg
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Aug 18, 2024
1 parent ac156a0 commit c7f9e80
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main/java/net/raphimc/viabedrock/protocol/BedrockProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.viaversion.viaversion.api.protocol.packet.PacketType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.exception.CancelException;
import com.viaversion.viaversion.exception.InformativeException;
import com.viaversion.viaversion.protocol.packet.PacketWrapperImpl;
Expand All @@ -38,6 +39,7 @@
import net.raphimc.viabedrock.api.util.PacketFactory;
import net.raphimc.viabedrock.platform.ViaBedrockConfig;
import net.raphimc.viabedrock.protocol.data.BedrockMappingData;
import net.raphimc.viabedrock.protocol.data.enums.bedrock.PlayStatus;
import net.raphimc.viabedrock.protocol.packet.*;
import net.raphimc.viabedrock.protocol.provider.BlobCacheProvider;
import net.raphimc.viabedrock.protocol.provider.NettyPipelineProvider;
Expand All @@ -53,13 +55,16 @@ public class BedrockProtocol extends StatelessTransitionProtocol<ClientboundBedr

public static final BedrockMappingData MAPPINGS = new BedrockMappingData();

private static final EnumSet<ClientboundBedrockPackets> BEFORE_PLAY_STATE_WHITELIST = EnumSet.of(
private static final EnumSet<ClientboundBedrockPackets> LOGIN_STATE_WHITELIST = EnumSet.of(
ClientboundBedrockPackets.NETWORK_SETTINGS,
ClientboundBedrockPackets.SERVER_TO_CLIENT_HANDSHAKE,
ClientboundBedrockPackets.PLAY_STATUS,
ClientboundBedrockPackets.DISCONNECT,
ClientboundBedrockPackets.PACKET_VIOLATION_WARNING,
ClientboundBedrockPackets.NETWORK_STACK_LATENCY,
ClientboundBedrockPackets.NETWORK_STACK_LATENCY
);

private static final EnumSet<ClientboundBedrockPackets> BEFORE_PLAY_STATE_WHITELIST = EnumSet.of(
ClientboundBedrockPackets.RESOURCE_PACKS_INFO,
ClientboundBedrockPackets.RESOURCE_PACK_DATA_INFO,
ClientboundBedrockPackets.RESOURCE_PACK_CHUNK_DATA,
Expand All @@ -71,6 +76,10 @@ public class BedrockProtocol extends StatelessTransitionProtocol<ClientboundBedr
ClientboundBedrockPackets.START_GAME
);

static {
BEFORE_PLAY_STATE_WHITELIST.addAll(LOGIN_STATE_WHITELIST);
}

public BedrockProtocol() {
super(ClientboundBedrockPackets.class, ClientboundPackets1_21.class, ServerboundBedrockPackets.class, ServerboundPackets1_20_5.class);
}
Expand Down Expand Up @@ -155,6 +164,14 @@ public void transform(Direction direction, State state, PacketWrapper wrapper) t
ViaBedrock.getPlatform().getLogger().warning("Received unknown packet " + wrapper.getId() + " in state " + serverState + " with content: " + ByteBufUtil.hexDump(content));
throw CancelException.generate();
}
if (serverState == State.LOGIN && !LOGIN_STATE_WHITELIST.contains(packet) && BEFORE_PLAY_STATE_WHITELIST.contains(packet)) { // Mojang client can skip the login state
ViaBedrock.getPlatform().getLogger().warning("Server skipped LOGIN state");
final PacketWrapper playStatus = PacketWrapper.create(ClientboundBedrockPackets.PLAY_STATUS, wrapper.user());
playStatus.write(Types.INT, PlayStatus.LoginSuccess.getValue()); // status
playStatus.send(BedrockProtocol.class, false);
wrapper.user().getProtocolInfo().setServerState(State.CONFIGURATION);
serverState = State.CONFIGURATION;
}
if (serverState != State.PLAY && !BEFORE_PLAY_STATE_WHITELIST.contains(packet)) { // Mojang client ignores most packets before receiving the START_GAME packet
ViaBedrock.getPlatform().getLogger().log(Level.WARNING, "Received packet " + packet + " outside PLAY state. Ignoring it.");
throw CancelException.generate();
Expand Down

0 comments on commit c7f9e80

Please sign in to comment.