PrismarineJS / node-minecraft-protocol

Parse and serialize minecraft packets, plus authentication and encryption.
https://prismarinejs.github.io/node-minecraft-protocol/
BSD 3-Clause "New" or "Revised" License
1.22k stars 239 forks source link

Onclose/disconnect event #546

Closed MrSonicMaster closed 6 years ago

MrSonicMaster commented 6 years ago

Is there ANY WAY at ALL to detect disconnect/error/close events - I have tried EVERYTHING and NOTHING logs at all to tell me why it's failing to connect or really just any helpful information at all.

(code snippet, not full script)

const bot = mc.createClient({
    host: 'mc.hypixel.net',
    port: 25565,
    username: username,
    password: password,
    version: '1.8.9'
});

bot.on('end', reason => {
    console.error(`${realName} has been ended (${reason})!`);
});

bot.on('error', error => {
    console.error(`${realName} connection error (${error})!`);
});

bot.on('close', close => {
    console.error(`${realName} connection close (${close})!`);
});

bot.on('timeout', timeout => {
    console.error(`${realName} connection timeout (${timeout})!`);
});

Nothing logs (no errors, nothing at all), node script just terminates most of the time. I've gotten around a 1% success rate where it actually connects/logs it's connected and does what it's supposed to (with no modification from where it fails). What's wrong?

rom1504 commented 6 years ago

Try to enable the debug information so see what packet are transmitted ( https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/README.md#debugging ) About the reason it is failing to connect, I would say probably you're trying to connect to a server that is not vanilla and not compatible, see https://github.com/PrismarineJS/node-minecraft-protocol/issues/532 Node Minecraft protocol mainly supports vanilla (in all the versions written in the readme) but we are trying to support more non vanilla servers in that issue. If you can report there what server failed, we can try to reproduce the problem and fix it.

On Sun, Feb 11, 2018, 00:10 Mr.Sonic Master notifications@github.com wrote:

Is there ANY WAY at ALL to detect disconnect/error/close events - I have tried EVERYTHING and NOTHING logs at all to tell me why it's failing to connect or really just any helpful information at all.

(code snippet, not full script)

const bot = mc.createClient({ host: 'mc.hypixel.net', port: 25565, username: username, password: password, version: '1.8.9' });

bot.on('end', reason => { console.error(${realName} has been ended (${reason})!); });

bot.on('error', error => { console.error(${realName} connection error (${error})!); });

bot.on('close', close => { console.error(${realName} connection close (${close})!); });

bot.on('timeout', timeout => { console.error(${realName} connection timeout (${timeout})!); });

Nothing logs (no errors, nothing at all), node script just terminates most of the time. I've gotten around a 1% success rate where it actually connects/logs it's connected and does what it's supposed to (with no modification from where it fails). What's wrong?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/node-minecraft-protocol/issues/546, or mute the thread https://github.com/notifications/unsubscribe-auth/ACPN_rI6tQvhUM2Yiu1g8EHRG6YfuCHyks5tTiH9gaJpZM4SBHzI .

rom1504 commented 6 years ago

Ah I didn't read you were trying to connect to hypixel. Hypixel is highly non vanilla (it uses bungee cord and a bunch of other stuff) so I believe there are still some stuff to fix for it to work properly, but look at that issue, I think some people managed to connect a bit.

MrSonicMaster commented 6 years ago

Yeah, it does connect some of the time, but the times it fails it refuses to log a single bit of information no matter how many events I add (including disconnect and kick_disconnect as well as the others I listed above) when it fails to connect which makes it a lot harder to debug, and a lot harder to tell it to reconnect on fail/disconnect - right now I just have a 20 second timeout start right as I set connect, and it clears the timeout after it succeeds connecting. This way, if it takes too long connecting, it will attempt a re-connect assuming it fails - but obviously this could cause it to try connecting 2 times and uses up some time we could have saved by re-connecting right on fail. That being said, you can close this issue if you want (as I have a functional solution for now) but I'm pretty sure it might still be a bug with node-minecraft-protocol.