Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide interface for using not at all supported alternative accounts. #1026

Merged
merged 9 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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`, `mojang`, or `offline`. default to 'offline'
* auth : the type of account to use, either `microsoft`, `mojang`, `offline` or `function (client, options) => void`. defaults to 'offline'.
* 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.
Expand Down
25 changes: 17 additions & 8 deletions docs/FAQ.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
## FAQ
# FAQ

This Frequently Asked Question document is meant to help people for the most common things.

### How to hide errors ?
## How to hide errors ?

Use `hideErrors: true` in createClient options
You may also choose to add these listeners :

```js
client.on('error', () => {})
client.on('end', () => {})
```

### How can I make a proxy with this ?
## How can I make a proxy with this ?

* Check out our WIP proxy lib <https://github.com/PrismarineJS/prismarine-proxy>
* See this example <https://github.com/PrismarineJS/node-minecraft-protocol/tree/master/examples/proxy>
* Read this issue <https://github.com/PrismarineJS/node-minecraft-protocol/issues/712>
* check out <https://github.com/Heath123/pakkit>
* Check out this app <https://github.com/wvffle/minecraft-packet-debugger>

## Can you support alternative auth methods?

Supporting alternative authentcation methods has been a long standing issue with Prismarine for awhile. We do add support for using your own custom authentication method by providing a function to the `options.auth` property. In order to keep the legitimacy of the project, and to prevent bad attention from Mojang, we will not be supporting any custom authentication methods in the official repositories.

It is up to the end user to support and maintain the authentication protocol if this is used as support in many of the official channels will be limited.

* Check out our WIP proxy lib https://github.com/PrismarineJS/prismarine-proxy
* See this example https://github.com/PrismarineJS/node-minecraft-protocol/tree/master/examples/proxy
* Read this issue https://github.com/PrismarineJS/node-minecraft-protocol/issues/712
* check out https://github.com/Heath123/pakkit
* Check out this app https://github.com/wvffle/minecraft-packet-debugger
If you still wish to proceed, please make sure to throughly read and attempt to understand all implementations of the authentcation you wish to implement. Using an non-official authentication server can make you vulnerable to all different kinds of attacks which are not limited to insecure and/or malicious code! We will not be held responsible for anything you mess up.
41 changes: 41 additions & 0 deletions examples/client_custom_auth/client_custom_auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict'

const mc = require('minecraft-protocol')

const [, , host, port, username, password] = process.argv
if (!username || !password) {
console.log('Usage : node client_custom_auth.js <host> <port> <username/email> [<password>]')
process.exit(1)
}

const client = mc.createClient({
host,
port: parseInt(port),
username: username,
password: password,
sessionServer: '', // URL to your session server proxy that changes the expected result of mojang's seession server to mcleaks expected.
// For more information: https://github.com/PrismarineJS/node-yggdrasil/blob/master/src/Server.js#L19
auth: async (client, options) => {
// handle custom authentication your way.

// client.username = options.username
// options.accessToken =
return options.connect(client)
}
})

client.on('connect', function () {
console.info('connected')
})
client.on('disconnect', function (packet) {
console.log('disconnected: ' + packet.reason)
})
client.on('chat', function (packet) {
const jsonMsg = JSON.parse(packet.message)
if (jsonMsg.translate === 'chat.type.announcement' || jsonMsg.translate === 'chat.type.text') {
const username = jsonMsg.with[0].text
const msg = jsonMsg.with[1]
if (username === client.username) return
client.write('chat', { message: msg })
}
})
10 changes: 10 additions & 0 deletions examples/client_custom_auth/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "node-minecraft-protocol-example-client-custom-auth",
"version": "0.0.0",
"description": "A node-minecraft-protocol example",
"main": "client_custom_auth.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": ""
}
30 changes: 17 additions & 13 deletions src/createClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,23 @@ function createClient (options) {
const client = new Client(false, version.minecraftVersion, options.customPackets, hideErrors)

tcpDns(client, options)
switch (options.auth) {
case 'mojang':
console.warn('[deprecated] mojang auth servers no longer accept mojang accounts to login. convert your account.\nhttps://help.minecraft.net/hc/en-us/articles/4403181904525-How-to-Migrate-Your-Mojang-Account-to-a-Microsoft-Account')
auth(client, options)
break
case 'microsoft':
microsoftAuth.authenticate(client, options)
break
case 'offline':
default:
client.username = options.username
options.connect(client)
break
if (options.auth instanceof Function) {
options.auth(client, options)
} else {
switch (options.auth) {
case 'mojang':
console.warn('[deprecated] mojang auth servers no longer accept mojang accounts to login. convert your account.\nhttps://help.minecraft.net/hc/en-us/articles/4403181904525-How-to-Migrate-Your-Mojang-Account-to-a-Microsoft-Account')
auth(client, options)
break
case 'microsoft':
microsoftAuth.authenticate(client, options)
break
case 'offline':
default:
client.username = options.username
options.connect(client)
break
}
}
if (options.version === false) autoVersion(client, options)
setProtocol(client, options)
Expand Down
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ declare module 'minecraft-protocol' {
export interface ClientOptions {
username: string
port?: number
auth?: 'mojang' | 'microsoft' | 'offline'
auth?: 'mojang' | 'microsoft' | 'offline' | ((client: Client, options: ClientOptions) => void)
password?: string
host?: string
clientToken?: string
Expand Down