3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 08:10:09 +01:00

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

Dieser Commit ist enthalten in:
RK_01 2024-10-22 13:03:43 +02:00 committet von GitHub
Ursprung 2b37178482
Commit a6850392e1
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
2 geänderte Dateien mit 15 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -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();

Datei anzeigen

@ -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;
}