PrismarineJS / mineflayer

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

Chatterbox Example error! #159

Closed jjdt closed 10 years ago

jjdt commented 11 years ago

Hi, I have installed MineFlayer on a CentOS dedicated server, and, when I try executing Chatterbox example logging on offline mode on a localhost server 1.6.2 It returns the following error:


I logged in. settings { chat: 'enabled', colorsEnabled: true, viewDistance: 'tiny', difficulty: 2, showCape: true } current time { day: 2160, age: 97968906 }

/usr/src/npm/node_modules/mineflayer/lib/plugins/chat.js:17 if (jsonMsg.translate.match(/^chat./)) { ^ TypeError: Cannot call method 'match' of undefined at Client. (/usr/src/npm/node_modules/mineflayer/lib/plugins/chat.js:17:27) at Client.EventEmitter.emit (events.js:126:20) at Socket.Client.setSocket.ended (/usr/src/npm/node_modules/minecraft-protocol/lib/client.js:41:12) at Socket.EventEmitter.emit (events.js:96:17) at TCP.onread (net.js:397:14)


I hope you could find the solution ;)

andrewrk commented 11 years ago

Check the api docs.

Looks like that example is depending on something from the server being a certain way which is an invalid assumption. Until the example is fixed these docs should help you understand.

jjdt commented 11 years ago

Hi again and thank for the reply, I have been reading the docs, they are very instructive, but I still have problems with chat.js The thing is that I was trying to use "message" event and I still had the problem I commented in the last post. So I tried to create this example:


var mineflayer = require('mineflayer'); var bot = mineflayer.createBot({ host: "localhost", // optional port: 25599, // optional username: "Bot", // email and password are required only for });


Stupid example xD just connect without doing anything. And the thing was that I still had the same problem:


/usr/src/npm/node_modules/mineflayer/lib/plugins/chat.js:17 if (jsonMsg.translate.match(/^chat./)) { ^ TypeError: Cannot call method 'match' of undefined at Client. (/usr/src/npm/node_modules/mineflayer/lib/plugins/ch.js:17:27)


I deleted chat.js on /lib/plugins folder and the bot works, just connected to the server without doing anything, but Connected! So, seems to be an error with this file. Due to I dont know anything related to js code, i have to ask you xD, do you think the bot will work without this file ?

zuazo commented 11 years ago

Hi @jjdt,

I can't reproduce the error using 1.6.2. But I tried to fix it in the next commit: fe2a7f1

Could you try if that works for you?

jjdt commented 11 years ago

Hi, I tried to run the code with that new commit. When I run it just to connect and do nothing, the client works, but, if I try to use "Chat" Event, it does not work when I talk on Minecraft with a real user or with the console (I mean it proceeds as noone is talking, but the js does not crash). If I try to use the "Message" Event, the js answers with this Error:


/usr/src/npm/node_modules/mineflayer/lib/plugins/chat.js:30 message = message.replace(outgoingFilter, ''); ^ TypeError: Object # has no method 'replace' (...)


Looks like chat.js is not working well for me :S

andrewrk commented 11 years ago

Can we have more information about the minecraft server you're trying to connect to? Is it vanilla 1.6.2? Is it modded? etc

zuazo commented 11 years ago

Make sure you are passing a string as a bot.chat() argument and not an object. As @superjoe30 said, if you could give us more information about the server and the code example used, the better.

jjdt commented 11 years ago

Hi guys, thank you for everything. Im using Bukkit 1.6.2 After trying lots of codes I decided to get the value of the chat packet that my server was sending. New Minecraft protocol indicates that a JSON should be sent with "translate" "color" "using" and more fields, but my server only sent "text" field, so in the chat.js the code tried to look for "using" and that fields and it crashed. So I used directly Node-MinecraftProtocol and ignored those fields getting only text field.

I dont know if this works like that with all the servers or it just mine, If I can I will try to use it on a Vanilla Server and tell you what is happening. Btw I recommend you to check your chat code if you want maybe because I dont think my server is so modified (Specially because I coded so I know what is modified) and maybe the client will crash with many other servers :S

Thank you for everything again, really good project !

jjdt commented 11 years ago

Update:

I have investigated a bit. It seems that not all CHAT PACKETS must have all the JSON fields ("using", "text", "translate") For example, when someone says hello on a server, the server send a Chat Packet to all users with only the TEXT field Ex: { text: "[Admin][Notch] Hello Guys" }

But, for example, when a user dies, the server send this packet:

'{"translate":"death.attack.generic","using":["boti"]}' }

That is translated by the client to: Boti died.

Before last update all packets were translated by the server and sent as a String, now some packets should be translated by the client. So I think, you should add to your code a "If(JsonMsg.translate!=null)" and similar to "using" and other fields to check if the field exists before using a function with a null field=exception

I hope I could help, sorry for my fatal English, Its not my native language as you have seen xD

zuazo commented 11 years ago

First of all, thanks for all your information and dedication :smiley:

I pushed a commit that makes chat messages compatible with the old format and the new bukkit format (text subkey but still JSON). Anyway, craftbukkit is still in beta for 1.6.2, so this could change.

Can you help us by testing this commit? a35a2d8

jjdt commented 11 years ago

Hi zuazo, I tried that commit and when I chat, Chat event does not reply, It does not shows any error, but does not work xD

Maybe the best thing is wait for a Bukkit Stable Build to try it ;) Btw users can get chat messages with "message" event or listening to the 0x03 Chat Packet as I do atm, so its not a big problem.

Thank you for your help and dedication, jjdt ;)

benjajaja commented 11 years ago

Hello, I ran into the same issue using the npm version 1.0.0, but it disapparead when using the latest gihub version as of now a35a2d83d37890c402cd8a3ba4bb17803a2f6807 :)

Edit: happened with a bukkit server, did not test with a vanilla server.

zuazo commented 11 years ago

Wonderful @gipsy-king. Thank you for commenting because worked for me also and I was a bit lost :thumbsup:

@jjdt are you sure it doesn't work for you with the last version (Beta Build 1.6.2-R0.1)? Any clue or error?

vampirefrog commented 11 years ago

Hey guys. I've encountered the same problem as initially stated in the issue text. After getting the latest revision, there isn't a crash anymore, but the examples that use the 'chat' event don't work either. I've figured out why - my craftbukkit server has a plugin called 'Essentials', which does a number of things - firstly, it prepends a tilde to operators' nicknames, and the world name in brackets as well (so the regular expression from chat.js:19 needs to have the caret removed for the match to work, and then you need to manually remove the tilde from the resulting nickname). An example would be '[world]<~poopy> hello' (also colored btw); secondly, it allows for nicknames - so if you are using a nickname (for example your username might be poopybiscuits1629 and your nick can be biscuits), there seems to be no way of identifying a relation between the username and the nickname. If you're running the node bot on the same filesystem as the mc server, you could read the per-user data in craftbukkit/plugins/Essentials/userdata/poopybiscuits1629.yml, but I believe at this point the code is getting too complex to stuff into the chat.js plugin. Perhaps the furthest it could go is to allow an array of aliases, and let the user write his own code (perhaps a library) for getting the data to fill that array, or just hardcode it. Or, even more generally, allow the chat plugin to use a specified parsing function for the JSON or just the chat string. These last few options might simplify it greatly, but the examples won't work. Perhaps you could add a throw() in the chat.js plugin that says 'I can't figure out who sent this message and I can't really parse it properly. Please write your own parser. See this page for more information (insert url to a wiki page explaining the wonderful varieties of chat message flavors)."

zuazo commented 11 years ago

Awesome. So the problem seems to be the Essentials plugin. Thanks, @vampirefrog, for all your information, all your ideas and proposed solutions. I also think, at this point, it will be a good idea to make the chat plugin more customizable. We cannot parse all the chat tricks of all bukkit plugins.

zuazo commented 10 years ago

Until we implement a clean way to parse multiple chat message formats, perhaps you may be able to use "message" event to read the chat message, parsing it on your own.

https://github.com/superjoe30/mineflayer/blob/a35a2d83d37890c402cd8a3ba4bb17803a2f6807/lib/plugins/chat.js#L56-L60

nevercast commented 10 years ago

Another chat related issue. Closed. I think we will have to backport the new chat implementation that is currently under development to 1.6.

andrewrk commented 10 years ago

The philosophy before has been that only the latest version matters, too bad so sad if you are running old code. If people are willing to put in the effort required to maintain old versions, by all means do so, but it's probably not going to hurt anyone's feelings if we blaze on ahead.

nevercast commented 10 years ago

I've no problem with just focusing on the latest version. I don't think we really have the programming power to maintain all versions tbh. We should put all the energy on the latest