Record Class ServerStatusPing

java.lang.Object
java.lang.Record
net.minecraftforge.network.ServerStatusPing

public record ServerStatusPing(Map<ResourceLocation,ServerStatusPing.ChannelData> channels, Map<String,String> mods, int fmlNetworkVer, boolean truncated) extends Record
Represents additional data sent by FML when a server is pinged. Previous versions used the following format:

 {
     "fmlNetworkVersion" : FMLNETVERSION,
     "channels": [
          {
              "res": "fml:handshake",
              "version": "1.2.3.4",
              "required": true
          }
     ],
     "mods": [
          {
              "modid": "modid",
              "modmarker": "{@literal <somestring>}"
          }
     ]
 }
 

Due to size of the ping packet (32767 UTF-16 code points of JSON data) this could exceed this limit and cause issues. To work around this, a truncation mechanism was introduced, to heuristically truncate the size of the data, at the expense of making the compatibility info on the server screen inaccurate.

Modern versions will send binary data, which is encoded in a custom format optimized for UTF-16 code point count. See encodeOptimized(ByteBuf) and decodeOptimized(String). Essentially 15 bits of binary data are encoded into every UTF-16 code point. The resulting string is then stored in the "d" property of the resulting JSON.

The "channels" and "mods" properties are retained for backwards compatibility, but left empty. A client that cannot read the old format would not be able to connect anyways, but the properties must exist to not cause exceptions.


 {
     "fmlNetworkVersion": FMLNETVERSION,
     "channels": [],
     "mods": [],
     "d": "&lt;binary data&gt;"
 }
 
  • Field Details

    • channels

      The field for the channels record component.
    • mods

      private final Map<String,String> mods
      The field for the mods record component.
    • fmlNetworkVer

      private final int fmlNetworkVer
      The field for the fmlNetworkVer record component.
    • truncated

      private final boolean truncated
      The field for the truncated record component.
    • BYTE_BUF_CODEC

      private static final com.mojang.serialization.Codec<io.netty.buffer.ByteBuf> BYTE_BUF_CODEC
    • CODEC

      public static final com.mojang.serialization.Codec<ServerStatusPing> CODEC
    • VERSION_FLAG_IGNORESERVERONLY

      private static final int VERSION_FLAG_IGNORESERVERONLY
      See Also:
  • Constructor Details

    • ServerStatusPing

      public ServerStatusPing()
    • ServerStatusPing

      public ServerStatusPing(Map<ResourceLocation,ServerStatusPing.ChannelData> channels, Map<String,String> mods, int fmlNetworkVer, boolean truncated)
      Creates an instance of a ServerStatusPing record class.
      Parameters:
      channels - the value for the channels record component
      mods - the value for the mods record component
      fmlNetworkVer - the value for the fmlNetworkVer record component
      truncated - the value for the truncated record component
  • Method Details

    • equals

      public boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • getChannelsForMod

      private List<Map.Entry<ResourceLocation,ServerStatusPing.ChannelData>> getChannelsForMod(String modId)
    • getNonModChannels

    • toBuf

      public io.netty.buffer.ByteBuf toBuf()
    • deserializeOptimized

      private static ServerStatusPing deserializeOptimized(int fmlNetworkVersion, io.netty.buffer.ByteBuf bbuf)
    • encodeOptimized

      private static String encodeOptimized(io.netty.buffer.ByteBuf buf)
      Encode given ByteBuf to a String. This is optimized for UTF-16 Code-Point count. Supports at most 2^30 bytes in length
    • decodeOptimized

      private static io.netty.buffer.ByteBuf decodeOptimized(String s)
      Decode binary data encoded by encodeOptimized(io.netty.buffer.ByteBuf)
    • getRemoteChannels

      public Map<ResourceLocation,ServerStatusPing.ChannelData> getRemoteChannels()
    • getRemoteModData

      public Map<String,String> getRemoteModData()
    • getFMLNetworkVersion

      public int getFMLNetworkVersion()
    • isTruncated

      public boolean isTruncated()
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • channels

      Returns the value of the channels record component.
      Returns:
      the value of the channels record component
    • mods

      public Map<String,String> mods()
      Returns the value of the mods record component.
      Returns:
      the value of the mods record component
    • fmlNetworkVer

      public int fmlNetworkVer()
      Returns the value of the fmlNetworkVer record component.
      Returns:
      the value of the fmlNetworkVer record component
    • truncated

      public boolean truncated()
      Returns the value of the truncated record component.
      Returns:
      the value of the truncated record component