node-minecraft-protocol/README.md

143 lines
4 KiB
Markdown
Raw Normal View History

2015-04-16 16:07:18 -04:00
# minecraft protocol
[![NPM version](https://img.shields.io/npm/v/minecraft-protocol.svg)](http://npmjs.com/package/minecraft-protocol)
2015-07-27 19:13:24 -04:00
[![Build Status](https://img.shields.io/circleci/project/PrismarineJS/node-minecraft-protocol/master.svg)](https://circleci.com/gh/PrismarineJS/node-minecraft-protocol)
[![Join the chat at https://gitter.im/PrismarineJS/node-minecraft-protocol](https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg)](https://gitter.im/PrismarineJS/node-minecraft-protocol)
2015-03-22 22:09:38 -04:00
2013-01-01 21:02:07 -05:00
Parse and serialize minecraft packets, plus authentication and encryption.
2013-01-01 16:01:43 -05:00
## Features
* Supports Minecraft version 1.7.10, 1.8.8 and 1.9 (15w40b and 16w05b)
2013-01-04 23:16:48 -05:00
* Parses all packets and emits 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-04 23:16:48 -05:00
* Client
- Authenticating and logging in
2015-03-06 14:54:27 -05:00
- Encryption
- Compression
2013-01-04 23:16:48 -05:00
- Both online and offline mode
- Respond to keep-alive packets.
- Ping a server for status
* Server
2015-03-06 14:54:27 -05:00
- Online/Offline mode
- Encryption
- Compression
2013-01-04 23:16:48 -05:00
- Handshake
- Keep-alive checking
- Ping status
* Robust test coverage.
2013-01-01 16:01:43 -05:00
* Optimized for rapidly staying up to date with Minecraft protocol updates.
## Third Party Plugins
node-minecraft-protocol is pluggable.
* [minecraft-protocol-forge](https://github.com/PrismarineJS/node-minecraft-protocol-forge) add forge support to minecraft-protocol
2013-01-01 16:01:43 -05:00
2013-02-12 13:58:53 -05:00
## Projects Using node-minecraft-protocol
* [mineflayer](https://github.com/PrismarineJS/mineflayer/) - create minecraft
2013-02-12 13:58:53 -05:00
bots with a stable, high level API.
* [mcserve](https://github.com/andrewrk/mcserve) - runs and monitors your
2013-02-12 13:58:53 -05:00
minecraft server, provides real-time web interface, allow your users to
create bots.
* [flying-squid](https://github.com/PrismarineJS/flying-squid) create minecraft
2015-08-30 15:34:28 -04:00
servers with a high level API, also a minecraft server by itself.
2013-01-07 14:42:28 -05:00
## Usage
2013-01-03 21:42:35 -05:00
### Echo client example
```js
var mc = require('minecraft-protocol');
var client = mc.createClient({
host: "localhost", // optional
port: 25565, // optional
username: "email@example.com",
password: "12345678",
});
2014-04-11 13:40:15 -04:00
client.on('chat', function(packet) {
2013-01-03 21:42:35 -05:00
// Listen for chat messages and echo them back.
var jsonMsg = JSON.parse(packet.message);
if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
var username = jsonMsg.with[0].text;
var msg = jsonMsg.with[1];
if(username === client.username) return;
client.write('chat', {message: msg});
}
});
```
If the server is in offline mode, you may leave out the `password` option.
2013-01-03 22:01:17 -05:00
### Hello World server example
```js
var mc = require('minecraft-protocol');
var server = mc.createServer({
2013-01-04 01:45:57 -05:00
'online-mode': true, // optional
encryption: true, // optional
host: '0.0.0.0', // optional
port: 25565, // optional
2013-01-03 22:01:17 -05:00
});
2013-01-04 01:45:57 -05:00
server.on('login', function(client) {
2014-04-11 13:40:15 -04:00
client.write('login', {
entityId: client.id,
2013-01-03 22:01:17 -05:00
levelType: 'default',
gameMode: 0,
dimension: 0,
difficulty: 2,
maxPlayers: server.maxPlayers,
reducedDebugInfo: false
2013-01-03 22:01:17 -05:00
});
2014-04-11 13:40:15 -04:00
client.write('position', {
2013-01-03 22:01:17 -05:00
x: 0,
y: 1.62,
z: 0,
yaw: 0,
pitch: 0,
flags: 0x00
2013-01-03 22:01:17 -05:00
});
var msg = {
translate: 'chat.type.announcement',
"with": [
'Server',
'Hello, world!'
]
};
client.write("chat", { message: JSON.stringify(msg), position: 0 });
2013-01-03 22:01:17 -05:00
});
```
2013-01-05 00:55:24 -05:00
## Installation
`npm install minecraft-protocol`
2015-03-06 14:54:27 -05:00
URSA, an optional dependency, should improve login times
for servers. However, it can be somewhat complicated to install.
Follow the instructions from
[Obvious/ursa](https://github.com/Obvious/ursa)
2013-01-05 00:55:24 -05:00
## Documentation
See [doc](doc/README.md)
## Testing
* Ensure your system has the `java` executable in `PATH`.
* `MC_SERVER_JAR_DIR=some/path/to/store/minecraft/server/ MC_USERNAME=email@example.com MC_PASSWORD=password npm test`
2013-01-02 01:47:18 -05:00
## Debugging
You can enable some protocol debugging output using `NODE_DEBUG` environment variable:
```bash
NODE_DEBUG="minecraft-protocol" node [...]
```
2013-01-26 15:35:52 -05:00
## History
2014-10-19 11:55:27 -04:00
See [history](HISTORY.md)