PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.92k stars 904 forks source link

message event processing issue.. crash down your bot #2303

Open AsherJingkongChen opened 2 years ago

AsherJingkongChen commented 2 years ago

Versions

Detailed description of a problem

When I put 32*[] on the chatroom: [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] The bot stuck in the event processing, because I can't see the message or jsonMsg in 'message' or 'messagestr' event via console.log().

What did you try yet?

  1. Whether console.log(jsonMsg) exists, bot crashes down.
  2. When 32[] is sent, the bot stopped any process.
  3. Take 2 times long to finish processing to display on console as one more [] is sent. 31[] => took 60s to finish. 30[] => took 30s to finish. 29[] => took 15s to finish. 28[] => took 7s to finish. 27[] => took 3s to finish.

    Your current code

    const mineflayer = require('mineflayer')
    const bot = mineflayer.createBot({~Options~})
    bot.on('messagestr',(message, messagePosition, jsonMsg)=>{console.log(message)})

Expected behavior

<bot> [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] displayed on the console.

Additional context

Maybe it doesn't work on other servers, but it may works if it's 64[] in singleplayer 1.17.1 Thanks if you try to help out!

rom1504 commented 2 years ago

can you try adding a return at the line before there https://github.com/PrismarineJS/mineflayer/blob/8bdce55dc3e0311ab979bc901b53f85becf7abce/lib/plugins/chat.js#L174 and try again?

AsherJingkongChen commented 2 years ago

can you try adding a return at the line before there

https://github.com/PrismarineJS/mineflayer/blob/8bdce55dc3e0311ab979bc901b53f85becf7abce/lib/plugins/chat.js#L174

and try again?

Do you mean: 截圖 2021-11-07 下午11 12 17

AsherJingkongChen commented 2 years ago

Thanks @rom1504! it works!

rom1504 commented 2 years ago

ok I guess that is one valid use case of #2247 then and also of fixing these regex to not be so easy to break

U5B commented 2 years ago

https://github.com/PrismarineJS/mineflayer/issues/2328#issuecomment-985246695 temporary workaround

Zn10plays commented 2 years ago

What is a proper solution for this? A better chat regex?

U5B commented 2 years ago

What is a proper solution for this? A better chat regex?

A proper solution is to make chat regexes in prismarine-chat that support different server chat formats such as vanilla, essential and hypixel. Another thing that could be added to prismarine-chat or minecraft-data is a list of chat regexes for various servers.

The problem with this regex is that it tries to match too many things at once, and matching too many things at once can lead to mistakes or regex dos.