node-minecraft-protocol/README.md

118 lines
3.1 KiB
Markdown
Raw Normal View History

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 16:01:43 -05:00
## Features
2013-01-04 23:22:48 -05:00
* Supports Minecraft version 1.4.7pre
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
- Encryption on and encryption off
- Both online and offline mode
- Respond to keep-alive packets.
- Ping a server for status
* Server
- Offline mode
- [TODO](https://github.com/superjoe30/node-minecraft-protocol/issues/13) -
Encryption and online mode
- Handshake
- Keep-alive checking
- Ping status
* Robust test coverage. See Test Coverage section below.
2013-01-01 16:01:43 -05:00
* Optimized for rapidly staying up to date with Minecraft protocol updates.
## 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: "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
});
client.on(0x03, function(packet) {
2013-01-03 21:42:35 -05:00
// Listen for chat messages and echo them back.
if (packet.message.indexOf(client.session.username) !== -1) return;
2013-01-03 21:42:35 -05:00
client.write(0x03, {
message: packet.message,
});
});
```
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) {
2013-01-03 22:01:17 -05:00
client.write(0x01, {
entityId: client.id,
2013-01-03 22:01:17 -05:00
levelType: 'default',
gameMode: 0,
dimension: 0,
difficulty: 2,
2013-01-04 01:45:57 -05:00
maxPlayers: server.maxPlayers
2013-01-03 22:01:17 -05:00
});
client.write(0x0d, {
x: 0,
y: 1.62,
stance: 0,
z: 0,
yaw: 0,
pitch: 0,
onGround: true
});
2013-01-04 01:45:57 -05:00
client.write(0x03, { message: 'Hello, ' + client.username });
2013-01-03 22:01:17 -05:00
});
```
2013-01-05 00:55:24 -05:00
## Installation
### Linux
`npm install minecraft-protocol`
### Windows
* Follow the Windows instructions from [Obvious/ursa](https://github.com/Obvious/ursa)
* `npm install minecraft-protocol`
## 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`.
* `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
2013-01-04 23:16:48 -05:00
### Test Coverage
```
client
✓ pings the server (6164ms)
✓ connects successfully - online mode (2527ms)
✓ connects successfully - offline mode (1902ms)
✓ gets kicked when no credentials supplied in online mode (3720ms)
✓ does not crash for 10000ms (11731ms)
mc-server
✓ starts listening and shuts down cleanly
✓ kicks clients that do not log in (103ms)
✓ kicks clients that do not send keepalive packets (104ms)
✓ responds to ping requests
✓ clients can log in and chat (43ms)
✓ gives correct reason for kicking clients when shutting down
11 tests complete (45 seconds)
```