PaperMC/patches/server/0410-Fix-for-large-move-vectors-crashing-server.patch

87 lines
6 KiB
Diff
Raw Permalink Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
Rewrite chunk system (#8177) Patch documentation to come Issues with the old system that are fixed now: - World generation does not scale with cpu cores effectively. - Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps. - Unreliable prioritisation of chunk gen/load calls that block the main thread. - Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved. - Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal. - Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles. The above list is not complete. The patch documentation will complete it. New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil. Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft. The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 10:02:51 +02:00
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
2021-06-11 14:02:28 +02:00
Date: Sun, 17 May 2020 23:47:33 -0700
Subject: [PATCH] Fix for large move vectors crashing server
Check movement distance also based on current position.
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-12-03 22:06:05 +01:00
index 0d7dae5fa79cd302d73d1be51d8bf908a816c4ca..1e6c8a23e892fc1c49da9538b435aa3eb0a28934 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-12-03 19:21:12 +01:00
@@ -499,9 +499,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
float prevYaw = this.player.getYRot();
float prevPitch = this.player.getXRot();
// CraftBukkit end
2021-06-11 14:02:28 +02:00
- double d0 = entity.getX();
- double d1 = entity.getY();
- double d2 = entity.getZ();
2024-12-03 19:21:12 +01:00
+ double d0 = entity.getX(); final double fromX = d0; // Paper - OBFHELPER
+ double d1 = entity.getY(); final double fromY = d1; // Paper - OBFHELPER
+ double d2 = entity.getZ(); final double fromZ = d2; // Paper - OBFHELPER
double d3 = ServerGamePacketListenerImpl.clampHorizontal(packet.position().x()); final double toX = d3; // Paper - OBFHELPER
double d4 = ServerGamePacketListenerImpl.clampVertical(packet.position().y()); final double toY = d4; // Paper - OBFHELPER
double d5 = ServerGamePacketListenerImpl.clampHorizontal(packet.position().z()); final double toZ = d5; // Paper - OBFHELPER
@@ -511,7 +511,16 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-06-11 14:02:28 +02:00
double d7 = d4 - this.vehicleFirstGoodY;
double d8 = d5 - this.vehicleFirstGoodZ;
double d9 = entity.getDeltaMovement().lengthSqr();
- double d10 = d6 * d6 + d7 * d7 + d8 * d8;
+ // Paper start - fix large move vectors killing the server
+ double currDeltaX = toX - fromX;
+ double currDeltaY = toY - fromY;
+ double currDeltaZ = toZ - fromZ;
+ double d10 = Math.max(d6 * d6 + d7 * d7 + d8 * d8, (currDeltaX * currDeltaX + currDeltaY * currDeltaY + currDeltaZ * currDeltaZ) - 1);
+ double otherFieldX = d3 - this.vehicleLastGoodX;
2024-12-03 19:54:10 +01:00
+ double otherFieldY = d4 - this.vehicleLastGoodY;
+ double otherFieldZ = d5 - this.vehicleLastGoodZ;
+ d10 = Math.max(d10, (otherFieldX * otherFieldX + otherFieldY * otherFieldY + otherFieldZ * otherFieldZ) - 1);
+ // Paper end - fix large move vectors killing the server
2021-06-11 14:02:28 +02:00
// CraftBukkit start - handle custom speeds and skipped ticks
this.allowedPlayerTicks += (System.currentTimeMillis() / 50) - this.lastTick;
2024-12-03 19:21:12 +01:00
@@ -557,9 +566,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
boolean flag = worldserver.noCollision(entity, entity.getBoundingBox().deflate(0.0625D));
- d6 = d3 - this.vehicleLastGoodX;
2024-12-03 19:21:12 +01:00
- d7 = d4 - this.vehicleLastGoodY;
- d8 = d5 - this.vehicleLastGoodZ;
+ d6 = d3 - this.vehicleLastGoodX; // Paper - diff on change, used for checking large move vectors above
2024-12-03 19:54:10 +01:00
+ d7 = d4 - this.vehicleLastGoodY; // Paper - diff on change, used for checking large move vectors above
+ d8 = d5 - this.vehicleLastGoodZ; // Paper - diff on change, used for checking large move vectors above
2022-03-01 06:43:03 +01:00
boolean flag1 = entity.verticalCollisionBelow;
2023-06-08 01:44:11 +02:00
if (entity instanceof LivingEntity) {
2024-12-03 19:21:12 +01:00
@@ -1318,7 +1327,16 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-06-08 01:44:11 +02:00
double d7 = d1 - this.firstGoodY;
double d8 = d2 - this.firstGoodZ;
double d9 = this.player.getDeltaMovement().lengthSqr();
- double d10 = d6 * d6 + d7 * d7 + d8 * d8;
2021-06-11 14:02:28 +02:00
+ // Paper start - fix large move vectors killing the server
+ double currDeltaX = toX - prevX;
+ double currDeltaY = toY - prevY;
+ double currDeltaZ = toZ - prevZ;
+ double d10 = Math.max(d6 * d6 + d7 * d7 + d8 * d8, (currDeltaX * currDeltaX + currDeltaY * currDeltaY + currDeltaZ * currDeltaZ) - 1);
+ double otherFieldX = d0 - this.lastGoodX;
+ double otherFieldY = d1 - this.lastGoodY;
+ double otherFieldZ = d2 - this.lastGoodZ;
2023-06-08 01:44:11 +02:00
+ d10 = Math.max(d10, (otherFieldX * otherFieldX + otherFieldY * otherFieldY + otherFieldZ * otherFieldZ) - 1);
2021-06-11 14:02:28 +02:00
+ // Paper end - fix large move vectors killing the server
if (this.player.isSleeping()) {
2023-06-08 01:44:11 +02:00
if (d10 > 1.0D) {
2024-12-03 19:21:12 +01:00
@@ -1374,9 +1392,9 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
AABB axisalignedbb = this.player.getBoundingBox();
2023-06-08 01:44:11 +02:00
- d6 = d0 - this.lastGoodX;
- d7 = d1 - this.lastGoodY;
- d8 = d2 - this.lastGoodZ;
+ d6 = d0 - this.lastGoodX; // Paper - diff on change, used for checking large move vectors above
+ d7 = d1 - this.lastGoodY; // Paper - diff on change, used for checking large move vectors above
+ d8 = d2 - this.lastGoodZ; // Paper - diff on change, used for checking large move vectors above
2024-04-24 15:46:45 +02:00
boolean flag1 = d7 > 0.0D;
2024-04-24 15:46:45 +02:00
if (this.player.onGround() && !packet.isOnGround() && flag1) {