levrik / node-modern-rcon

A modern RCON client implementation written in ES2015
MIT License
29 stars 5 forks source link

Instance is not authed #8

Closed PiBgierka closed 3 years ago

PiBgierka commented 3 years ago

(node:577) UnhandledPromiseRejectionWarning: RconError: Instance is not authed at /home/runner/mcbot/node_modules/modern-rcon/rcon.js:70:42 at new Promise (<anonymous>) at Rcon.disconnect (/home/runner/mcbot/node_modules/modern-rcon/rcon.js:69:12) at /home/runner/mcbot/index.js:300:27 at processTicksAndRejections (internal/process/task_queues.js:97:5) When i try example code and .disconnect() i got that error on some servers :# why?

`
rcon.connect().then(() => {
          rcon.send("bc §6"+nick+" §egot gift");
          return rcon.send(cmd); // That's a command for Minecraft
          }).catch(function(e) {
            console.log("\n\nERROR\n");
            console.error(e);
          }).then(res => {
          console.log(res);
        }).then(() => {
          return rcon.disconnect(); //this is 300 line of code
        });
        `
        and sometimes i got error:
        `RconError: Authentication failed
at Rcon._handleResponse (/home/runner/mcbot/node_modules/modern-rcon/rcon.js:91:53)
at Socket.emit (events.js:314:20)
at Socket.EventEmitter.emit (domain.js:483:12)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:272:9)
at Socket.Readable.push (_stream_readable.js:213:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)`
levrik commented 3 years ago

Because you're disconnecting after handling errors in the whole Promise chain. In case the auth fails (the Authentication failed error), the RCON instance isn't authed thus the disconnect fails. I'll close this issue since it is caused by your code and not by the library.

PiBgierka commented 3 years ago

so how handle that error :) cuz I only got RconError: Authentication failed :) and i got that only for one server. Others works. Rcon is enabled and password is good so?