PrismarineJS / mineflayer

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

Bot completely freezes on chat message #902

Open UltimateGG opened 4 years ago

UltimateGG commented 4 years ago

Versions

Message:

____________________.[ Royal ].______________________
Description: Apply here! ---> https://discord.gg/xxxxxxx
Joining: invitation is required    
Land / Power / Maxpower:  1774/2500/2500
Founded: 12/1/19 1:34PM
Land value: no value no refund
Balance: no balance
Bans: 22
Allies(1/1):  §fkinkers
Online: (15/48): **§6[§4§lSrMod§6]§7[§d§lMadre§7]§c freshdougie, *§7[§c§lMOD§7][§d§lJOE-MAMA§7]§c§l XFactum, *§d§lSrDAD Harryyysan, +§7[§2§lM§7]§7[§b§lGLIZZYS§c§lDAD§7]§a Godly_op, +§7[§2§lM§7]§7[§c§lMASTER§e§lCARD§7]§a glizzygreg, +§7[§6§lBOT§7]§6§l RoyalFactions, +igotbannedincsgo Aucxi, +nocheatpls, +§7[§2§lM§7]§d§o[§6§oUr§e§oFav§d§o]§a iansanity, +§cA§eGreat§bGuy§a skillable, +§7[§2§lM§7][§dPlastered§7]§a DrVexyDankHarry, +legend Totemfire3, +OVERLORDSUPREMELEADER LIL_DUDI_21, +§f§oThe§e§oPack§b§oMaster§a Xinide, +§7[§2§lM§7]§a BranchingALT
Offline: (33/48): ***§7[§5§lMASTER§7]§d IamVexy, **HeadassOnBreak JustSoDank, *§7[§c§lMOD§7]§7[§8§lOnBreak§7]§c§l Jushua, *§7[§l§4MOD§7]§c _We_The_South_, *§6[§4§lMOD§6]§a[§b§lHayleysDaddy§a] Harry_s_Truman1, *[§aM§a] BestDiamondSword, *§3§lprincessboomer rangedhealer77, *§7[§c§lMod§7][§3Spa§bce§eCad§fet§7]§c dotEXP, +NojoGabe, +LoveHate, +§7[§2§lM§7][§cS§6t§ea§fr§7]§a QuasarsInSpace, +§7[§2§lM§7]§7[§fI§4Own§fFour§1Cars§7]§a lattas01, +§7[§2§lM§7]§a RECREATOR, +§7[§2§lM§7]§7[§bBOT§7]§a gpisstevie, +§7[§2§lM§7][§d§oSoft§e§oLemon§7]§a melseuss, +§7[§2§lM§7]§a _StreetFighter, +Aidan3521, +§5ARNEOZ Derpylatios, +JustSoAdam, +§7[§2§lM§7]§a MadPeppermint, +OdinsUlfhedinn, +§7[§2§lA§7]§a RH77, +§7[§2§lM§7]§7[§c§le§5§lThot§b§lbbg§7]§a xoabbie, +§7[§2§lM§7][§bCole§fWorld§7]§a coli0, +§7[§2§lM§7]§7[§e§lV§b§lisa§7]§7[§6SugarDaddy§7]§a tustificatethe3, +§7[§2§lM§7]§a _C4OnYourDoor_, +cooltitle WalkingBillboard, +§7[§2§lM§7]§7[§e§lHOPE§7]§a KorkadBanan, +§7[§2§lM§7][§c§l;3§7]§5§o[§6§o6§e§oCPS§5§o]§a Mushey, +§7[§2§lM§7]§6[§bMogz§6]§a Morgansoley, +§d§l§oM§b§o§lunchinq§a BestDiamondAxe, +§7[§2§lM§7]§7[§5§lCu§d§ltie§7]§a Mizuki_Okami_, +BiggestClownInRoyal prettyyodd
UltimateGG commented 4 years ago

Ah so apparently removing the checkForChatPatterns function fixes this, but the problem is I need that to check for certain messages.

Ok I just added a if statement to check if it at least includes some of the patterns I would want, not fully a solution but fixes this for me.

wvffle commented 4 years ago

Well this is a bug. Seems like regexp dos.

wvffle commented 4 years ago

@Gamer745 Can you run your bot with DEBUG="minecraft-protocol" and show me the output after typing /f who royal to the chat?

extremeheat commented 3 years ago

This appears to be due to https://github.com/PrismarineJS/mineflayer/blob/030930dbb494188e4407d4f074aa945ecceb1009/lib/plugins/chat.js#L8

the username detection regex looks unnecessarily complex.

wvffle commented 3 years ago

@extremeheat actually, there's a reason to that. We're matching many possible chat patterns at once. Though I guess it could be replaced with (?:\\([^)]+\\)|\\[.[^\]]+\\]|.)*?(\\w+) to be more strict.

rom1504 commented 3 years ago

Would be good to have unit tests for these patterns. So we can improve them without breaking what they parse

On Mon, Jan 18, 2021, 10:17 Kasper Seweryn notifications@github.com wrote:

@extremeheat https://github.com/extremeheat actually, there's a reason to that. We're matching many possible chat patterns at once. Though I guess it could be replaced with (?:\([^)]+\)|\[.[^]]+\]|.)*?(\w+) to be more strict.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/902#issuecomment-762107622, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437QNNGPDYCAA4XXM43LS2P4DZANCNFSM4KLORIOQ .

banimania commented 2 years ago

Is there any way to fix this?

xanning commented 7 months ago

Can confirm, still happens. Bot goes and crashes randomly (probably a unsupported string) process hangs forever, and it just doesnt respond anymore.

extremeheat commented 7 months ago

This lag should have been fixed in https://github.com/PrismarineJS/mineflayer/pull/2350

Not a great regex but not really relevant anymore in 1.19+ since chat is now formatted on the client. We don't need regex anymore. Kind of surprised chat event wasn't updated in 1.19 update, but should be an easy fix to listen to message and re-emit a chat or whisper:

https://github.com/PrismarineJS/mineflayer/blob/5c71edf48bb2f2dfa16cddb9af5baa0c4d55cf0d/lib/plugins/chat.js#L199