mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 10:55:05 -05:00
add offline as an auth mode
This commit is contained in:
parent
5a653f68fe
commit
0d8fea2445
9 changed files with 25 additions and 19 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
2
src/index.d.ts
vendored
2
src/index.d.ts
vendored
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue