Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit af31ece
Author: Romain Beaumont <[email protected]>
Date:   Tue Aug 16 01:00:53 2022 +0200

    Release 1.36.0

commit 79afd27
Author: IceTank <[email protected]>
Date:   Tue Aug 16 00:57:47 2022 +0200

    Fix unhandled promise rejection on ms auth (PrismarineJS#1022)

commit d7c5053
Author: extremeheat <[email protected]>
Date:   Mon Aug 15 18:57:26 2022 -0400

    1.19.0 support (PrismarineJS#1027)

    * Bump mcdata for 1.19

    * 1.19 in version.js

    * 1.19.0 in ci yml

    * Update ci.yml

    * Update version.js

    * Update package.json

    * No fail fast

    * Update mcdata

    * Update package.json

    * Update ci.yml

    * [1.19] fix tests and library session code (PrismarineJS#1020)

    * make tests work, add todo's

    * clean up, varlong test, additional todo

    * removed log statements, fix for older versions

    * Update mcdata

    * Update ci.yml

    * Update ci.yml

    * remove excessive version comments near supportFeature checks

    Co-authored-by: Romain Beaumont <[email protected]>

    * chat signing implementation

    * Update ci.yml

    * move some boilerplate to pauth

    * update tests

    * update chat example

    * bump pauth, update doc

    * modify test nextMessage func

    * lint

    * update default version

    * add server player verifyMessage

    * update doc

    Co-authored-by: Romain Beaumont <[email protected]>
    Co-authored-by: Rob9315 <[email protected]>

commit 60379eb
Author: Jordan Jones <[email protected]>
Date:   Fri Jul 29 09:41:43 2022 -0700

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

    * Handle auth potentially being an function

    * "Simple" example of how in theroy it would work

    * Add package.json

    * Fix lint

    * add type declarations

    * Remove mcleaks example

    * Add doc changes

    * adjust warning

    * Fix lint from rebase manual edit.

commit e079e9b
Author: Jordan Jones <[email protected]>
Date:   Fri Jul 29 09:03:20 2022 -0700

    Use offline mode as default authentication, fallback to offline mode if invalid option. (PrismarineJS#998)

    * Default n-m-p to use offline unless specified.

    * Remove expression

    * actually make offline default

    * Revert examples

    * Revert all example changes

    * Add deprecation warning that mojang servers are no longer accepting mojang auth tokens.

commit e4c797d
Author: Romain Beaumont <[email protected]>
Date:   Fri Jul 22 22:20:55 2022 +0200

    Release 1.35.1 (PrismarineJS#1024)

    * Update HISTORY.md

    * Update package.json

commit 92fd00d
Author: Rob9315 <[email protected]>
Date:   Thu Jul 21 22:56:34 2022 +0200

    add type values to packetTest (PrismarineJS#1023)

    * add varlong value to packetTest

    * add command_node type value in packetTest

commit 446d1d9
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue Jul 19 22:47:52 2022 +0200

    Bump readable-stream from 3.6.0 to 4.1.0 (PrismarineJS#1014)

    Bumps [readable-stream](https://github.com/nodejs/readable-stream) from 3.6.0 to 4.1.0.
    - [Release notes](https://github.com/nodejs/readable-stream/releases)
    - [Commits](nodejs/readable-stream@v3.6.0...v4.1.0)

    ---
    updated-dependencies:
    - dependency-name: readable-stream
      dependency-type: direct:production
      update-type: version-update:semver-major
    ...

    Signed-off-by: dependabot[bot] <[email protected]>

    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 50de598
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Tue Jul 19 22:47:36 2022 +0200

    Bump @types/node from 17.0.45 to 18.0.6 (PrismarineJS#1017)

    Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 17.0.45 to 18.0.6.
    - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
    - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

    ---
    updated-dependencies:
    - dependency-name: "@types/node"
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...

    Signed-off-by: dependabot[bot] <[email protected]>

    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 6cc3cfc
Author: Rob9315 <[email protected]>
Date:   Tue Jul 19 22:47:18 2022 +0200

    add custom minecraft type `varlong` which aliases to varint (PrismarineJS#1018)

    * add custom minecraft type varlong which aliases to varint for now or forever

    * semicolon (standard-js)
  • Loading branch information
LucienHH committed Aug 19, 2022
1 parent 50bc31e commit 7741015
Show file tree
Hide file tree
Showing 27 changed files with 650 additions and 342 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
mcVersion: ['1.7', '1.8', '1.9', '1.10', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17', '1.17.1', '1.18.2']
mcVersion: ['1.7', '1.8', '1.9', '1.10', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17', '1.17.1', '1.18.2', '1.19']
fail-fast: false

steps:
- uses: actions/checkout@v2
Expand Down
19 changes: 14 additions & 5 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ automatically logged in and validated against mojang's auth.
* hideErrors : do not display errors, default to false
* agent : a http agent that can be used to set proxy settings for yggdrasil authentication confirmation (see proxy-agent on npm)
* validateChannelProtocol (optional) : whether or not to enable protocol validation for custom protocols using plugin channels for the connected clients. Defaults to true
* enforceSecureProfile (optional) : Kick clients that do not have chat signing keys from Mojang (1.19+)

## mc.Server(version,[customPackets])

Expand All @@ -40,6 +41,10 @@ Create a server instance for `version` of minecraft.

Write a packet to all `clients` but encode it only once.

### client.verifyMessage(packet) : boolean

Verifies if player's chat message packet was signed with their Mojang provided key

### server.onlineModeExceptions

This is a plain old JavaScript object. Add a key with the username you want to
Expand Down Expand Up @@ -93,7 +98,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 'mojang'
* 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 Expand Up @@ -132,8 +137,7 @@ Returns a `Client` instance and perform login.
* realms : An object which should contain one of the following properties: `realmId` or `pickRealm`. When defined will attempt to join a Realm without needing to specify host/port. **The authenticated account must either own the Realm or have been invited to it**
* realmId : The id of the Realm to join.
* pickRealm(realms) : A function which will have an array of the user Realms (joined/owned) passed to it. The function should return a Realm.


* disableChatSigning (optional) : Don't try obtaining chat signing keys from Mojang (1.19+)

## mc.Client(isServer,version,[customPackets])

Expand Down Expand Up @@ -272,6 +276,13 @@ Start emitting channel events of the given name on the client object.

Unregister a channel `name` and send the unregister packet if `custom` is true.

### client.signMessage(message: string, timestamp: BigInt, salt?: number) : Buffer

Generate a signature for a chat message to be sent to server

### client.verifyMessage(publicKey: Buffer | KeyObject, packet) : boolean

Verifies a player chat packet sent by another player against their public key

## Not Immediately Obvious Data Type Formats

Expand Down Expand Up @@ -352,5 +363,3 @@ Returns a minecraft protocol [serializer](https://github.com/roblabla/ProtoDef#s
## mc.createDeserializer({ state = states.HANDSHAKING, isServer = false, packetsToParse = {"packet": true}, version })

Returns a minecraft protocol [deserializer](https://github.com/roblabla/ProtoDef#parserprotomaintype) for these parameters.


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.
11 changes: 11 additions & 0 deletions docs/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# History

## 1.36.0

* Use offline mode as default authentication, fallback to offline mode if invalid option. (@Kashalls)
* Provide interface for using not at all supported alternative accounts. (@Kashalls)
* 1.19 support (@extremeheat)
* Fix unhandled promise rejection on ms auth (@IceTank)

## 1.35.1

* add custom minecraft type varlong which aliases to varint @rob9315

## 1.35.0

* Add option to not answer to pings (@matthi4s)
Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var client = mc.createClient({
port: 25565, // optional
username: "[email protected]",
password: "12345678",
auth: 'mojang' // optional; by default uses mojang, if using a microsoft account, set to 'microsoft'
auth: 'microsoft' // optional; by default uses offline mode, if using a microsoft account, set to 'microsoft'
});
client.on('chat', function(packet) {
// Listen for chat messages and echo them back.
Expand All @@ -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 and switch 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.

### Client example joining a Realm
Expand Down
130 changes: 67 additions & 63 deletions examples/client_chat/client_chat.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,28 @@
const readline = require('readline')
const mc = require('minecraft-protocol')
const states = mc.states

const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
})

function printHelp () {
console.log('usage: node client_chat.js <hostname> <port> <user> [<password>]')
}

if (process.argv.length < 5) {
console.log('Too few arguments!')
printHelp()
const [,, host, port, username] = process.argv
if (!host || !port) {
console.error('Usage: node client_chat.js <host> <port> <username>')
console.error('Usage (offline mode): node client_chat.js <host> <port> offline')
process.exit(1)
}

process.argv.forEach(function (val) {
if (val === '-h') {
printHelp()
process.exit(0)
}
})

let host = process.argv[2]
let port = parseInt(process.argv[3])
const user = process.argv[4]
const passwd = process.argv[5]

let ChatMessage

if (host.indexOf(':') !== -1) {
port = host.substring(host.indexOf(':') + 1)
host = host.substring(0, host.indexOf(':'))
}

console.log('connecting to ' + host + ':' + port)
console.log('user: ' + user)

const client = mc.createClient({
host: host,
port: port,
username: user,
password: passwd
})

client.on('kick_disconnect', function (packet) {
console.info('Kicked for ' + packet.reason)
process.exit(1)
})

const chats = []

client.on('connect', function () {
ChatMessage = require('prismarine-chat')(client.version)
console.info('Successfully connected to ' + host + ':' + port)
host,
port,
username,
auth: username === 'offline' ? 'offline' : 'microsoft'
})

// Boilerplate
client.on('disconnect', function (packet) {
console.log('disconnected: ' + packet.reason)
console.log('Disconnected from server : ' + packet.reason)
})

client.on('end', function () {
Expand All @@ -69,19 +31,66 @@ client.on('end', function () {
})

client.on('error', function (err) {
console.log('Error occured')
console.log('Error occurred')
console.log(err)
process.exit(1)
})

client.on('connect', () => {
const mcData = require('minecraft-data')(client.version)
const ChatMessage = require('prismarine-chat')(client.version)
const players = {} // 1.19+

console.log('Connected to server')

client.chat = (message) => {
if (mcData.supportFeature('signedChat')) {
const timestamp = BigInt(Date.now())
client.write('chat_message', {
message,
timestamp,
salt: 0,
signature: client.signMessage(message, timestamp)
})
} else {
client.write('chat', { message })
}
}

function onChat (packet) {
const message = packet.message || packet.unsignedChatContent || packet.signedChatContent
const j = JSON.parse(message)
const chat = new ChatMessage(j)

if (packet.signature) {
const verified = client.verifyMessage(players[packet.senderUuid].publicKey, packet)
console.info(verified ? 'Verified: ' : 'UNVERIFIED: ', chat.toAnsi())
} else {
console.info(chat.toAnsi())
}
}

client.on('chat', onChat)
client.on('player_chat', onChat)
client.on('player_info', (packet) => {
if (packet.action === 0) { // add player
for (const player of packet.data) {
players[player.UUID] = player.crypto
}
}
})
})

// Send the queued messages
const queuedChatMessages = []
client.on('state', function (newState) {
if (newState === states.PLAY) {
chats.forEach(function (chat) {
client.write('chat', { message: chat })
})
if (newState === mc.states.PLAY) {
queuedChatMessages.forEach(message => client.chat(message))
queuedChatMessages.length = 0
}
})

// Listen for messages written to the console, send them to game chat
rl.on('line', function (line) {
if (line === '') {
return
Expand All @@ -93,14 +102,9 @@ rl.on('line', function (line) {
console.info('Forcibly ended client')
process.exit(0)
}
if (!client.write('chat', { message: line })) {
chats.push(line)
if (!client.chat) {
queuedChatMessages.push(line)
} else {
client.chat(line)
}
})

client.on('chat', function (packet) {
if (!ChatMessage) return // Return if ChatMessage is not loaded yet.
const j = JSON.parse(packet.message)
const chat = new ChatMessage(j)
console.info(chat.toAnsi())
})
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": ""
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minecraft-protocol",
"version": "1.35.0",
"version": "1.36.0",
"description": "Parse and serialize minecraft packets, plus authentication and encryption.",
"main": "src/index.js",
"types": "src/index.d.ts",
Expand Down Expand Up @@ -33,7 +33,7 @@
},
"browser": "src/browser.js",
"devDependencies": {
"@types/node": "^17.0.4",
"@types/node": "^18.0.6",
"espower-loader": "^1.0.0",
"intelli-espower-loader": "^1.0.0",
"minecraft-packets": "^1.1.5",
Expand All @@ -51,15 +51,15 @@
"endian-toggle": "^0.0.0",
"lodash.get": "^4.1.2",
"lodash.merge": "^4.3.0",
"minecraft-data": "^3.0.0",
"minecraft-data": "^3.8.0",
"minecraft-folder-path": "^1.2.0",
"node-fetch": "^2.6.1",
"node-rsa": "^0.4.2",
"prismarine-auth": "^1.1.0",
"prismarine-auth": "^1.7.0",
"prismarine-nbt": "^2.0.0",
"prismarine-realms": "^1.2.0",
"protodef": "^1.8.0",
"readable-stream": "^3.0.6",
"readable-stream": "^4.1.0",
"uuid-1345": "^1.0.1",
"yggdrasil": "^1.4.0"
}
Expand Down
Loading

0 comments on commit 7741015

Please sign in to comment.