Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: server_data payload sent to clients is incomplete #1362

Closed
extremeheat opened this issue Jan 3, 2025 · 2 comments · Fixed by #1364
Closed

server: server_data payload sent to clients is incomplete #1362

extremeheat opened this issue Jan 3, 2025 · 2 comments · Fixed by #1364
Labels

Comments

@extremeheat
Copy link
Member

extremeheat commented Jan 3, 2025

client.write('server_data', {
previewsChat: options.enableChatPreview,
// Note: in 1.20.5+ user must send this with `login`
enforcesSecureChat: options.enforceSecureProfile
})
doesn't send correct payload for 1.19+

1.19

   packet_server_data:   
      motd?: string
      icon?: string
      previewsChat: bool

1.19.2

   packet_server_data:   
      motd?: string
      icon?: string
      previewsChat: bool
      enforcesSecureChat: bool

1.19.3

   packet_server_data:   
      motd?: string
      icon?: string
      enforcesSecureChat: bool

1.19.4, 1.20, 1.20.2

   packet_server_data:   
      motd: string
      iconBytes?: [
         "buffer",
         {
            "countType": "varint"
         }
      ]
      enforcesSecureChat: bool

1.20.3

   packet_server_data:
      motd: anonymousNbt
      iconBytes?: [
         "buffer",
         {
            "countType": "varint"
         }
      ]
      enforcesSecureChat: bool

1.20.5+

   # MC: ClientboundServerDataPacket
   packet_server_data:
      motd: anonymousNbt
      iconBytes?: ByteArray

Check

  • Did icon actually change from string to buffer
  • verify motd went optional string -> required string -> nbt (probably caused by JSON chat component to NBT)

Not breaking anything currently though, interestingly

@extremeheat
Copy link
Member Author

extremeheat commented Jan 5, 2025

1.19 - is a chat component (json) serialized as a string

      var1.writeOptional(this.motd, FriendlyByteBuf::writeComponent);
      var1.writeOptional(this.iconBase64, FriendlyByteBuf::writeUtf);
      var1.writeBoolean(this.previewsChat);

1.19.1/1.19.2 (v760) motd is unchanged ✅

      var1.writeOptional(this.motd, FriendlyByteBuf::writeComponent);
      var1.writeOptional(this.iconBase64, FriendlyByteBuf::writeUtf);
      var1.writeBoolean(this.previewsChat);
      var1.writeBoolean(this.enforcesSecureChat);

1.19.3 motd is unchanged

      var1.writeOptional(this.motd, FriendlyByteBuf::writeComponent);
      var1.writeOptional(this.iconBase64, FriendlyByteBuf::writeUtf);
      var1.writeBoolean(this.enforcesSecureChat);

1.19.4 motd is no longer optional

      var1.writeComponent(this.motd);
      var1.writeOptional(this.iconBytes, FriendlyByteBuf::writeByteArray);
      var1.writeBoolean(this.enforcesSecureChat);

1.20.3 remains a chat component, but these have been changed to be NBT instead of json ✅

      var1.writeComponent(this.motd);
      var1.writeOptional(this.iconBytes, FriendlyByteBuf::writeByteArray);
      var1.writeBoolean(this.enforcesSecureChat);

20.5 same minus last field

      STREAM_CODEC = StreamCodec.composite(
ComponentSerialization.TRUSTED_CONTEXT_FREE_STREAM_CODEC,
 ClientboundServerDataPacket::motd, 
ByteBufCodecs.BYTE_ARRAY.apply(ByteBufCodecs::optional), 
ClientboundServerDataPacket::iconBytes, 
ClientboundServerDataPacket::new);

icon goes from b64 to raw buffer

So mc-data is correct, and nmp is lacking implementation

@extremeheat
Copy link
Member Author

✨✨ Here's an AI-assisted sketch of how you might approach this issue saved by @extremeheat using Copilot Workspace v0.27

extremeheat added a commit that referenced this issue Jan 6, 2025
Fixes #1362

Add missing fields to `server_data` payload for versions 1.19+.

* Add `motd` and `icon` fields to `server_data` payload for version 1.19.
* Add `motd`, `icon`, and `enforcesSecureChat` fields to `server_data` payload for version 1.19.2.
* Add `motd`, `icon`, and `enforcesSecureChat` fields to `server_data` payload for version 1.19.3.
* Add `motd`, `iconBytes`, and `enforcesSecureChat` fields to `server_data` payload for versions 1.19.4, 1.20, and 1.20.2.
* Add `motd`, `iconBytes`, and `enforcesSecureChat` fields to `server_data` payload for version 1.20.3.
* Add `motd` and `iconBytes` fields to `server_data` payload for version 1.20.5+.
* Use NBT components for `motd` if `chatPacketsUseNbtComponents` feature is supported.
* Convert `favicon` to buffer for `iconBytes` field if available.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/PrismarineJS/node-minecraft-protocol/issues/1362?shareId=XXXX-XXXX-XXXX-XXXX).
@rom1504 rom1504 closed this as completed in 8e131c3 Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant