Skip to content

Commit

Permalink
Clear chunk on dimension switch
Browse files Browse the repository at this point in the history
This should resolve chunks being leftover in instances such as server switches in proxies.
  • Loading branch information
Camotoy authored and SupremeMortal committed Aug 31, 2021
1 parent b954150 commit ab2f5b3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Expand Up @@ -67,7 +67,7 @@ public void addToCache(Column chunk) {
chunks.put(chunkPosition, geyserColumn);
}

public GeyserColumn getChunk(int chunkX, int chunkZ) {
public GeyserColumn getChunk(int chunkX, int chunkZ) {
long chunkPosition = MathUtils.chunkPositionToLong(chunkX, chunkZ);
return chunks.getOrDefault(chunkPosition, null);
}
Expand Down Expand Up @@ -136,6 +136,19 @@ public void removeChunk(int chunkX, int chunkZ) {
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() {
return minY >> 4;
}
Expand Down
Expand Up @@ -60,6 +60,7 @@ public static void switchDimension(GeyserSession session, String javaDimension)
int bedrockDimension = javaToBedrock(javaDimension);
Entity player = session.getPlayerEntity();

session.getChunkCache().clear();
session.getEntityCache().removeAllEntities();
session.getItemFrameCache().clear();
session.getLecternCache().clear();
Expand Down
Expand Up @@ -57,6 +57,7 @@
import java.security.PublicKey;
import java.security.interfaces.ECPublicKey;
import java.security.spec.ECGenParameterSpec;
import java.util.Iterator;
import java.util.UUID;

public class LoginEncryptionUtils {
Expand All @@ -70,8 +71,10 @@ private static boolean validateChainData(JsonNode data) throws Exception {
}

ECPublicKey lastKey = null;
boolean validChain = false;
for (JsonNode node : data) {
boolean mojangSigned = false;
Iterator<JsonNode> iterator = data.iterator();
while (iterator.hasNext()) {
JsonNode node = iterator.next();
JWSObject jwt = JWSObject.parse(node.asText());

// x509 cert is expected in every claim
Expand All @@ -92,8 +95,12 @@ private static boolean validateChainData(JsonNode data) throws Exception {
return false;
}

if (mojangSigned) {
return !iterator.hasNext();
}

if (lastKey.equals(EncryptionUtils.getMojangPublicKey())) {
validChain = true;
mojangSigned = true;
}

Object payload = JSONValue.parse(jwt.getPayload().toString());
Expand All @@ -104,7 +111,7 @@ private static boolean validateChainData(JsonNode data) throws Exception {
lastKey = EncryptionUtils.generateKey((String) identityPublicKey);
}

return validChain;
return mojangSigned;
}

public static void encryptPlayerConnection(GeyserSession session, LoginPacket loginPacket) {
Expand Down

0 comments on commit ab2f5b3

Please sign in to comment.