Add failsafe handling to ACCEPT_TELEPORTATION packet order fix (#12)

This commit is contained in:
RK_01 2024-10-22 13:03:43 +02:00 committed by GitHub
parent 2b37178482
commit a6850392e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 4 deletions

View File

@ -283,7 +283,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
protocol.registerServerbound(ServerboundPackets1_21_2.MOVE_PLAYER_STATUS_ONLY, this::readOnGround);
protocol.registerServerbound(ServerboundPackets1_21_2.ACCEPT_TELEPORTATION, wrapper -> {
final PlayerPositionStorage playerPositionStorage = wrapper.user().get(PlayerPositionStorage.class);
if (playerPositionStorage.hasPlayerPosition()) {
if (playerPositionStorage.checkHasPlayerPosition()) {
// Send move player after accept teleportation
wrapper.sendToServer(Protocol1_21To1_21_2.class);
wrapper.cancel();

View File

@ -40,6 +40,7 @@ public class PlayerPositionStorage implements StorableObject {
public boolean checkPong(final int id) {
if (this.pendingPongs.remove(id)) {
this.reset(); // Ensure we don't have any leftover state
this.captureNextPlayerPositionPacket = true;
return true;
} else {
@ -51,7 +52,8 @@ public class PlayerPositionStorage implements StorableObject {
if (this.captureNextPlayerPositionPacket) {
this.captureNextPlayerPositionPacket = false;
return true;
} else {
} else { // Packet order was wrong
this.reset();
return false;
}
}
@ -60,8 +62,13 @@ public class PlayerPositionStorage implements StorableObject {
this.playerPosition = playerPosition;
}
public boolean hasPlayerPosition() {
return this.playerPosition != null;
public boolean checkHasPlayerPosition() {
if (this.playerPosition != null) {
return true;
} else { // Packet order was wrong (ACCEPT_TELEPORTATION before MOVE_PLAYER_POS_ROT packet)
this.reset();
return false;
}
}
public void sendMovePlayerPosRot(final UserConnection user) {
@ -73,6 +80,10 @@ public class PlayerPositionStorage implements StorableObject {
movePlayerPosRot.write(Types.FLOAT, this.playerPosition.pitch); // Pitch
movePlayerPosRot.write(Types.BOOLEAN, this.playerPosition.onGround); // On Ground
movePlayerPosRot.sendToServer(Protocol1_21To1_21_2.class);
this.reset();
}
private void reset() {
this.captureNextPlayerPositionPacket = false;
this.playerPosition = null;
}