JSPM

  • Created
  • Published
  • Downloads 105
  • Score
    100M100P100Q78272F
  • License ISC

Small Minecraft protocol implementation

Package Exports

  • mcproto

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mcproto) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Minecraft Protocol

A small implementation of the Minecraft Protocol written in Typescript. It provides a functionality to decode or encode packets and has a Connection class which keeps track of the connection state, compression and encryption.

This implementation doesn't automatically decode all packets, it does decode packets that change the state or type of the connection like set compression or encryption request. For reading packets, a class PacketReader is provided which contains methods for reading common data types.

Packets are written using the PacketWriter class and can be converted to a buffer with the .encode() method. The encoded packet is not prefixed with it's length.

Server List Ping

import { connect } from "net"
import { Connection, PacketWriter } from "../lib"

const HOST = "play.hivemc.com"

const socket = connect({ host: HOST, port: 25565 }, async () => {
    const client = new Connection(socket)

    client.send(new PacketWriter(0x0).writeVarInt(-1)
    .writeString(HOST).writeUInt16(socket.remotePort!)
    .writeVarInt(1))

    client.send(new PacketWriter(0x0))

    const response = await client.nextPacket
    console.log(response.readString())

    socket.end()
})

More examples can be found in the repository's examples folder.