mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 19:04:59 -05:00
add reasons for client.end() & fix issues (#944)
* add add client.end() when ping.js fails added reasons in encrypt.js switched order of error event and client.end() in versionChecking.js added an error emitter for keepAliveTimeout * should be an Error object * camalCase socketClosed
This commit is contained in:
parent
601f86fc8f
commit
86dcbd5f3c
5 changed files with 10 additions and 6 deletions
|
@ -142,7 +142,7 @@ class Client extends EventEmitter {
|
|||
this.socket.removeListener('close', endSocket)
|
||||
this.socket.removeListener('end', endSocket)
|
||||
this.socket.removeListener('timeout', endSocket)
|
||||
this.emit('end', this._endReason || 'SocketClosed')
|
||||
this.emit('end', this._endReason || 'socketClosed')
|
||||
}
|
||||
|
||||
const onFatalError = (err) => {
|
||||
|
|
|
@ -15,7 +15,7 @@ module.exports = function (client, options) {
|
|||
if (err) {
|
||||
debug(err)
|
||||
client.emit('error', err)
|
||||
client.end()
|
||||
client.end('encryptionSecretError')
|
||||
return
|
||||
}
|
||||
if (options.haveCredentials) {
|
||||
|
@ -30,7 +30,7 @@ module.exports = function (client, options) {
|
|||
function onJoinServerResponse (err) {
|
||||
if (err) {
|
||||
client.emit('error', err)
|
||||
client.end()
|
||||
client.end('encryptionLoginError')
|
||||
} else {
|
||||
sendEncryptionKeyResponse()
|
||||
}
|
||||
|
|
|
@ -14,7 +14,10 @@ module.exports = function (client, options) {
|
|||
|
||||
function onKeepAlive (packet) {
|
||||
if (timeout) { clearTimeout(timeout) }
|
||||
timeout = setTimeout(() => client.end(`client timed out after ${checkTimeoutInterval} milliseconds`), checkTimeoutInterval)
|
||||
timeout = setTimeout(() => {
|
||||
client.emit('error', new Error(`client timed out after ${checkTimeoutInterval} milliseconds`))
|
||||
client.end('keepAliveError')
|
||||
}, checkTimeoutInterval)
|
||||
client.write('keep_alive', {
|
||||
keepAliveId: packet.keepAliveId
|
||||
})
|
||||
|
|
|
@ -12,8 +12,8 @@ module.exports = function (client, options) {
|
|||
}
|
||||
|
||||
if (!versionRequired) { return }
|
||||
client.end()
|
||||
client.emit('error', new Error('This server is version ' + versionRequired +
|
||||
', you are using version ' + client.version + ', please specify the correct version in the options.'))
|
||||
', you are using version ' + client.version + ', please specify the correct version in the options.'))
|
||||
client.end('differentVersionError')
|
||||
})
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ function ping (options) {
|
|||
return new Promise((resolve, reject) => {
|
||||
client.on('error', function (err) {
|
||||
clearTimeout(closeTimer)
|
||||
client.end()
|
||||
reject(err)
|
||||
})
|
||||
client.once('server_info', function (packet) {
|
||||
|
|
Loading…
Reference in a new issue