diff --git a/docs/API.md b/docs/API.md index 26739cf..d585927 100644 --- a/docs/API.md +++ b/docs/API.md @@ -81,7 +81,7 @@ Returns a `Client` instance and perform login. `options` is an object containing the properties : * username * port : default to 25565 - * auth : the type of account to use, either `microsoft` or `mojang`. default to 'microsoft' + * auth : the type of account to use, either `microsoft`, `mojang` or `offline`. default to 'microsoft' * password : can be omitted * (microsoft account) leave this blank to use device code auth. If you provide a password, we try to do username and password auth, but this does not always work. diff --git a/docs/README.md b/docs/README.md index 23b6dcd..2d2745f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -78,7 +78,7 @@ var client = mc.createClient({ port: 25565, // optional username: "email@example.com", password: "12345678", - auth: 'microsoft' // optional; by default uses microsoft + auth: 'microsoft' // optional; by default uses microsoft ; mojang or offline are also valid values }); client.on('chat', function(packet) { // Listen for chat messages and echo them back. @@ -92,7 +92,7 @@ client.on('chat', function(packet) { }); ``` -If the server is in offline mode, you may leave out the `password` option. +If the server is in offline mode, you may leave out the `password` option. In this case set auth to "offline". You can also leave out `password` when using a Microsoft account. If provided, password based auth will be attempted first which may fail. *Note:* if using a Microsoft account, your account age must be >= 18 years old. ### Hello World server example diff --git a/examples/client_electron/renderer/index.js b/examples/client_electron/renderer/index.js index c362ea5..81e1c91 100644 --- a/examples/client_electron/renderer/index.js +++ b/examples/client_electron/renderer/index.js @@ -18,7 +18,7 @@ document.getElementById('connect').addEventListener('click', () => { username: document.getElementById('username').value, password: document.getElementById('password').value === '' ? undefined : document.getElementById('password').value } - if (authType.value === 'Microsoft') { + if (authType.value === '' || authType.value === 'Microsoft') { data.auth = 'microsoft' delete data.password } diff --git a/examples/client_microsoft_auth/client_microsoft_auth.js b/examples/client_microsoft_auth/client_microsoft_auth.js index 01eebe8..25997b7 100644 --- a/examples/client_microsoft_auth/client_microsoft_auth.js +++ b/examples/client_microsoft_auth/client_microsoft_auth.js @@ -12,8 +12,7 @@ const client = mc.createClient({ host, port: parseInt(port), username: userOrEmail, // your microsoft account email - password: password, // your microsoft account password - auth: 'microsoft' // This option must be present and set to 'microsoft' to use Microsoft Account Authentication. Failure to do so will result in yggdrasil throwing invalid account information. + password: password // your microsoft account password }) client.on('connect', function () { diff --git a/examples/client_microsoft_auth/client_msal_auth.js b/examples/client_microsoft_auth/client_msal_auth.js index a80483f..d53d3b0 100644 --- a/examples/client_microsoft_auth/client_msal_auth.js +++ b/examples/client_microsoft_auth/client_msal_auth.js @@ -10,9 +10,8 @@ if (process.argv.length < 4 || process.argv.length > 6) { const client = mc.createClient({ host: process.argv[2], port: parseInt(process.argv[3]), - username: process.argv[4], // your microsoft account email + username: process.argv[4] // your microsoft account email // password: process.argv[5], // your microsoft account password - auth: 'microsoft' // This option must be present and set to 'microsoft' to use Microsoft Account Authentication. Failure to do so will result in yggdrasil throwing invalid account information. }) client.on('connect', function () { diff --git a/examples/proxy/proxy.js b/examples/proxy/proxy.js index 499c4a5..bc18ab2 100644 --- a/examples/proxy/proxy.js +++ b/examples/proxy/proxy.js @@ -96,7 +96,8 @@ srv.on('login', function (client) { port: port, username: client.username, keepAlive: false, - version: version + version: version, + auth: 'offline' }) client.on('packet', function (data, meta) { if (targetClient.state === states.PLAY && meta.state === states.PLAY) { diff --git a/src/createClient.js b/src/createClient.js index ffdc5ed..36f3787 100644 --- a/src/createClient.js +++ b/src/createClient.js @@ -34,10 +34,12 @@ function createClient (options) { const client = new Client(false, version.minecraftVersion, options.customPackets, hideErrors) tcpDns(client, options) - if (options.auth === 'microsoft') { - microsoftAuth.authenticate(client, options) - } else { - auth(client, options) + if (options.auth !== 'offline') { + if (options.auth === 'microsoft' || options.auth === undefined) { + microsoftAuth.authenticate(client, options) + } else if (options.auth === 'mojang') { + auth(client, options) + } } if (options.version === false) autoVersion(client, options) setProtocol(client, options) diff --git a/src/index.d.ts b/src/index.d.ts index 6bf785f..7e1f18b 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -80,7 +80,7 @@ declare module 'minecraft-protocol' { export interface ClientOptions { username: string port?: number - auth?: 'mojang' | 'microsoft' + auth?: 'mojang' | 'microsoft' | 'offline' password?: string host?: string clientToken?: string diff --git a/test/clientTest.js b/test/clientTest.js index 079b6e6..b9c219e 100644 --- a/test/clientTest.js +++ b/test/clientTest.js @@ -100,7 +100,8 @@ for (const supportedVersion of mc.supportedVersions) { const client = mc.createClient({ username: 'Player', version: version.minecraftVersion, - port: PORT + port: PORT, + auth: 'offline' }) client.on('error', err => done(err)) const lineListener = function (line) { @@ -149,7 +150,8 @@ for (const supportedVersion of mc.supportedVersions) { const client = mc.createClient({ username: 'Player', version: version.minecraftVersion, - port: PORT + port: PORT, + auth: 'offline' }) client.on('error', err => done(err)) client.on('login', function () { @@ -167,7 +169,8 @@ for (const supportedVersion of mc.supportedVersions) { const client = mc.createClient({ username: 'Player', version: version.minecraftVersion === '1.8.8' ? '1.11.2' : '1.8.8', - port: PORT + port: PORT, + auth: 'offline' }) client.once('error', function (err) { if (err.message.startsWith('This server is version')) { @@ -215,7 +218,8 @@ for (const supportedVersion of mc.supportedVersions) { username: process.env.MC_USERNAME, password: process.env.MC_PASSWORD, version: version.minecraftVersion, - port: PORT + port: PORT, + auth: 'offline' }) client.on('error', err => done(err)) const lineListener = function (line) { @@ -252,7 +256,8 @@ for (const supportedVersion of mc.supportedVersions) { const client = mc.createClient({ username: 'Player', version: version.minecraftVersion, - port: PORT + port: PORT, + auth: 'offline' }) client.on('error', err => done(err)) let gotKicked = false