mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-25 18:09:17 +00:00
rewritten profile cache (#415)
* rewritten profile cache * cleanup * Fix build * Update comments
This commit is contained in:
@@ -1,97 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
||||
Date: Thu, 28 Mar 2024 13:36:09 -0400
|
||||
Subject: [PATCH] Cache player profileResult
|
||||
|
||||
This patch includes code that references the Caffeine caching library,
|
||||
which is licensed under the Apache License, Version 2.0.
|
||||
|
||||
Caffeine (https://github.com/ben-manes/caffeine)
|
||||
Copyright (c) Ben Manes
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
diff --git a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
index f68923c5f6fbecd8f1c10a30dbd06ed0dfee8b84..2e014cd543a6a790a0023835199b0e956e49fd1f 100644
|
||||
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
@@ -71,6 +71,14 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
|
||||
public @Nullable java.util.UUID requestedUuid; // Paper
|
||||
private final io.papermc.paper.connection.PaperPlayerLoginConnection paperLoginConnection; // Paper - Config API
|
||||
private volatile boolean disconnecting = false; // Paper - Fix disconnect still ticking login
|
||||
+ // Leaf start - Cache player profileResult
|
||||
+ private static final com.github.benmanes.caffeine.cache.Cache<String, ProfileResult> playerProfileResultCache = com.github.benmanes.caffeine.cache.Caffeine.newBuilder()
|
||||
+ .expireAfterWrite(org.dreeam.leaf.config.modules.misc.Cache.cachePlayerProfileResultTimeout, java.util.concurrent.TimeUnit.MINUTES)
|
||||
+ .build();
|
||||
+ private static final com.github.benmanes.caffeine.cache.Cache<String, InetAddress> playerSession = com.github.benmanes.caffeine.cache.Caffeine.newBuilder()
|
||||
+ .expireAfterWrite(org.dreeam.leaf.config.modules.misc.Cache.cachePlayerProfileResultTimeout, java.util.concurrent.TimeUnit.MINUTES)
|
||||
+ .build();
|
||||
+ // Leaf end - Cache player profileResult
|
||||
|
||||
public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection, boolean transferred) {
|
||||
this.server = server;
|
||||
@@ -269,9 +277,30 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
|
||||
String string1 = Objects.requireNonNull(ServerLoginPacketListenerImpl.this.requestedUsername, "Player name not initialized");
|
||||
|
||||
try {
|
||||
- ProfileResult profileResult = ServerLoginPacketListenerImpl.this.server
|
||||
- .getSessionService()
|
||||
- .hasJoinedServer(string1, string, this.getAddress());
|
||||
+ // Leaf start - Cache player profileResult
|
||||
+ ProfileResult profileResult;
|
||||
+ if (org.dreeam.leaf.config.modules.misc.Cache.cachePlayerProfileResult) {
|
||||
+ profileResult = playerProfileResultCache.getIfPresent(string1);
|
||||
+
|
||||
+ InetAddress address = this.getAddress();
|
||||
+ InetAddress lastAddress = playerSession.getIfPresent(string1);
|
||||
+ if (isInvalidSession(address, lastAddress)) {
|
||||
+ // Send request to mojang server to verify session
|
||||
+ // Result will be null if is invalid and will do disconnect logic below
|
||||
+ profileResult = ServerLoginPacketListenerImpl.this.server
|
||||
+ .getSessionService()
|
||||
+ .hasJoinedServer(string1, string, address);
|
||||
+ if (profileResult != null && address != null) {
|
||||
+ playerProfileResultCache.put(string1, profileResult);
|
||||
+ playerSession.put(string1, address);
|
||||
+ }
|
||||
+ }
|
||||
+ } else {
|
||||
+ profileResult = ServerLoginPacketListenerImpl.this.server
|
||||
+ .getSessionService()
|
||||
+ .hasJoinedServer(string1, string, this.getAddress());
|
||||
+ }
|
||||
+ // Leaf end - Cache player profileResult
|
||||
if (profileResult != null) {
|
||||
GameProfile gameProfile = profileResult.profile();
|
||||
// CraftBukkit start - fire PlayerPreLoginEvent
|
||||
@@ -316,6 +345,20 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
|
||||
// Paper end - Cache authenticator threads
|
||||
}
|
||||
|
||||
+ // Leaf start - Cache player profileResult
|
||||
+ private static boolean isInvalidSession(@org.jetbrains.annotations.Nullable InetAddress currAddress, @org.jetbrains.annotations.Nullable InetAddress lastAddress) {
|
||||
+ // Invalid address or non-public IP address
|
||||
+ if (currAddress == null ||
|
||||
+ currAddress.isAnyLocalAddress() ||
|
||||
+ currAddress.isLinkLocalAddress() ||
|
||||
+ currAddress.isLoopbackAddress() ||
|
||||
+ currAddress.isSiteLocalAddress()) {
|
||||
+ return true;
|
||||
+ }
|
||||
+ return !currAddress.equals(lastAddress);
|
||||
+ }
|
||||
+ // Leaf end - Cache player profileResult
|
||||
+
|
||||
// CraftBukkit start
|
||||
private GameProfile callPlayerPreLoginEvents(GameProfile gameprofile) throws Exception { // Paper - Add more fields to AsyncPlayerPreLoginEvent
|
||||
// Paper start - Add Velocity IP Forwarding Support
|
||||
@@ -97,7 +97,7 @@ index 8516d47b0ba79d91638837199e7ae0fb6cb44a79..4f4b55dd099dd2c2fea118b18b535881
|
||||
RandomSource fork();
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 0cdd3eb97e74aa3955f014a1f8f6a7d1580d323f..574be7359a2ad62c95a42c46c7a0f3c7a42eb44e 100644
|
||||
index ce331618d70d3dcfa576994e3f67f8c81fd6e8cc..2bed05da7e5ba52e85d437460679a7b81293fe5b 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -155,7 +155,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Remove stream in entity visible effects filter
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
|
||||
index 34460363c4a5fbd274fee0f26d3731333c990072..df52963414f6c3b626eaed0f36a6cabdad68f398 100644
|
||||
index d8c3f05d36916e122bfd47d761b4d91ab54fd8f5..a75f8f86ebd3bb73b5fbeb389137344256e1175f 100644
|
||||
--- a/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -1013,12 +1013,15 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
||||
@@ -6,7 +6,7 @@ Subject: [PATCH] Replace Entity active effects map with optimized collection
|
||||
Dreeam TODO: check this
|
||||
|
||||
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
|
||||
index df52963414f6c3b626eaed0f36a6cabdad68f398..4fc9b64bce70ef1169cf361d1414553f63f047ec 100644
|
||||
index a75f8f86ebd3bb73b5fbeb389137344256e1175f..1df69848c60a724b14bb6230a67ecd7cac1a0e03 100644
|
||||
--- a/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -208,6 +208,10 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
||||
@@ -23,7 +23,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
index b3c138e78552ba348d67c37343c6684d37f2e10f..3f8b0c9f0d2172b1ffaee6c1065a91ff34b35953 100644
|
||||
index 0c73d4919e58b9282a8a6fc24fc7ab8e87b97b74..070fc3b4ec0558c597eb411db5b22edc447fe976 100644
|
||||
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -342,17 +342,12 @@ public class ServerGamePacketListenerImpl
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Configurable player knockback zombie
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
|
||||
index 4fc9b64bce70ef1169cf361d1414553f63f047ec..d81d1303fc3d23b35dbc177dd6a4c7f489eb5381 100644
|
||||
index 1df69848c60a724b14bb6230a67ecd7cac1a0e03..f63d0af0f6dc8a634f56f329d256affeaeac17da 100644
|
||||
--- a/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -2111,6 +2111,8 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
||||
@@ -7,7 +7,7 @@ Original license: AGPL-3.0
|
||||
Original project: https://github.com/snackbag/TT20
|
||||
|
||||
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
||||
index 07943aa3be4222ab7a63b09a6625f7a003da8725..3c45e6eac0403c9cb13409c8e0e9c1653fd531ba 100644
|
||||
index 6c1a8925b1e13a0ebddc1b45a980fe8bdd8676cf..169d4c5e317af201a2d5ad0d82d39805376c2e9e 100644
|
||||
--- a/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/net/minecraft/server/MinecraftServer.java
|
||||
@@ -1541,6 +1541,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@@ -12,7 +12,7 @@ As part of: Lithium (https://github.com/CaffeineMC/lithium-fabric)
|
||||
Licensed under: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
|
||||
|
||||
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
|
||||
index 7f7304af9bcf252af2e171bf64ebb139f6d30d86..875975594bc1356c416f6824907037aa28d2993d 100644
|
||||
index 80d80bc0c6c22ceda190fd238ca63875d47fc599..a1efe500e3751e1345d0c5b7671b378a97541f88 100644
|
||||
--- a/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -2825,6 +2825,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
||||
@@ -97,7 +97,7 @@ index fd3d0f6cb53bc8b6186f0d86575f21007b2c20ed..cddeeab73e7b981701a42c5aad6b4777
|
||||
// Paper end - rewrite chunk system
|
||||
}
|
||||
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
||||
index b4ee1682a851eb8f1fae999ba0913ae300a71a89..97408ce24313ff26347ff434ab6460e9971c3598 100644
|
||||
index b0ac6de9e0f15d234781fc43dd6fd1d5cd6c5ddf..7fb763e89e43698bfb2b9fcf6296705384e8624a 100644
|
||||
--- a/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -508,7 +508,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
||||
@@ -9,7 +9,7 @@ By default, the server will start rewriting all map datas to the disk after load
|
||||
This also slows down world saving a lot if you have a lot of maps
|
||||
|
||||
diff --git a/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java b/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
||||
index d049af4f129f6ac2d53f10c7a811c989d1f3edc0..81c30f4a4f411ccedf74e589294a5d279bf51663 100644
|
||||
index bf01c9d54248ceb8f97cf1e1c0e4234a338cb8ce..07d35086a41b060b4b9864f0593a08818eee6789 100644
|
||||
--- a/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
||||
+++ b/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
||||
@@ -160,6 +160,7 @@ public class MapItemSavedData extends SavedData {
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Optimize checking nearby players for spawning
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
|
||||
index 634d37f6401f19cc28f9c131dbfbbfefb6c0895a..3c80a42a4d99460d75ab18afae43cfe29e4be798 100644
|
||||
index 42555d9fc1b37696b8da4c85f9a809819bcc6dde..5c369b3d94e369c3f240821ad90b9d96223f24ca 100644
|
||||
--- a/net/minecraft/server/level/ChunkMap.java
|
||||
+++ b/net/minecraft/server/level/ChunkMap.java
|
||||
@@ -764,7 +764,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Cache supporting block check
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 23b5695bf27663bbf1f2e3fd2010c0722ad425b0..fea6b829474e4fafbb9986a0c4fd73ae8fae1e09 100644
|
||||
index fde4109b27fbafd9db1eaeedf7a6cd754a84024d..129248da7e1bfa5edc1c1a43c98a400f697e735f 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -1104,12 +1104,36 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
@@ -6,7 +6,7 @@ Subject: [PATCH] Only player pushable
|
||||
Useful for extreme cases like massive entities collide together in a small area
|
||||
|
||||
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
|
||||
index 875975594bc1356c416f6824907037aa28d2993d..3df99f699db7f25d3e05e2626c4babee87893813 100644
|
||||
index a1efe500e3751e1345d0c5b7671b378a97541f88..6d9d8f85bf6936eee76c3d790dd676aa309a1d46 100644
|
||||
--- a/net/minecraft/world/entity/LivingEntity.java
|
||||
+++ b/net/minecraft/world/entity/LivingEntity.java
|
||||
@@ -3694,7 +3694,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
||||
@@ -27,7 +27,7 @@ index c8265f25ead389b025aef6ebe4cc44972132f143..5ad00ebb9e0acab73a8366f0caf06979
|
||||
CrashReport crashReport = CrashReport.forThrowable(levelTickingException, "Exception ticking world");
|
||||
serverLevel.fillReportDetails(crashReport);
|
||||
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
||||
index bc9cf4aa9b1e71e03100a10c45ef9fc23ee5ae9f..bbe2a420193d15874a4dd384ddb3e24ee2d62420 100644
|
||||
index 0b26940e3f1645b6b8d5bd92be4d10fbe17fda58..a4c7fd6214ff37d4eb52e42b021c24a13d6a15c9 100644
|
||||
--- a/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -571,6 +571,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
||||
@@ -9,7 +9,7 @@ Leaf: ~48ms (-36%)
|
||||
This should help drastically on the farms that use actively changing fluids.
|
||||
|
||||
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
||||
index f20d7591e473a37a0f5b97c60c2eb9974980b41e..4df5bf806b84d03b2aed13fcf6ab2c00a6698d86 100644
|
||||
index a4c7fd6214ff37d4eb52e42b021c24a13d6a15c9..9453d65fbe08911674cf9090d8729264429c8d8a 100644
|
||||
--- a/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -1443,6 +1443,10 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
||||
@@ -8,7 +8,7 @@ Integrated with Imanity Software's Raytrace AntiXray for better performance
|
||||
Original project: https://github.com/Imanity-Software/raytrace-antixray-spigot-sdk
|
||||
|
||||
diff --git a/net/minecraft/server/level/ServerPlayerGameMode.java b/net/minecraft/server/level/ServerPlayerGameMode.java
|
||||
index c4a4f08272b34f72dea4feaaeb66d153b2aab8c8..be5da5a81246b4f4abe19f7c0cf68990d6bdf5bd 100644
|
||||
index d638821595138ef972163925136eb57207b31719..02c02314a4a6a7a6da427f0d064dbc61ce92301d 100644
|
||||
--- a/net/minecraft/server/level/ServerPlayerGameMode.java
|
||||
+++ b/net/minecraft/server/level/ServerPlayerGameMode.java
|
||||
@@ -296,6 +296,12 @@ public class ServerPlayerGameMode {
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Micro optimizations for random tick
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
||||
index 4df5bf806b84d03b2aed13fcf6ab2c00a6698d86..ab509260d536dfb5cb0268c20abf445498602fff 100644
|
||||
index 9453d65fbe08911674cf9090d8729264429c8d8a..a1c2e9018800339fca62d95c522da1bf254568fe 100644
|
||||
--- a/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -1041,7 +1041,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
||||
@@ -11,7 +11,7 @@ As part of: Airplane (https://github.com/TECHNOVE/Airplane)
|
||||
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
||||
|
||||
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
||||
index 4be8e90dfe99663ea84dae04d9bb2b0e3bb01098..aa1c937f8cee164b9e832b7d155bcbcf22e95b63 100644
|
||||
index b1b9bc9be22da5a9a683e907766aaaafee0129ec..bfd486c85942a7d7b3e00724dd08319381222230 100644
|
||||
--- a/net/minecraft/world/entity/Entity.java
|
||||
+++ b/net/minecraft/world/entity/Entity.java
|
||||
@@ -4812,10 +4812,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user