记录类 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;"
 }
 
  • 字段详细资料

    • channels

      channels 记录组件的字段。
    • mods

      private final Map<String,String> mods
      mods 记录组件的字段。
    • fmlNetworkVer

      private final int fmlNetworkVer
      fmlNetworkVer 记录组件的字段。
    • truncated

      private final boolean truncated
      truncated 记录组件的字段。
    • 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
      另请参阅:
  • 构造器详细资料

    • ServerStatusPing

      public ServerStatusPing()
    • ServerStatusPing

      public ServerStatusPing(Map<ResourceLocation,ServerStatusPing.ChannelData> channels, Map<String,String> mods, int fmlNetworkVer, boolean truncated)
      创建 ServerStatusPing 记录类的实例。
      参数:
      channels - channels 记录组件的值
      mods - mods 记录组件的值
      fmlNetworkVer - fmlNetworkVer 记录组件的值
      truncated - truncated 记录组件的值
  • 方法详细资料

    • equals

      public boolean equals(Object o)
      指示某个其他对象是否“等于”此对象。如果两个对象属于同一个类,而且所有记录组件都相等,则这两个对象相等。 使用 Objects::equals(Object,Object) 对参考组件进行比较;使用 '==' 对基元组件进行比较
      指定者:
      equals 在类中 Record
      参数:
      o - 要与之进行比较的对象
      返回:
      如果此对象与 o 参数相同,则为 true;否则为 false
    • hashCode

      public int hashCode()
      返回此对象的哈希代码值。此值派生自每个记录组件的哈希代码。
      指定者:
      hashCode 在类中 Record
      返回:
      此对象的哈希代码值
    • 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()
      返回此记录类的字符串表示形式。此表示形式包含类的名称,后跟每个记录组件的名称和值。
      指定者:
      toString 在类中 Record
      返回:
      此对象的字符串表示形式
    • channels

      返回 channels 记录组件的值。
      返回:
      channels 记录组件的值
    • mods

      public Map<String,String> mods()
      返回 mods 记录组件的值。
      返回:
      mods 记录组件的值
    • fmlNetworkVer

      public int fmlNetworkVer()
      返回 fmlNetworkVer 记录组件的值。
      返回:
      fmlNetworkVer 记录组件的值
    • truncated

      public boolean truncated()
      返回 truncated 记录组件的值。
      返回:
      truncated 记录组件的值