Files
MinecraftForge/patches.mcp/minecraft/net/minecraft/network/ServerStatusResponse.java.patch
T

92 lines
2.9 KiB
Diff

--- ../src-base/minecraft/net/minecraft/network/ServerStatusResponse.java
+++ ../src-work/minecraft/net/minecraft/network/ServerStatusResponse.java
@@ -29,6 +29,7 @@
public void setServerDescription(ITextComponent motd)
{
this.serverMotd = motd;
+ invalidateJson();
}
public ServerStatusResponse.Players getPlayerCountData()
@@ -39,6 +40,7 @@
public void setPlayerCountData(ServerStatusResponse.Players countData)
{
this.playerCount = countData;
+ invalidateJson();
}
public ServerStatusResponse.Version getProtocolVersionInfo()
@@ -49,11 +51,13 @@
public void setProtocolVersionInfo(ServerStatusResponse.Version protocolVersionData)
{
this.protocolVersion = protocolVersionData;
+ invalidateJson();
}
public void setFavicon(String faviconBlob)
{
this.favicon = faviconBlob;
+ invalidateJson();
}
public String getFavicon()
@@ -176,6 +180,7 @@
serverstatusresponse.setFavicon(JsonUtils.getString(jsonobject, "favicon"));
}
+ net.minecraftforge.fml.client.FMLClientHandler.instance().captureAdditionalData(serverstatusresponse, jsonobject);
return serverstatusresponse;
}
@@ -203,10 +208,50 @@
jsonobject.addProperty("favicon", p_serialize_1_.getFavicon());
}
+ net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.enhanceStatusQuery(jsonobject);
return jsonobject;
}
}
+ 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.SPacketServerInfo.GSON.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;
+ }
+
public static class Version
{
private final String name;