Skip to content

Commit bd2bb63

Browse files
committed
Validate state transition
1 parent 3f0a85d commit bd2bb63

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
8484
private static final Logger logger = LogManager.getLogger(MinecraftConnection.class);
8585

8686
private final Channel channel;
87+
public boolean pendingConfigurationSwitch = false;
8788
private SocketAddress remoteAddress;
8889
private StateRegistry state;
8990
private Map<StateRegistry, MinecraftSessionHandler> sessionHandlers;

proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import com.velocitypowered.proxy.protocol.packet.title.GenericTitlePacket;
7373
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
7474
import com.velocitypowered.proxy.util.CharacterUtil;
75+
import com.velocitypowered.proxy.util.except.QuietRuntimeException;
7576
import io.netty.buffer.ByteBuf;
7677
import io.netty.buffer.ByteBufUtil;
7778
import io.netty.buffer.Unpooled;
@@ -392,6 +393,9 @@ public boolean handle(ResourcePackResponsePacket packet) {
392393

393394
@Override
394395
public boolean handle(FinishedUpdatePacket packet) {
396+
if (!player.getConnection().pendingConfigurationSwitch) {
397+
throw new QuietRuntimeException("Not expecting reconfiguration");
398+
}
395399
// Complete client switch
396400
player.getConnection().setActiveSessionHandler(StateRegistry.CONFIG);
397401
VelocityServerConnection serverConnection = player.getConnectedServer();

proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,7 @@ public void switchToConfigState() {
13181318
connection.write(BundleDelimiterPacket.INSTANCE);
13191319
}
13201320
connection.write(StartUpdatePacket.INSTANCE);
1321+
connection.pendingConfigurationSwitch = true;
13211322
connection.getChannel().pipeline().get(MinecraftEncoder.class).setState(StateRegistry.CONFIG);
13221323
// Make sure we don't send any play packets to the player after update start
13231324
connection.addPlayPacketQueueHandler();

0 commit comments

Comments
 (0)