Code Monkey home page Code Monkey logo

node-minecraft-protocol's Introduction

minecraft protocol

NPM version Build Status Discord Gitter Irc

Try it on gitpod

Parse and serialize minecraft packets, plus authentication and encryption.

Features

  • Supports Minecraft PC version 1.7.10, 1.8.8, 1.9 (15w40b, 1.9, 1.9.1-pre2, 1.9.2, 1.9.4), 1.10 (16w20a, 1.10-pre1, 1.10, 1.10.1, 1.10.2), 1.11 (16w35a, 1.11, 1.11.2), 1.12 (17w15a, 17w18b, 1.12-pre4, 1.12, 1.12.1, 1.12.2), and 1.13 (17w50a, 1.13, 1.13.1, 1.13.2-pre1, 1.13.2-pre2, 1.13.2), 1.14 (1.14, 1.14.1, 1.14.3, 1.14.4) , 1.15 (1.15, 1.15.1, 1.15.2) and 1.16 (20w13b, 20w14a, 1.16-rc1, 1.16, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5), 1.17 (21w07a, 1.17, 1.17.1), 1.18 (1.18, 1.18.1 and 1.18.2), 1.19 (1.19, 1.19.1, 1.19.2, 1.19.3, 1.19.4), 1.20 (1.20, 1.20.1, 1.20.2, 1.20.3 and 1.20.4)
  • Parses all packets and emits events with packet fields as JavaScript objects.
  • Send a packet by supplying fields as a JavaScript object.
  • Client
    • Authenticating and logging in
    • Encryption
    • Compression
    • Both online and offline mode
    • Respond to keep-alive packets
    • Follow DNS service records (SRV)
    • Ping a server for status
  • Server
    • Online/Offline mode
    • Encryption
    • Compression
    • Handshake
    • Keep-alive checking
    • Ping status
  • Robust test coverage.
  • Optimized for rapidly staying up to date with Minecraft protocol updates.

Want to contribute on something important for PrismarineJS ? go to https://github.com/PrismarineJS/mineflayer/wiki/Big-Prismarine-projects

Third Party Plugins

node-minecraft-protocol is pluggable.

Projects Using node-minecraft-protocol

  • mineflayer - Create minecraft bots with a stable, high level API.
  • mcserve - Runs and monitors your minecraft server, provides real-time web interface, allow your users to create bots.
  • flying-squid - Create minecraft servers with a high level API, also a minecraft server by itself.
  • pakkit - A GUI tool to monitor Minecraft packets in real time, allowing you to view their data and interactively edit and resend them.
  • minecraft-packet-debugger - A tool to capture Minecraft packets in a buffer then view them in a browser.
  • aresrpg - An open-source mmorpg minecraft server.
  • SteveProxy - Proxy for Minecraft with the ability to change the gameplay using plugins.
  • and several thousands others

Installation

npm install minecraft-protocol

Documentation

Usage

Echo client example

const mc = require('minecraft-protocol');
const client = mc.createClient({
  host: "localhost",   // optional
  port: 25565,                 // set if you need a port that isn't 25565
  username: 'Bot',             // username to join as if auth is `offline`, else a unique identifier for this account. Switch if you want to change accounts
  // version: false,           // only set if you need a specific version or snapshot (ie: "1.8.9" or "1.16.5"), otherwise it's set automatically
  // password: '12345678'      // set if you want to use password-based auth (may be unreliable). If specified, the `username` must be an email
});

client.on('playerChat', function (ev) {
  // Listen for chat messages and echo them back.
  const content = ev.formattedMessage
    ? JSON.parse(ev.formattedMessage)
    : ev.unsignedChat
      ? JSON.parse(ev.unsignedContent)
      : ev.plainMessage
  const jsonMsg = JSON.parse(packet.message)
  if (ev.senderName === client.username) return
  client.chat(JSON.stringify(content))
});

Set auth to offline if the server is in offline mode. If auth is set to microsoft, you will be prompted to login to microsoft.com with a code in your browser. After signing in on your browser, the client will automatically obtain and cache authentication tokens (under your specified username) so you don't have to sign-in again.

To switch the account, update the supplied username. By default, cached tokens will be stored in your user's .minecraft folder, or if profilesFolder is specified, they'll instead be stored there. For more information on bot options see the API doc.

Note: SRV records will only be looked up if the port is unspecified or set to 25565 and if the host is a valid non-local domain name.

Client example joining a Realm

Example to connect to a Realm that the authenticating account is owner of or has been invited to:

const mc = require('minecraft-protocol');
const client = mc.createClient({
  realms: {
    pickRealm: (realms) => realms[0] // Function which recieves an array of joined/owned Realms and must return a single Realm. Can be async
  },
  auth: 'microsoft'
})

Hello World server example

For a more up to date example, see examples/server/server.js.

const mc = require('minecraft-protocol')
const nbt = require('prismarine-nbt')
const server = mc.createServer({
  'online-mode': true,   // optional
  encryption: true,      // optional
  host: '0.0.0.0',       // optional
  port: 25565,           // optional
  version: '1.18'
})
const mcData = require('minecraft-data')(server.version)

function chatText (text) {
  return mcData.supportFeature('chatPacketsUseNbtComponents')
    ? nbt.comp({ text: nbt.string(text) })
    : JSON.stringify({ text })
}

server.on('playerJoin', function(client) {
  const loginPacket = mcData.loginPacket

  client.write('login', {
    ...loginPacket,
    entityId: client.id,
    hashedSeed: [0, 0],
    maxPlayers: server.maxPlayers,
    viewDistance: 10,
    reducedDebugInfo: false,
    enableRespawnScreen: true,
    isDebug: false,
    isFlat: false
  })

  client.write('position', {
    x: 0,
    y: 255,
    z: 0,
    yaw: 0,
    pitch: 0,
    flags: 0x00
  })

  const message = {
    translate: 'chat.type.announcement',
    with: [
      'Server',
      'Hello, world!'
    ]
  }
  if (mcData.supportFeature('signedChat')) {
    client.write('player_chat', {
      plainMessage: message,
      signedChatContent: '',
      unsignedChatContent: chatText(message),
      type: 0,
      senderUuid: 'd3527a0b-bc03-45d5-a878-2aafdd8c8a43', // random
      senderName: JSON.stringify({ text: 'me' }),
      senderTeam: undefined,
      timestamp: Date.now(),
      salt: 0n,
      signature: mcData.supportFeature('useChatSessions') ? undefined : Buffer.alloc(0),
      previousMessages: [],
      filterType: 0,
      networkName: JSON.stringify({ text: 'me' })
    })
  } else {
    client.write('chat', { message: JSON.stringify({ text: message }), position: 0, sender: 'me' })
  }
})

Testing

  • Ensure your system has the java executable in PATH.
  • MC_SERVER_JAR_DIR=some/path/to/store/minecraft/server/ [email protected] MC_PASSWORD=password npm test

Debugging

You can enable some protocol debugging output using DEBUG environment variable:

DEBUG="minecraft-protocol" node [...]

On Windows:

set DEBUG=minecraft-protocol
node your_script.js

Contribute

Please read https://github.com/PrismarineJS/prismarine-contribute

History

See history

Related

  • node-rcon can be used to access the rcon server in the minecraft server
  • map-colors can be used to convert any image into a buffer of minecraft compatible colors

node-minecraft-protocol's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-minecraft-protocol's Issues

Ping test broken.

Due to the latest addition of latency in ping.js, the test for ping is broken, the assertion being erroneous now..

How to send slot data correctly?

var input = {
    id: 5,
    itemCount: 56,
    itemDamage: 2,
    nbtData: new Buffer(90)
  };
client.write(0x67, {
    windowID: 0,
    slot: 36,
    item: input
  });

client returns

java.util.zip.ZipException: Not in GZIP format

and

  var zlib = require("zlib");
var input = new Buffer({
    id: 5,
    itemCount: 56,
    itemDamage: 2,
    nbtData: new Buffer(90)
  });

zlib.gzip(input, function(err, buffer) {
  if (!err) {
    console.log("OK");
    //console.log(input);
    //console.log(buffer);
    //console.log(buffer.toString('base64'));
client.write(0x67, {
    windowID: 0,
    slot: 36,
    item: buffer
  });
  }else{
  console.log(err);
  }
});

server returns

OK
/home/gjz010/node_modules/minecraft-protocol/lib/protocol.js:1266
  return value.id === -1 ? 2 : 7 + value.nbtData.length;
                                                ^
TypeError: Cannot read property 'length' of undefined
    at sizeOfSlot (/home/gjz010/node_modules/minecraft-protocol/lib/protocol.js:1266:49)
    at sizeOf (/home/gjz010/node_modules/minecraft-protocol/lib/protocol.js:1391:12)
    at /home/gjz010/node_modules/minecraft-protocol/lib/protocol.js:1405:13
    at Array.forEach (native)
    at createPacketBuffer (/home/gjz010/node_modules/minecraft-protocol/lib/protocol.js:1401:10)
    at Client.write (/home/gjz010/node_modules/minecraft-protocol/lib/client.js:92:16)
    at /home/gjz010/Download/hw.js:59:8
    at Gzip.onEnd (zlib.js:166:5)
    at Gzip.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:910:16

Then how to send it correctly?

Login with username instead of email

For the people who have not yet migrated their account to mojang accounts, being able to login with username/password combo should be possible.

packet id shorthands

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,
  });
});

versus

client.on(id.CHAT_MESSAGE, function(packet) {
  // Listen for chat messages and echo them back.
  if (packet.message.indexOf(client.session.username) !== -1) return;
  client.write(id.CHAT_MESSAGE, {
    message: packet.message,
  });
});

It's humanly impossible to remember all those packet ids, so giving them away with these nice shorthands would be very kind.

I refer to this site, when naming the packets. I don't know, if you know this wiki already, but it's super helpful. :D

client : username/email -> login

Been looking at the code, and there's something bugging me still about the client : we still have a distinction between the username and the email in the login. To fix this issue 100%, we would need to move the call to getLoginSession before the creation of the client, and get the actual username from it.
For 1, it would remove the batch job (which I personally find quiet ugly, but that's just me).
For 2, it would be more logical (we shouldn't login to the minecraft server before connecting to a server)...

Of course, getLoginSession would only be called if haveCredidentials is true.

The string dilemna

Right now, we have two string types, string and ustring. The former is limited to 255 characters, while the other isn't limited at all. The whole problem is, minecraft limits the length of certain fields to a certain amount of characters. Generally speaking, the limit is 255 characters, but that is not always the case.

Unfortunately, this has caused many issues in the library in the past, where a field would be marked as a "string" when it could receive input longer than 255 characters. To make matters worse, wiki.vg doesn't really give much insight in which fields are limited in length.

I suggest we simply remove the limit from the packets entirely. It should be the user's responsibility to make sure the other side doesn't give unwanted input, and thus sanitize the input.

crash: oob Buffer at readEntityMetadata

using this project as a proxy, every once in a while it crashes:

buffer.js:552
  if (end > this.length) throw new Error('oob');
                         ^
Error: oob
    at Buffer.slice (buffer.js:552:32)
    at readSlot (/home/andy/apps/mcserve/node_modules/minecraft-protocol/lib/protocol.js:1021:24)
    at readEntityMetadata (/home/andy/apps/mcserve/node_modules/minecraft-protocol/lib/protocol.js:741:15)
    at parsePacket (/home/andy/apps/mcserve/node_modules/minecraft-protocol/lib/protocol.js:1230:19)
    at Socket.Client.setSocket.ended (/home/andy/apps/mcserve/node_modules/minecraft-protocol/lib/client.js:30:16)
    at Socket.EventEmitter.emit (events.js:96:17)
    at TCP.onread (net.js:397:14)

remove socket delays to reduce latency

It is pretty important not to use socket delays (Nagle algorithm) for game networking as it
adds a lot of latency. By default, sockets wait (possibly up to a few hundred milliseconds)
before writing data, so it can combine data into 1 packet.

@mappum had a PR for this which got merged but then broke a bunch of tests. We still want to do it but need to figure out why it was breaking things first.

cutom types

I think custom types are more appropriate as plain objects.

[
  {type: 'slot', value: slot, key: 3},
  {type: 'int', value: value, key: 4},
  ...
]

versus something like

[
  new Slot(3, value),
  new Int(4, value),
  ...
]

trick to avoid using iconv

            for(var j = 0; j < stringLength; j++) {
                value += String.fromCharCode(buf.readUInt16BE(offset));
                offset += 2;
            }

Using a favicon raises assertion 'string greater than max length'

Using a favicon raises the assertion 'string greater than max length' and stack traces.

This seems to be due to the status packet's response var being cast as a string.

packet.js:

  "status": {
    "toClient": {
      0x00: [
        { name: "response", type: "string" }
      ],
      0x01: [
        { name: "time", type: "long" }
      ]
    },

Changing this to a ustring works fine and the current unit tests pass.

Send kick packet on End

I am not 100% sure about what I'm going to say here (I'm going on what I read the code), but I believe when you end a connection, you do so by simply ending the socket with some non-minecraft-standard (e.g. : KeepAliveTimeout).
A good idea would be to modify client.end() so it actually sends a kick packet, as to gracefully end the connection.

Client chatting can cause a crash

Sometimes when trying to chat using the client, the client will not chat, and will instead crash after a minute or two. Usually there is no stacktrace, but sometimes there is a connection reset stacktrace:

Error: write ECONNRESET
    at errnoException (net.js:770:11)
    at Object.afterWrite (net.js:594:19)

The notchian server always logs this as a timeout:

[INFO] helperbot lost connection: disconnect.timeout

Using a Windows host machine and localhost server, I have been able to reproduce the issue using examples/client_echo.js. In addition, this also happens when connecting a client running on Ubuntu in a VM to a Notchian server running in the Windows host machine, as well as running both the client and server on the Ubuntu VM.

Install issue on Linux

Hey, thanks for updating this!

I'm trying to install it on linux but it's not working, probably due to a reference somewhere to 'node' rahter than 'nodejs' - on linux there was a conflict with that.

I ran this command:
npm install minecraft-protocol@latest

and it failed with this error:
sh: 1: node: not found
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR! weird error 127
npm ERR! not ok code 0

Hope that helps.

Chat packet string max length

In the chat packet, a server may send a string of a length up to 32767 characters since 1.2.5 to the client (however, client is still limited to 240 characters). Right now, a server sending more than 240 characters will cause node-minecraft-protocol to crash.

Needs update for 1.6.2

Tried modifying the code and changing the exports to the new version numbers. Caused Minecraft Client to crash upon connection.

Bug in protocol.js

Not sure if this is a bug or not, so no pull request yet. The line here has no effect. Should it be a single equals?

some data types lack writers

'entityMetadata'
'byteArray32'
'slotArray':
'mapChunkBulk':
'objectData'
'intArray8
'intVector'
'byteVector
'byteVectorArray

this is causing the following packets to be unwritable:

1) 0x14
2) 0x17
3) 0x18
4) 0x1d
5) 0x28
6) 0x33
7) 0x34
8) 0x38
9) 0x3c
10) 0x68

crash: AssertionError: value is larger than maximum value for type

assert.js:102
  throw new assert.AssertionError({
        ^
AssertionError: value is larger than maximum value for type
    at verifuint (buffer.js:857:10)
    at Buffer.writeUInt8 (buffer.js:875:5)
    at performTwosCompliment (/home/andy/dev/mc-proxy/node_modules/minecraft-protocol/index.js:362:16)
    at mcHexDigest (/home/andy/dev/mc-proxy/node_modules/minecraft-protocol/index.js:347:17)
    at verifyUsername (/home/andy/dev/mc-proxy/node_modules/minecraft-protocol/index.js:157:22)
    at Client.onEncryptionKeyResponse (/home/andy/dev/mc-proxy/node_modules/minecraft-protocol/index.js:154:7)
    at Client.g (events.js:192:14)
    at Client.EventEmitter.emit (events.js:96:17)
    at Socket.Client.setSocket.ended (/home/andy/dev/mc-proxy/node_modules/minecraft-protocol/lib/client.js:39:12)
    at Socket.EventEmitter.emit (events.js:96:17)
    at TCP.onread (net.js:397:14)

Exception after disconnect

Unfortunately, I was not immediately able to reproduce this. I had setup the HelloWorld example posted on the npmjs page, the code of which is in this handy gist.

Some small amount of time after disconnecting from the working example, the server crashed throwing this error:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: write after end
    at writeAfterEnd (_stream_writable.js:125:12)
    at Socket.Writable.write (_stream_writable.js:170:5)
    at Socket.write (net.js:596:40)
    at Client.write (/home/navarr/minecraft-server/node_modules/minecraft-protocol/lib/client.js:96:15)
    at Client.end (/home/navarr/minecraft-server/node_modules/minecraft-protocol/lib/server.js:27:14)
    at Timer.keepAliveLoop (/home/navarr/minecraft-server/node_modules/minecraft-protocol/index.js:67:16)
    at Timer.timer.ontimeout (timers.js:247:14)

Getting reason for disconnect

I tried to create a Script that connects to a offline Server sends a Message and immediatly disconnects. Im currently looking to get the reason, why the client is disconnected. Basically in order to check if the username is banned or the client failed to Authenticate with minecraft.net

var mc = require('minecraft-protocol');
var client = mc.createClient({
  host: "192.168.178.22",   
  port: 80,       
  username: "test",
});

client.on('connect', function() {
  console.info("connected"); 
});

client.on('end', function(reason) {
  console.info(reason);
  response.end();
  console.log("---ENDED----");          
});

client.on(0x01, function() {
  client.write(0x03, { message: "dsasda",});
  setTimeout(function() {
  client.end();
  console.log('disconnected');
  return;
  }, 1);        
});

Unimplemented packetIDs for 1.5

With or without keepAlive: true the client randomly crashes without any errors.
The Server shows this error:

java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(SocketInputStream.java:189)
        at java.net.SocketInputStream.read(SocketInputStream.java:121)
        at java.io.FilterInputStream.read(FilterInputStream.java:133)
        at asa.a(Unknown Source)
        at asa.read(Unknown Source)
        at java.io.FilterInputStream.read(FilterInputStream.java:83)
        at ei.a(SourceFile:185)
        at ci.i(SourceFile:250)
        at ci.c(SourceFile:16)
        at cj.run(SourceFile:94)
2013-03-14 18:12:11 [INFO] username lost connection: disconnect.genericReason

OOB

buffer.js:552
  if (end > this.length) throw new Error('oob');
                               ^
Error: oob
    at Buffer.slice (buffer.js:552:32)
    at readSlot (/home/contra/Projects/minebot/node_modules/mineflayer/node_modules/minecraft-protocol/lib/protocol.js:855:24)
    at readSlotArray (/home/contra/Projects/minebot/node_modules/mineflayer/node_modules/minecraft-protocol/lib/protocol.js:743:15)
    at parsePacket (/home/contra/Projects/minebot/node_modules/mineflayer/node_modules/minecraft-protocol/lib/protocol.js:1017:19)
    at Socket.Client.setSocket (/home/contra/Projects/minebot/node_modules/mineflayer/node_modules/minecraft-protocol/lib/client.js:32:16)
    at Socket.EventEmitter.emit (events.js:96:17)
    at TCP.onread (net.js:397:14)

Happens after connecting to play.dakotakraft.com - I get a weird nonSpokenChat (f f 1 0 2 4f f 4 0 9 6f f 2 0 4 83 9 2 0 0 13 9 2 0 0 23 9 2 0 0 3001fe002fe00345678fe01012ff0134ff015ff016ff0189abff017ff ) then the error

Update needed for 1.7

What's left before the next release:

  • Update protocol definition
  • Add a way to listen to packets by name.
  • Add container/array type and remove old, extremely verbose types
  • Add opportunistic packet parsing
  • Update docs and release notes

Edited by roblabla

Packet 0x66: rename "shift" to "mode"?

In node-minecraft-protocol, packet 0x66 (Click Window) has the following structure:

  0x66: [
    { name: "windowId", type: "byte" },
    { name: "slot", type: "short" },
    { name: "mouseButton", type: "byte" },
    { name: "action", type: "short" },
    { name: "shift", type: "byte" },
    { name: "item", type: "slot" }
  ],

According to the documentation, "shift" has been renamed to "mode", with the following description:

Mode: Inventory operation mode. 0 - regular mouse click. 1 - mouse click while holding shift. 5 - "painting" mode packet (see below). 6 - mouse double-click (used to group stacks into one picked up, is sent immediately after normal mouse click packet (which picks item up)).

Do you think it is appropriate to rename this field?

Transform asserts into proper error managements

A lot of times, I find myself unable to debug an issue because my program will prematurely quit due to an assert failing at the protocol level. This is very problematic, and it would be nice if, instead of using asserts everywhere, the "error" event was triggered. It would help both for debug and recovering the application when it is still possible.

What would be the correct approach for sending the initial chunk?

Hello! I found this module really useful for my project. Now I've managed to get a server where I can log in, talk and al, so now I'm going to try to send an initial world. I've been trying with this code to generate a world (which I found on a similar project):

var generate_world = function(callback) {
  var chunk = new Buffer(16 * 16 * 128 + 16384 * 3);
    var index = 0;

    for (var x = 0; x < 16; x++) {
        for (var z = 0; z < 16; z++) {
            for (var y = 0; y< 128; y++) {
                index = y + (z * 128) + (x * 128 * 16);
                if (y > 62) {
                    chunk.writeUInt8(0, index);
                } else {
                    chunk.writeUInt8(1, index);
                }
                if (y <= 1) {
                    chunk.writeUInt8(7, index);
                }
            }
        }
    }

    chunk.fill(0, 32768, 32768+16384); // empty metadata
    chunk.fill(255, 32768+16384, 32768+16384*2); // full brightness
    chunk.fill(255, 32768 + 16384*2, 32768+16384*3); //full sky light

  console.log('Uncompressed chunk size: ' + chunk.length);

  var compressor = zlib.Deflate();

  var data = [];
  compressor.on('data', function(data_part) { 
    data.push(data_part);
  });
  compressor.on('end', function() {
    var total_length = 0;
    for (i in data) {
      total_length = data[i].length;
    }
    console.log('Chunk size after compression: ' + total_length);
    var out_data = new Buffer(total_length);
    var pointer = 0;
    for (i in data) {
      data[i].copy(out_data, pointer, 0);
      pointer += data[i].length;
    }
    callback(out_data);

  });
  compressor.write(chunk);
  compressor.end();
  if (!callback) {
    return chunk;
  }
}

world = generate_world(function(table_chunk) {
  console.log('Chunk size ' + table_chunk.length);
  return table_chunk;

});

world_length = generate_world(function(table_chunk) {

    return table_chunk.length;
});

And then using this for sending it:

client.write(0x38, {
    chunkColumnCount: 1,
    dataLength: world_length,
    skyLightSent: true,
    compressedChunkData: world,
    meta:null
  });

But this crashes the server with

/Volumes/Datos/Usuarios/pablo/Dropbox/Workspace/Experimentos/minecraft/node/node_modules/minecraft-protocol/lib/protocol.js:598
  this.size = 7 + value.compressedChunkData.length + 12 * value.meta.length;

TypeError: Cannot read property 'compressedChunkData' of undefined

I don't really know how can I achieve this. If any of you could help me with this, it'd be great (BTW, I know GH Issues is not the best place for this, but I've figured it'd be the place where I could get the most help).
Thanks!

Client crash when string too long

assert.js:102
  throw new assert.AssertionError({
        ^
AssertionError: string greater than max length
    at new StringWriter (/home/roblabla/Dropbox/dev/src/js/node-minecraft-protocol/lib/protocol.js:1039:10)
    at /home/roblabla/Dropbox/dev/src/js/node-minecraft-protocol/lib/protocol.js:1182:17
    at Array.forEach (native)
    at createPacketBuffer (/home/roblabla/Dropbox/dev/src/js/node-minecraft-protocol/lib/protocol.js:1178:10)
    at Client.write (/home/roblabla/Dropbox/dev/src/js/node-minecraft-protocol/lib/client.js:63:16)
    at Interface.<anonymous> (/home/roblabla/Dropbox/dev/src/js/node-minecraft-protocol/examples/client.js:22:12)
    at Interface.EventEmitter.emit (events.js:96:17)
    at Interface._onLine (readline.js:200:10)
    at Interface._line (readline.js:518:8)
    at Interface._ttyWrite (readline.js:783:20)

That happens when creating a client pointing towards my server, survival.craftingcorners.com when the server is full, because the motd contains all the player names. Notchian minecraft client does NOT crash. The code of my client can be found in the following gist : https://gist.github.com/4649303

Protocol only works on major verions

I notice that the protocol only works on major version of Minecraft. This isnt a major bug or issue, but as a suggestion was to make it where the protocols are stored in different libs and defined in the code with a version so it would look like

var mc = require('minecraft-protocol');
var client = mc.createClient({
host: "localhost", // optional
port: 25565, // optional
username: "[email protected]",
password: "12345678",
version: "1.6.2",
});

Which could help alot.

I may submit a PR to implement this

Creating instances of "Writer" classes for each packet write

Currently in protocol.js, whenever one packet field is written, a class instance is created to write that field. This is very inefficient as creating class instances is slow and memory intensive, and even worse is that we do this multiple times per packet.

The solution will be to create static writing functions, e.g.

function writeByte(buffer, value, offset) {
  buffer.writeInt8(value, offset);
}

and will also require functions for getting the memory that field will take up when allocating the buffer, e.g.

function sizeByte(value) {
  return 1;
}

For more info on the performance difference, see http://jsperf.com/creating-instances-vs-static-functions. This could reduce memory usage and CPU to less than a third of what it is now, which is especially important for servers.

Server: Crash if unrecognized packet ID

The server crashes if it recieves an unrecognized packet ID. This is obviously very very bad. We would want to make the server close the conection to the client instead of crashing.

Unhandled packet (1.6.1)

4g5m1dr
Just updated to the 1.6.1 branches protocol and connected to my 1.6.1 server with a simple command line chat bot. Was disconnected almost instantly because of an unrecognized packet.

I attacked the exception as a picture, hopefully this helps the problem get resolved quicker.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.