Parse and serialize minecraft packets, plus authentication and encryption.
Find a file
2013-01-04 21:42:31 -05:00
examples server API update 2013-01-04 20:22:19 -05:00
lib passing test: pinging a real minecraft server 2013-01-04 21:42:31 -05:00
test passing test: pinging a real minecraft server 2013-01-04 21:42:31 -05:00
.gitignore getting encryption request 2012-12-31 20:33:35 -05:00
index.js add test, ping, and 2 API changes 2013-01-04 21:33:19 -05:00
package.json avoid dependency on iconv. makes it easier to use on windows. see #12 2013-01-04 19:04:06 -05:00
README.md refactor + createServer support 2013-01-04 01:45:57 -05:00

minecraft protocol

Parse and serialize minecraft packets, plus authentication and encryption.

Features

  • Parses all packets and emits packet events with packet fields as JavaScript objects.
  • Send a packet by supplying fields as a JavaScript object.
  • Supports authenticating and logging in.
    • Supports encryption (client only)
    • Supports online mode (client only)
    • Supports offline mode
  • Respond to keep-alive packets.
  • Test coverage
    • encryption
    • authentication/online mode
    • offline mode
    • initialization packets
  • Optimized for rapidly staying up to date with Minecraft protocol updates.

Minecraft Compatibility

Supports Minecraft version 1.4.7pre

Usage

Echo client example

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
  password: "12345678",       // online-mode=true servers
});
client.on(0x03, function(packet) {
  // Listen for chat messages and echo them back.
  if (packet.message.indexOf(client.session.username) !== -1) return;
  client.write(0x03, {
    message: packet.message,
  });
});

Hello World server example

var mc = require('minecraft-protocol');
var server = mc.createServer({
  'online-mode': true,   // optional
  encryption: true,      // optional
  host: '0.0.0.0',       // optional
  port: 25565,           // optional
});
server.on('login', function(client) {
  client.write(0x01, {
    entityId: 0,
    levelType: 'default',
    gameMode: 0,
    dimension: 0,
    difficulty: 2,
    maxPlayers: server.maxPlayers
  });
  client.write(0x0d, {
    x: 0,
    y: 1.62,
    stance: 0,
    z: 0,
    yaw: 0,
    pitch: 0,
    onGround: true
  });
  client.write(0x03, { message: 'Hello, ' + client.username });
});

Testing

  • Ensure your system has the java executable in PATH.
  • 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

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.
  1. Update the "Minecraft Compatibility" section above in this README.
  2. Run the test suite to make sure everything still works. See "Testing" above.