PrismarineJS / PrismarineJS/node-minecraft-protocol

custom_payload packet won't encode properly.

Open
#1,256 8 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

possible bug
Dominant language
JavaScript
Stars
1.4k
Forks
290
Avg merge
4d 8h
Merged PRs (30d)
7

Description

[ ] The FAQ doesn't contain a resolution to my issue

Versions

  • minecraft-protocol: 1.18.2
  • server: vanilla/spigot/paper, every server version.
  • node: v18.17.0
  • minecraft-packets@1.5.0
  • minecraft-protocol@1.44.0

Detailed description of a problem

A clear and concise description of what the problem is.

node-protocol cannot convert json -> byte from generated json
custom_payload packet cannot be encoded back from json.

Current code

const { createDeserializer, createSerializer } = require('minecraft-protocol');

const serializerMap = new Map();
const deserializerMap = new Map();

function getOrCreateSerializer(state, version, isServer) {
  const key = `${state}_${version}_${isServer}`;
  if (!serializerMap.has(key)) {
    serializerMap.set(key, createSerializer({ state, version, isServer }));
  }
  return serializerMap.get(key);
}

function getOrCreateDeserializer(state, version, isServer) {
  const key = `${state}_${version}_${isServer}`;
  if (!deserializerMap.has(key)) {
    deserializerMap.set(key, createDeserializer({ state, version, isServer }));
  }
  return deserializerMap.get(key);
}

function convertObjectToBuffer(state, version, json, isServer) {
  const serializer = getOrCreateSerializer(state, version, isServer);

  const data = serializer.createPacketBuffer(JSON.parse(json));
  const arrByte = Uint8Array.from(data);

  return arrByte;
}

function convertBufferToObject(state, version, buffer, isServer) {
  const buf = Buffer.from(buffer);
  const deserializer = getOrCreateDeserializer(state, version, isServer);
  const data = deserializer.parsePacketBuffer(buf).data;
  const out = JSON.stringify(data);

  return out;
}

const chat = [3,8,116,101,115,116,32,97,115,100]
const positionlook = [18,0,0,0,0,0,0,0,0,64,87,64,0,0,0,0,0,0,0,0,0,0,0,0,0,-61,94,13,127,-65,-78,-14,-85,1]
const payload = [10,15,109,105,110,101,99,114,97,102,116,58,98,114,97,110,100,7,118,97,110,105,108,108,97]

console.log("Testing Chat");
testLibrary(chat);
console.log("Testing PositionLook");
testLibrary(positionlook);
console.log("Testing Payload");
testLibrary(payload);

function testLibrary(array) {
    const decodedData = convertBufferToObject('play', '1.18.2', array, true);
    console.log(decodedData);

    const payloadData = convertObjectToBuffer('play', '1.18.2', decodedData, false);
    console.log(payloadData);

    console.log("Done!");
}

Expected behavior

custom_payload should be converted back to Buffer

Behavior i got

Throws error when encoding custom_payload

Testing Payload
{"name":"custom_payload","params":{"channel":"minecraft:brand","data":{"type":"Buffer","data":[7,118,97,110,105,108,108,97]}}}
node:buffer:404
throw new ERR_INVALID_ARG_VALUE.RangeError('size', size);
^

RangeError [ERR_INVALID_ARG_VALUE]: The argument 'size' is invalid. Received NaN

Additional Context

All other packets including chunk/declare command/positions works, only custom_payload is affected.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the createSerializer and createPacketBuffer entry points and reproduce the custom_payload case using the provided payload array and JSON output for Minecraft 1.18.2. Trace why the decoded Buffer-shaped data produces an invalid size during encoding; done means custom_payload round-trips back to a Buffer without breaking the other packet examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.