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

Joining world and then timeout 1.21.1 #1361

Open
daoq opened this issue Dec 28, 2024 · 1 comment
Open

Joining world and then timeout 1.21.1 #1361

daoq opened this issue Dec 28, 2024 · 1 comment

Comments

@daoq
Copy link

daoq commented Dec 28, 2024

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

Versions

  • minecraft-protocol: 1.51.0
  • server: vanilla
  • node: 21.0.0

Detailed description of a problem

once i run the code and connect to the localhost, it is stuck at Joining world until it times out, however the client does connect to the server and receives packets but the minecraft window is stuck at "Joining World..."
once i connect:
Incoming connection (::ffff:127.0.0.1)
after few seconds:
Connection closed by client (::ffff:127.0.0.1)
Connection closed by server (::ffff:127.0.0.1)
i dont get any error, i have tried multiple servers
Could it be my game error or the code? i am not sure
also when using 1.8.9 it seems to work normally on any server

Current code

const mc = require('minecraft-protocol')
const states = mc.states
const srv = mc.createServer({
  'online-mode': false,
  port: 25565,
  keepAlive: false,
  version: '1.21.1'
})

srv.on('login', function (client) {
  const addr = client.socket.remoteAddress
  console.log('Incoming connection', '(' + addr + ')')
  let endedClient = false
  let endedTargetClient = false

  client.on('end', function () {
    endedClient = true
    console.log('Connection closed by client', '(' + addr + ')')
    if (!endedTargetClient) { targetClient.end('End') }
  })


  client.on('error', function (err) {
    endedClient = true
    console.log('Connection error by client', '(' + addr + ')')
    console.log(err.stack)
    if (!endedTargetClient) { targetClient.end('Error') }
  })

  const targetClient = mc.createClient({
    host: 'nmpTEST.aternos.me',
    port: 25565,
    username: 'abcadf324',
    keepAlive: false,
    version: '1.21.1'
  })

  client.on('packet', function (data, meta) {
    if (targetClient.state === states.PLAY && meta.state === states.PLAY) {
      if (!endedTargetClient) { targetClient.write(meta.name, data) }
    }
  })

  targetClient.on('packet', function (data, meta) {
    if (meta.state === states.PLAY && client.state === states.PLAY) {
      if (!endedClient) {
        client.write(meta.name, data)
        if (meta.name === 'set_compression') {
          client.compressionThreshold = data.threshold
        }
      }
    }
  })

  targetClient.on('end', function () {
    endedTargetClient = true
    console.log('Connection closed by server', '(' + addr + ')')
    if (!endedClient) { client.end('End') }
  })

  targetClient.on('error', function (err) {
    endedTargetClient = true
    console.log('Connection error by server', '(' + addr + ') ', err)
    console.log(err.stack)
    if (!endedClient) { client.end('Error') }
  })
})
@daoq
Copy link
Author

daoq commented Dec 28, 2024

it seems client.state is always at "configuration" where targetClient.state is "play", when removing && client.state === states.PLAY it is still stuck at "Joining World"

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

No branches or pull requests

1 participant