Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SERVER] Packet Login ? Network Protocol Error #1370

Open
1 task done
notegorkaa opened this issue Jan 26, 2025 · 6 comments
Open
1 task done

[SERVER] Packet Login ? Network Protocol Error #1370

notegorkaa opened this issue Jan 26, 2025 · 6 comments
Labels

Comments

@notegorkaa
Copy link

  • The FAQ doesn't contain a resolution to my issue

Versions

  • minecraft-protocol: 1.51.0
  • server: nmp server 1.21.4
  • node: 22.12.0

Detailed description of a problem

When trying to connect to the server, I get “Network Protocol Error”, although the Packet Login itself is filled in correctly. see minecraft logs:

Current code

const mc = require('minecraft-protocol')
const nbt = require('prismarine-nbt')

const options = {
  motd: 'Vox Industries',
  'max-players': 127,
  port: 25565,
  'online-mode': false, // https://github.com/PrismarineJS/node-minecraft-protocol/issues/1369
  version: "1.21.4"
}

const server = mc.createServer(options)
const mcData = require('minecraft-data')(server.version)
const loginPacket = mcData.loginPacket
function chatText (text) {
  return mcData.supportFeature('chatPacketsUseNbtComponents')
    ? nbt.comp({ text: nbt.string(text) })
    : JSON.stringify({ text })
}

server.on('playerJoin', function (client) {
  broadcast(client.username + ' joined the game.')
  const addr = client.socket.remoteAddress + ':' + client.socket.remotePort
  console.log(client.username + ' connected', '(' + addr + ')')

  client.on('end', function () {
    broadcast(client.username + ' left the game.', client)
    console.log(client.username + ' disconnected', '(' + addr + ')')
  })

  // send init data so client will start rendering world
  client.write('login', {
	...loginPacket,
	entityId: bot.entity,
	isHardcore: false,
	worldNames: ["minecraft:overworld", "minecraft:the_nether", "minecraft:the_end"],
	maxPlayers: 1,
	viewDistance: 10,
	simulationDistance: 10,
	reducedDebugInfo: false,
	enableRespawnScreen: true,
	doLimitedCrafting: false,
	dimension: 0,
	difficulty: difficulty[bot.game.difficulty],
	worldName: "minecraft:overworld",
	hashedSeed: [0, 0],
	gameMode: 0,
	previousGameMode: 0,
	levelType: 'default',
	spawnPosition: bot.spawnPoint ?? bot.entity.position,
	isDebug: false,
	isFlat: false,
	portalCooldown: 0,
	seaLevel: -63,
	enforcesSecureChat: false,
	dimensionCodec: loginPacket?.dimensionCodec,
  })
  client.write('position', {
	teleportId: 0,   // its changed in 1.21.4 (769) protocol
    x: 0,
    y: 10000,
    z: 0,
	dx: 0,
	dy: 5000,
	dz: 0,
    yaw: 0,
    pitch: 0,
    flags: 0x00
  })

  function handleChat (data) {
    const message = '<' + client.username + '>' + ' ' + data.message
    broadcast(message, null, client.username)
    console.log(message)
  }
  client.on('chat', handleChat) // pre-1.19
  client.on('chat_message', handleChat) // post 1.19
})

server.on('error', function (error) {
  console.log('Error:', error)
})

server.on('listening', function () {
  console.log('Server listening on port', server.socketServer.address().port)
})

function sendBroadcastMessage (server, clients, message, sender) {
  if (mcData.supportFeature('signedChat')) {
    server.writeToClients(clients, 'player_chat', {
      plainMessage: message,
      signedChatContent: '',
      unsignedChatContent: chatText(message),
      type: 0,
      senderUuid: 'd3527a0b-bc03-45d5-a878-2aafdd8c8a43', // random
      senderName: JSON.stringify({ text: sender }),
      senderTeam: undefined,
      timestamp: Date.now(),
      salt: 0n,
      signature: mcData.supportFeature('useChatSessions') ? undefined : Buffer.alloc(0),
      previousMessages: [],
      filterType: 0,
      networkName: JSON.stringify({ text: sender })
    })
  } else {
    server.writeToClients(clients, 'chat', { message: JSON.stringify({ text: message }), position: 0, sender: sender || '0' })
  }
}

function broadcast (message, exclude, username) {
  sendBroadcastMessage(server, Object.values(server.clients).filter(client => client !== exclude), message)
}

Expected behavior

expected the player was log on to the server without error.

Additional context

@extremeheat
Copy link
Member

Please use flying-squid if you need to make a server. Only use nmp if you understand the underlying server protocol very well.

http://github.com/prismarinejs/flying-squid

@notegorkaa
Copy link
Author

Please use flying-squid if you need to make a server. Only use nmp if you understand the underlying server protocol very well.

http://github.com/prismarinejs/flying-squid

you misunderstand me, they're completely different mistakes. I used both flying-squid and nmp server, same errors. Specifically here the problem is with online-mode and that the server handles it wrong.

@extremeheat
Copy link
Member

Then you need to open an issue under flying-squid. This repo is about node-minecraft-protocol.

@notegorkaa
Copy link
Author

Please use flying-squid if you need to make a server. Only use nmp if you understand the underlying server protocol very well.

http://github.com/prismarinejs/flying-squid

same error also on flying-squid, i tested

@notegorkaa
Copy link
Author

notegorkaa commented Jan 26, 2025

Then you need to open an issue under flying-squid. This repo is about node-minecraft-protocol.

the root of the problem is nmp, because flying-squid is based on it.

@rom1504
Copy link
Member

rom1504 commented Jan 26, 2025

upload login file in https://github.com/PrismarineJS/minecraft-data/tree/master/data/pc/1.21.4 and it'll work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants