diff --git a/docs/API.md b/docs/API.md index c506600..48cd708 100644 --- a/docs/API.md +++ b/docs/API.md @@ -84,6 +84,7 @@ Returns a `Client` instance and perform login. * version : 1.8 or 1.9 or false (to auto-negotiate): default to 1.8 * customPackets (optional) : an object index by version/state/direction/name, see client_custom_packet for an example * hideErrors : do not display errors, default to false + * skipValidation : do not try to validate given session, defaults to false ## mc.Client(isServer,version,[customPackets]) diff --git a/src/client/auth.js b/src/client/auth.js index c618ad8..ab02e96 100644 --- a/src/client/auth.js +++ b/src/client/auth.js @@ -3,6 +3,7 @@ const UUID = require('uuid-1345') module.exports = function (client, options) { const clientToken = options.clientToken || (options.session && options.session.clientToken) || UUID.v4().toString() + const skipValidation = false || options.skipValidation options.accessToken = null options.haveCredentials = options.password != null || (clientToken != null && options.session != null) @@ -21,23 +22,25 @@ module.exports = function (client, options) { } if (options.session) { - yggdrasil.validate(options.session.accessToken, function (err) { - if (!err) { cb(null, options.session) } else { - yggdrasil.refresh(options.session.accessToken, options.session.clientToken, function (err, accessToken, data) { - if (!err) { - cb(null, data) - } else if (options.username && options.password) { - yggdrasil.auth({ - user: options.username, - pass: options.password, - token: clientToken - }, cb) - } else { - cb(err, data) - } - }) - } - }) + if (!skipValidation) { + yggdrasil.validate(options.session.accessToken, function (err) { + if (!err) { cb(null, options.session) } else { + yggdrasil.refresh(options.session.accessToken, options.session.clientToken, function (err, accessToken, data) { + if (!err) { + cb(null, data) + } else if (options.username && options.password) { + yggdrasil.auth({ + user: options.username, + pass: options.password, + token: clientToken + }, cb) + } else { + cb(err, data) + } + }) + } + }) + } } else { yggdrasil.auth({ user: options.username, diff --git a/src/index.d.ts b/src/index.d.ts index 173c32b..3d0a87d 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -38,6 +38,7 @@ declare module 'minecraft-protocol' { port?: number username: string version?: string + skipValidation?: boolean } export class Server extends EventEmitter {