Twister915 / mcproto-rs

Minecraft Protocol in Rust
Apache License 2.0
112 stars 21 forks source link

Issue with chat decoding #6

Open nicoxxl opened 3 years ago

nicoxxl commented 3 years ago

Hi, I'm having an error as a client trying to decode chat messages.

First of all, I'm running it on 1.16.5 minecraft server (there is a change in protocol version but I did not see any change in protocol, so I'm not sure if it is not from there).

On my code I used dbg!() on `` and I get this :

[src/engine.rs:51] err = PacketErr {
    err: failed to deserialize packet: failed to deserialize json: "failed to deserialize chat from JSON '{\"translate\":\"chat.type.text\",\"with\":[{\"insertion\":\"nicoxxl\",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/tell nicoxxl \"},\"hoverEvent\":{\"action\":\"show_entity\",\"contents\":{\"type\":\"minecraft:player\",\"id\":\"665fbf7d-d38f-3fa1-80a3-3a9a2c7d7220\",\"name\":{\"text\":\"nicoxxl\"}}},\"text\":\"nicoxxl\"},\"Hello BillyBob :)\"]}' :: Error(\"unable to parse one of the translation with entries :: unexpected key in event contents\", line: 1, column: 314)",
}

The formatted JSON looks like that :

{
  "translate": "chat.type.text",
  "with": [
    {
      "clickEvent": {
        "action": "suggest_command",
        "value": "/tell nicoxxl "
      },
      "hoverEvent": {
        "action": "show_entity",
        "contents": {
          "id": "665fbf7d-d38f-3fa1-80a3-3a9a2c7d7220",
          "name": {
            "text": "nicoxxl"
          },
          "type": "minecraft:player"
        }
      },
      "insertion": "nicoxxl",
      "text": "nicoxxl"
    },
    "Hello BillyBob :)"
  ]
}

In the code I saw this :

#[derive(Serialize, Clone, Debug, PartialEq)]
pub struct BaseComponent {
    // Cut some fields above
    #[serde(skip_serializing_if = "Option::is_none")]
    pub click_event: Option<ChatClickEvent>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub hover_event: Option<ChatHoverEvent>,
    // Cut some field below
}

You did not used #[serde(rename = "name")] to swith to camelCase, is that an error or the protocol changed ?

Twister915 commented 3 years ago

Hi, I will have a look at this tonight. I believe I've also run into this issue before. Thanks for submitting this report.

regenerativep commented 3 years ago

I recently had this problem. It seems like mcproto is looking for a "value" key in the hoverEvent, but, even though its even specified like that in wiki.vg, that's not the case in the JSON minecraft is sending. Turning line 1009 in chat.rs from

"value" => {

to

"value" | "contents" => {

appears to fix it for me.