Mitigate potential issue with users requesting lots of server status information by caching ServerStatus json.
This commit is contained in:
parent
107e760aa3
commit
5064d33519
4 changed files with 103 additions and 5 deletions
|
@ -0,0 +1,76 @@
|
|||
--- ../src-base/minecraft/net/minecraft/network/ServerStatusResponse.java
|
||||
+++ ../src-work/minecraft/net/minecraft/network/ServerStatusResponse.java
|
||||
@@ -29,6 +29,7 @@
|
||||
public void func_151315_a(IChatComponent p_151315_1_)
|
||||
{
|
||||
this.field_151326_a = p_151315_1_;
|
||||
+ invalidateJson();
|
||||
}
|
||||
|
||||
public ServerStatusResponse.PlayerCountData func_151318_b()
|
||||
@@ -39,6 +40,7 @@
|
||||
public void func_151319_a(ServerStatusResponse.PlayerCountData p_151319_1_)
|
||||
{
|
||||
this.field_151324_b = p_151319_1_;
|
||||
+ invalidateJson();
|
||||
}
|
||||
|
||||
public ServerStatusResponse.MinecraftProtocolVersionIdentifier func_151322_c()
|
||||
@@ -49,11 +51,13 @@
|
||||
public void func_151321_a(ServerStatusResponse.MinecraftProtocolVersionIdentifier p_151321_1_)
|
||||
{
|
||||
this.field_151325_c = p_151321_1_;
|
||||
+ invalidateJson();
|
||||
}
|
||||
|
||||
public void func_151320_a(String p_151320_1_)
|
||||
{
|
||||
this.field_151323_d = p_151320_1_;
|
||||
+ invalidateJson();
|
||||
}
|
||||
|
||||
public String func_151316_d()
|
||||
@@ -270,4 +274,43 @@
|
||||
return this.serialize((ServerStatusResponse)p_serialize_1_, p_serialize_2_, p_serialize_3_);
|
||||
}
|
||||
}
|
||||
+
|
||||
+ private java.util.concurrent.Semaphore mutex = new java.util.concurrent.Semaphore(1);
|
||||
+ private String json = null;
|
||||
+ /**
|
||||
+ * Returns this object as a Json string.
|
||||
+ * Converting to JSON if a cached version is not available.
|
||||
+ *
|
||||
+ * Also to prevent potentially large memory allocations on the server
|
||||
+ * this is moved from the S00PacketServerInfo writePacket function
|
||||
+ *
|
||||
+ * As this method is called from the network threads thread safety is important!
|
||||
+ *
|
||||
+ * @return
|
||||
+ */
|
||||
+ public String getJson()
|
||||
+ {
|
||||
+ String ret = this.json;
|
||||
+ if (ret == null)
|
||||
+ {
|
||||
+ mutex.acquireUninterruptibly();
|
||||
+ ret = this.json;
|
||||
+ if (ret == null)
|
||||
+ {
|
||||
+ ret = net.minecraft.network.status.server.S00PacketServerInfo.field_149297_a.toJson(this);
|
||||
+ this.json = ret;
|
||||
+ }
|
||||
+ mutex.release();
|
||||
+ }
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Invalidates the cached json, causing the next call to getJson to rebuild it.
|
||||
+ * This is needed externally because PlayerCountData.setPlayer's is public.
|
||||
+ */
|
||||
+ public void invalidateJson()
|
||||
+ {
|
||||
+ this.json = null;
|
||||
+ }
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
--- ../src-base/minecraft/net/minecraft/network/status/server/S00PacketServerInfo.java
|
||||
+++ ../src-work/minecraft/net/minecraft/network/status/server/S00PacketServerInfo.java
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
public void func_148840_b(PacketBuffer p_148840_1_) throws IOException
|
||||
{
|
||||
- p_148840_1_.func_180714_a(field_149297_a.toJson(this.field_149296_b));
|
||||
+ p_148840_1_.func_180714_a(this.field_149296_b.getJson());
|
||||
}
|
||||
|
||||
public void func_148833_a(INetHandlerStatusClient p_148833_1_)
|
|
@ -117,7 +117,15 @@
|
|||
}
|
||||
|
||||
if (this.field_71307_n.func_76468_d())
|
||||
@@ -681,15 +662,18 @@
|
||||
@@ -630,6 +611,7 @@
|
||||
|
||||
Collections.shuffle(Arrays.asList(agameprofile));
|
||||
this.field_147147_p.func_151318_b().func_151330_a(agameprofile);
|
||||
+ this.field_147147_p.invalidateJson();
|
||||
}
|
||||
|
||||
if (this.field_71315_w % 900 == 0)
|
||||
@@ -681,15 +663,18 @@
|
||||
}
|
||||
|
||||
this.field_71304_b.func_76318_c("levels");
|
||||
|
@ -139,7 +147,7 @@
|
|||
this.field_71304_b.func_76320_a(worldserver.func_72912_H().func_76065_j());
|
||||
|
||||
if (this.field_71315_w % 20 == 0)
|
||||
@@ -733,9 +717,11 @@
|
||||
@@ -733,9 +718,11 @@
|
||||
this.field_71304_b.func_76319_b();
|
||||
}
|
||||
|
||||
|
@ -152,7 +160,7 @@
|
|||
this.field_71304_b.func_76318_c("connection");
|
||||
this.func_147137_ag().func_151269_c();
|
||||
this.field_71304_b.func_76318_c("players");
|
||||
@@ -774,7 +760,13 @@
|
||||
@@ -774,7 +761,13 @@
|
||||
|
||||
public WorldServer func_71218_a(int p_71218_1_)
|
||||
{
|
||||
|
@ -167,7 +175,7 @@
|
|||
}
|
||||
|
||||
public String func_71249_w()
|
||||
@@ -1025,6 +1017,7 @@
|
||||
@@ -1025,6 +1018,7 @@
|
||||
|
||||
if (worldserver != null)
|
||||
{
|
||||
|
@ -175,7 +183,7 @@
|
|||
worldserver.func_73041_k();
|
||||
}
|
||||
}
|
||||
@@ -1607,7 +1600,6 @@
|
||||
@@ -1607,7 +1601,6 @@
|
||||
this.field_71319_s = p_71208_1_;
|
||||
}
|
||||
|
||||
|
|
|
@ -156,3 +156,6 @@ public net.minecraft.client.renderer.WorldRenderer func_78909_a(I)I # getColorIn
|
|||
public net.minecraft.client.renderer.WorldRenderer func_178972_a(IIIII)V # putColorRGBA
|
||||
# ModelBlock Constructor
|
||||
public net.minecraft.client.renderer.block.model.ModelBlock <init>(Lnet/minecraft/util/ResourceLocation;Ljava/util/List;Ljava/util/Map;ZZLnet/minecraft/client/renderer/block/model/ItemCameraTransforms;)V
|
||||
|
||||
# S00PacketServerInfo
|
||||
public net.minecraft.network.status.server.S00PacketServerInfo field_149297_a # GSON
|
||||
|
|
Loading…
Reference in a new issue