Skip to content

Commit

Permalink
Cache player profile result
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Dec 31, 2024
1 parent 63d9f47 commit e90bf36
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ project(':cleanroom') {
installer 'net.openhft:affinity:3.23.3'
installer 'org.slf4j:slf4j-api:2.1.0-alpha1' // Affinity
installer 'org.slf4j:slf4j-simple:2.1.0-alpha1' // Affinity
installer 'com.github.ben-manes.caffeine:caffeine:3.1.8'

/*
forgeGradleMcDeps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,27 @@

public class NetHandlerLoginServer implements INetHandlerLoginServer, ITickable
{
@@ -49,6 +54,8 @@
@@ -48,6 +53,11 @@
private final String field_147334_j = "";
private SecretKey field_147335_k;
private EntityPlayerMP field_181025_l;

+ public String hostname = "";
+ private static final com.github.benmanes.caffeine.cache.Cache<String, GameProfile> playerProfileResultCache = com.github.benmanes.caffeine.cache.Caffeine.newBuilder()
+ .expireAfterWrite(catserver.server.CatServer.getConfig().playerProfileResultCacheMinutes, java.util.concurrent.TimeUnit.MINUTES)
+ .build(); // CatRoom - Cache player profile result
+
+ public String hostname = "";

public NetHandlerLoginServer(MinecraftServer p_i45298_1_, NetworkManager p_i45298_2_)
{
this.field_147327_f = p_i45298_1_;
@@ -56,7 +63,6 @@
@@ -56,7 +66,6 @@
field_147329_d.nextBytes(this.field_147330_e);
}

- @Override
public void func_73660_a()
{
if (this.field_147328_g == NetHandlerLoginServer.LoginState.READY_TO_ACCEPT)
@@ -70,16 +76,29 @@
@@ -70,16 +79,29 @@
if (entityplayermp == null)
{
this.field_147328_g = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
Expand Down Expand Up @@ -70,7 +73,7 @@

public void func_194026_b(ITextComponent p_194026_1_)
{
@@ -95,18 +114,48 @@
@@ -95,18 +117,48 @@
}
}

Expand Down Expand Up @@ -126,7 +129,7 @@
}
else
{
@@ -133,12 +182,11 @@
@@ -133,12 +185,11 @@
}
else
{
Expand All @@ -140,7 +143,7 @@
public void func_147231_a(ITextComponent p_147231_1_)
{
field_147332_c.info("{} lost connection: {}", this.func_147317_d(), p_147231_1_.func_150260_c());
@@ -146,12 +194,9 @@
@@ -146,12 +197,9 @@

public String func_147317_d()
{
Expand All @@ -154,7 +157,7 @@
public void func_147316_a(CPacketLoginStart p_147316_1_)
{
Validate.validState(this.field_147328_g == NetHandlerLoginServer.LoginState.HELLO, "Unexpected hello packet");
@@ -164,11 +209,24 @@
@@ -164,11 +212,24 @@
}
else
{
Expand All @@ -181,7 +184,7 @@
public void func_147315_a(CPacketEncryptionResponse p_147315_1_)
{
Validate.validState(this.field_147328_g == NetHandlerLoginServer.LoginState.KEY, "Unexpected key packet");
@@ -183,32 +241,28 @@
@@ -183,32 +244,39 @@
this.field_147335_k = p_147315_1_.func_149300_a(privatekey);
this.field_147328_g = NetHandlerLoginServer.LoginState.AUTHENTICATING;
this.field_147333_a.func_150727_a(this.field_147335_k);
Expand All @@ -208,7 +211,18 @@
- .func_147130_as()
- .hasJoinedServer(new GameProfile(null, gameprofile.getName()), s, this.func_191235_a());
+ String s = (new BigInteger(CryptManager.func_75895_a("", NetHandlerLoginServer.this.field_147327_f.func_71250_E().getPublic(), NetHandlerLoginServer.this.field_147335_k))).toString(16);
+ NetHandlerLoginServer.this.field_147337_i = NetHandlerLoginServer.this.field_147327_f.func_147130_as().hasJoinedServer(new GameProfile((UUID) null, gameprofile.getName()), s, this.func_191235_a());
+ // CatRoom start - Cache player profile result
+ if (catserver.server.CatServer.getConfig().cachePlayerProfileResult) {
+ GameProfile gp = playerProfileResultCache.getIfPresent(gameprofile.getName());
+ if (gp == null) {
+ gp = NetHandlerLoginServer.this.field_147327_f.func_147130_as().hasJoinedServer(new GameProfile((UUID)null, gameprofile.getName()), s, this.func_191235_a());
+ playerProfileResultCache.put(gameprofile.getName(), gp);
+ }
+ NetHandlerLoginServer.this.field_147337_i = gp;
+ } else {
+ NetHandlerLoginServer.this.field_147337_i = NetHandlerLoginServer.this.field_147327_f.func_147130_as().hasJoinedServer(new GameProfile((UUID) null, gameprofile.getName()), s, this.func_191235_a());
+ }
+ // CatRoom end - Cache player profile result

if (NetHandlerLoginServer.this.field_147337_i != null)
{
Expand All @@ -226,7 +240,7 @@
}
else if (NetHandlerLoginServer.this.field_147327_f.func_71264_H())
{
@@ -218,11 +272,11 @@
@@ -218,11 +286,11 @@
}
else
{
Expand All @@ -241,7 +255,7 @@
{
if (NetHandlerLoginServer.this.field_147327_f.func_71264_H())
{
@@ -232,23 +286,67 @@
@@ -232,23 +300,67 @@
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/catserver/server/CatServerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class CatServerConfig {
public boolean disableFMLStatusModInfo = false;
public boolean disableAsyncCatchWarn = false;
public boolean versionCheck = true;
public boolean cachePlayerProfileResult = false;
public int playerProfileResultCacheMinutes = 1440;

public boolean callConstructCapabilityEventOnRespawn = false;

Expand Down Expand Up @@ -113,6 +115,8 @@ public void loadConfig() {
releaseUseItemThrottle = getOrWriteIntConfig("network.packetLimit.releaseUseItemThrottle", releaseUseItemThrottle);
disableFMLHandshake = getOrWriteBooleanConfig("network.fml.disableHandshake", config.getBoolean("disableFMLHandshake", disableFMLHandshake));
disableFMLStatusModInfo = getOrWriteBooleanConfig("network.fml.disableStatusModInfo", config.getBoolean("disableFMLStatusModInfo", disableFMLStatusModInfo));
cachePlayerProfileResult = getOrWriteBooleanConfig("network.profile.cachePlayerProfileResult", cachePlayerProfileResult);
playerProfileResultCacheMinutes = getOrWriteIntConfig("network.profile.playerProfileResultCacheMinutes", playerProfileResultCacheMinutes);
// event bridge
bridgeForgeExplosionEventToBukkit = getOrWriteBooleanConfig("event-bridge.bridgeForgeExplosionEventToBukkit", bridgeForgeExplosionEventToBukkit);
// compatibility
Expand Down

0 comments on commit e90bf36

Please sign in to comment.