Clear chunk on dimension switch

This should resolve chunks being leftover in instances such as server switches in proxies.
This commit is contained in:
Camotoy 2021-08-30 15:12:17 -04:00 committed by SupremeMortal
parent b9541505af
commit ab2f5b326f
No known key found for this signature in database
GPG key ID: DDBB25F8EE4FA29A
3 changed files with 26 additions and 5 deletions

View file

@ -136,6 +136,19 @@ public class ChunkCache {
chunks.remove(chunkPosition); chunks.remove(chunkPosition);
} }
/**
* Manually clears all entries in the chunk cache.
* The server is responsible for clearing chunk entries if out of render distance (for example) or switching dimensions,
* but it is the client that must clear chunks in the event of proxy switches.
*/
public void clear() {
if (!cache) {
return;
}
chunks.clear();
}
public int getChunkMinY() { public int getChunkMinY() {
return minY >> 4; return minY >> 4;
} }

View file

@ -60,6 +60,7 @@ public class DimensionUtils {
int bedrockDimension = javaToBedrock(javaDimension); int bedrockDimension = javaToBedrock(javaDimension);
Entity player = session.getPlayerEntity(); Entity player = session.getPlayerEntity();
session.getChunkCache().clear();
session.getEntityCache().removeAllEntities(); session.getEntityCache().removeAllEntities();
session.getItemFrameCache().clear(); session.getItemFrameCache().clear();
session.getLecternCache().clear(); session.getLecternCache().clear();

View file

@ -57,6 +57,7 @@ import java.security.KeyPairGenerator;
import java.security.PublicKey; import java.security.PublicKey;
import java.security.interfaces.ECPublicKey; import java.security.interfaces.ECPublicKey;
import java.security.spec.ECGenParameterSpec; import java.security.spec.ECGenParameterSpec;
import java.util.Iterator;
import java.util.UUID; import java.util.UUID;
public class LoginEncryptionUtils { public class LoginEncryptionUtils {
@ -70,8 +71,10 @@ public class LoginEncryptionUtils {
} }
ECPublicKey lastKey = null; ECPublicKey lastKey = null;
boolean validChain = false; boolean mojangSigned = false;
for (JsonNode node : data) { Iterator<JsonNode> iterator = data.iterator();
while (iterator.hasNext()) {
JsonNode node = iterator.next();
JWSObject jwt = JWSObject.parse(node.asText()); JWSObject jwt = JWSObject.parse(node.asText());
// x509 cert is expected in every claim // x509 cert is expected in every claim
@ -92,8 +95,12 @@ public class LoginEncryptionUtils {
return false; return false;
} }
if (mojangSigned) {
return !iterator.hasNext();
}
if (lastKey.equals(EncryptionUtils.getMojangPublicKey())) { if (lastKey.equals(EncryptionUtils.getMojangPublicKey())) {
validChain = true; mojangSigned = true;
} }
Object payload = JSONValue.parse(jwt.getPayload().toString()); Object payload = JSONValue.parse(jwt.getPayload().toString());
@ -104,7 +111,7 @@ public class LoginEncryptionUtils {
lastKey = EncryptionUtils.generateKey((String) identityPublicKey); lastKey = EncryptionUtils.generateKey((String) identityPublicKey);
} }
return validChain; return mojangSigned;
} }
public static void encryptPlayerConnection(GeyserSession session, LoginPacket loginPacket) { public static void encryptPlayerConnection(GeyserSession session, LoginPacket loginPacket) {