2012-12-24 13:55:46 -05:00
|
|
|
# minecraft protocol
|
|
|
|
|
2013-01-01 21:02:07 -05:00
|
|
|
Parse and serialize minecraft packets, plus authentication and encryption.
|
2013-01-01 04:14:38 -05:00
|
|
|
|
2013-01-01 16:01:43 -05:00
|
|
|
## Features
|
|
|
|
|
2013-01-01 21:02:07 -05:00
|
|
|
* Parses all packets and emits `packet` events with packet fields as JavaScript
|
2013-01-01 16:01:43 -05:00
|
|
|
objects.
|
|
|
|
* Send a packet by supplying fields as a JavaScript object.
|
2013-01-01 21:02:07 -05:00
|
|
|
* Supports authenticating and logging in.
|
2013-01-02 02:22:00 -05:00
|
|
|
- Supports encryption
|
2013-01-01 21:02:07 -05:00
|
|
|
- Supports online mode
|
2013-01-02 02:22:00 -05:00
|
|
|
- Supports offline mode
|
2013-01-02 02:33:40 -05:00
|
|
|
* Respond to keep-alive packets.
|
|
|
|
* Test coverage
|
|
|
|
- encryption
|
|
|
|
- authentication/online mode
|
|
|
|
- offline mode
|
|
|
|
- initialization packets
|
2013-01-01 16:01:43 -05:00
|
|
|
* Optimized for rapidly staying up to date with Minecraft protocol updates.
|
|
|
|
|
|
|
|
## Minecraft Compatibility
|
|
|
|
|
|
|
|
Supports Minecraft version 1.4.6
|
|
|
|
|
2013-01-01 23:39:31 -05:00
|
|
|
## Usage
|
2013-01-01 04:14:38 -05:00
|
|
|
|
2013-01-01 23:39:31 -05:00
|
|
|
### Echo example
|
|
|
|
|
|
|
|
Listen for chat messages and echo them back.
|
|
|
|
|
|
|
|
```js
|
|
|
|
var mc = require('minecraft-protocol');
|
|
|
|
var client = mc.createClient({
|
|
|
|
host: "localhost", // optional
|
|
|
|
port: 25565, // optional
|
|
|
|
username: "player",
|
|
|
|
email: "email@example.com", // email and password are required only for
|
2013-01-02 06:35:10 -05:00
|
|
|
password: "12345678", // online-mode=true servers
|
2013-01-01 23:39:31 -05:00
|
|
|
});
|
2013-01-02 21:59:40 -05:00
|
|
|
client.on('packet-3', function(packet) {
|
2013-01-01 23:39:31 -05:00
|
|
|
if (packet.message.indexOf(client.session.username) !== -1) return;
|
|
|
|
client.writePacket(0x03, {
|
|
|
|
message: packet.message,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
2013-01-02 01:12:42 -05:00
|
|
|
|
|
|
|
## Testing
|
|
|
|
|
|
|
|
* Ensure your system has the `java` executable in `PATH`.
|
2013-01-02 01:47:18 -05:00
|
|
|
* Download the appropriate version of `minecraft_server.jar`.
|
2013-01-02 01:12:42 -05:00
|
|
|
* `MC_SERVER_JAR=path/to/minecraft_server.jar MC_USERNAME=username MC_EMAIL=email@example.com MC_PASSWORD=password npm test`
|
2013-01-02 01:47:18 -05:00
|
|
|
|
|
|
|
## Updating to a newer protocol version
|
|
|
|
|
|
|
|
In most cases you should only have to do the following:
|
|
|
|
|
|
|
|
1. In `packets.json`:
|
|
|
|
* Update `protocolVersion` to the correct number.
|
|
|
|
* Edit the data structure to reflect the new packet layout.
|
|
|
|
2. Update the "Minecraft Compatibility" section above in this README.
|
|
|
|
3. Run the test suite to make sure everything still works. See "Testing" above.
|