bedrock-protocol icon indicating copy to clipboard operation
bedrock-protocol copied to clipboard

1.19.10 Chat is not being read

Open MrWilco opened this issue 2 years ago • 28 comments

I am using the example scripts to listen to chat and chat is not being listened to. This was working fine on 1.19.1 and now is not working on 1.19.10.

const bedrock = require('bedrock-protocol')
const client = bedrock.createClient({   // optional
  realms: {
    realmInvite: "https://realms.gg/I4Pm46UEw6I"
  },         // optional, default 19132
  username: 'Wilco Realm Bot',   // the username you want to join as, optional if online mode
})

client.on('text', (packet) => { // Listen for chat messages and echo them back.
  if (packet.source_name != client.username) {
    client.queue('text', {
      type: 'chat', needs_translation: false, source_name: client.username, xuid: '', platform_chat_id: '',
      message: `${packet.source_name} said: ${packet.message} on ${new Date().toLocaleString()}`
    })
  }
})

MrWilco avatar Jul 23 '22 16:07 MrWilco

Why doesn't it work? Nothing printed out?

Can you add process.env.DEBUG = 'minecraft-protocol' to the top of your script & rerun and provide the output? https://gist.github.com/

Thanks

extremeheat avatar Jul 23 '22 17:07 extremeheat

@extremeheat Having the same issue here. Using 3.15.0 and minecraft-data 3.9.0, 3.9.1.

The callback in client.on('text', (packet) => {}) is not being called, and there is no debug output after the initial connection / handshake.

https://gist.github.com/nagytech/e4fa801f26da861b4eee08b66e6d554b

I can, however, send chat to the server just fine.

    client.queue('text', {
        type: 'chat', needs_translation: false, source_name: client.username, xuid: '', platform_chat_id: '',
        message: `test`
    })

ghost avatar Jul 25 '22 00:07 ghost

Based on the log, the connection is failing and client is not allowed to spawn (you get no chunk data and all).

I tried on a vanilla 1.19.10 server and it works fine -

  minecraft-protocol C <- Q <-  text {
  type: 'chat',
  needs_translation: false,
...

Have you tried a different server ?

extremeheat avatar Jul 25 '22 06:07 extremeheat

Haven’t tried a different server yet. This is a realms server BTW, not sure if that matters or not.

On Mon, 25 Jul 2022 at 16:54, extremeheat @.***> wrote:

Based on the log, the connection is failing and client is not allowed to spawn (you get no chunk data and all).

I tried on a vanilla 1.19.10 server and it works fine -

minecraft-protocol C <- Q <- text { type: 'chat', needs_translation: false, ...

Have you tried a different server ?

— Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/bedrock-protocol/issues/239#issuecomment-1193653526, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACBFOUNLHAGO5GGRZBK3MA3VVY22LANCNFSM54OIGELQ . You are receiving this because you commented.Message ID: @.***>

ghost avatar Jul 25 '22 08:07 ghost

Possibly if OP and you have same issues. Have you tried connecting to the server with a Relay proxy? There should be some doc on how to set this up.

If you are able to connect, please post another log file with the DEBUG flag set at top of your code like before.

extremeheat avatar Jul 25 '22 22:07 extremeheat

image

Relay Code

const { Relay } = require('bedrock-protocol')

process.env.DEBUG = "bedrock-protocol"

function createRelay () {
  console.log('Creating relay')
  /* Example to create a non-transparent proxy (or 'Relay') connection to destination server */
  const relay = new Relay({
    /* host and port for clients to listen to */
    host: '0.0.0.0',
    port: 19130,
    offline: false,
    /* Where to send upstream packets to */
    destination: {
      realms: {
        pickRealm: (realms) => realms[0] // I only have one realm, this is fine.
      },
      offline: false
    }
  })
  relay.conLog = console.debug
  relay.listen()
  relay.on('connect', player => {
    // Server is sending a message to the client.
    player.on('clientbound', ({ name, params }) => {
      console.log(params)
    })
    player.on('serverbound', ({ name, params }) => {
        console.log(params)
    })
  })
}

createRelay()

Relay output

Creating relay
Listening on 0.0.0.0 19130 1.19.10
New connection from 127.0.0.1/43585
Connecting to 20.5.103.67 30421
Connected to upstream server
{
  must_accept: false,
  has_scripts: false,
  force_server_packs: false,
  behaviour_packs: [],
  texture_packs: []
}
{ compression_threshold: 256 }
{ response_status: 'completed', resourcepackids: [] }
{ enabled: false }
{ request_time: 1658788267364n, response_time: 0n }
{
  type: 'chat',
  needs_translation: false,
  source_name: 'xxxx',
  message: 'test',
  parameters: undefined,
  xuid: '',
  platform_chat_id: ''
}
{ chunk_radius: 10 }
{
  type: 'chat',
  needs_translation: false,
  source_name: 'xxxx',
  message: 'test',
  parameters: undefined,
  xuid: '',
  platform_chat_id: ''
}
{
  type: 'chat',
  needs_translation: false,
  source_name: 'xxxx',
  message: 'test',
  parameters: undefined,
  xuid: '',
  platform_chat_id: ''
}

Client Code

process.env.DEBUG = 'minecraft-protocol'

const bedrock = require('bedrock-protocol');

const client = bedrock.createClient({
    
    // realms: {
    //     pickRealm: (r) => r[0]
    // }

    host: "127.0.0.1",
    port: 19130

});

setInterval(() => {    
    client.queue('text', {
        type: 'chat', needs_translation: false, source_name: client.username, xuid: '', platform_chat_id: '',
        message: `test`
    })
}, 5000);
  
client.on('text', (packet) => { // Listen for chat messages

    console.log(`${JSON.stringify(packet)}`)

})

Client output

minecraft-protocol chains [
  'xxxx',
  'xxxx'
] +0ms
  minecraft-protocol got xbox profile {
  nbf: xxxx,
  extraData: {
    XUID: 'xxxx',
    identity: 'xxxx',
    displayName: 'xxxx',
    titleId: 'xxxx'
  },
  randomNonce: xxxx,
  iss: 'Mojang',
  exp: xxxx,
  iat: xxxx,
  identityPublicKey: 'xxxx'
} +1ms
  minecraft-protocol [client] connecting to 127.0.0.1 19130 {
  name: 'xxxx',
  uuid: 'xxxx',
  xuid: 'xxxx'
} RakNativeClient {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  connected: false,
  onConnected: [Function (anonymous)],
  onCloseConnection: [Function (anonymous)],
  onEncapsulated: [Function (anonymous)],
  raknet: Client {
    _events: [Object: null prototype] {
      encapsulated: [Function (anonymous)],
      connect: [Function (anonymous)],
      disconnect: [Function (anonymous)]
    },
    _eventsCount: 3,
    _maxListeners: undefined,
    client: RakClient {},
    ping: [Function (anonymous)],
    connect: [Function (anonymous)],
    close: [Function (anonymous)],
    [Symbol(kCapture)]: false
  },
  [Symbol(kCapture)]: false
} +0ms
  minecraft-protocol * new status 1 +0ms
  minecraft-protocol Auth chain [
  'xxxx',
  'xxxx',
  'xxxx'
] +50ms
  minecraft-protocol C <- login {
  protocol_version: 534,
  tokens: {
    identity: '{"chain":["xxxx"]}',
    client: 'xxxx'
  }
} +1ms
  minecraft-protocol while sending to RakNativeClient {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  connected: true,
  onConnected: [Function (anonymous)],
  onCloseConnection: [Function (anonymous)],
  onEncapsulated: [Function: onEncapsulated],
  raknet: Client {
    _events: [Object: null prototype] {
      encapsulated: [Function (anonymous)],
      connect: [Function (anonymous)],
      disconnect: [Function (anonymous)]
    },
    _eventsCount: 3,
    _maxListeners: undefined,
    client: RakClient {},
    ping: [Function (anonymous)],
    connect: [Function (anonymous)],
    close: [Function (anonymous)],
    [Symbol(kCapture)]: false
  },
  [Symbol(kCapture)]: false
} Error: Failed to send: -5
    at Client.send (/home/redacted/source/client/node_modules/raknet-native/lib/RakNet.js:57:13)
    at RakNativeClient.sendReliable (/home/redacted/source/client/node_modules/bedrock-protocol/src/rak.js:76:24)
    at Client.sendMCPE (/home/redacted/source/client/node_modules/bedrock-protocol/src/connection.js:139:23)
    at Client.sendDecryptedBatch (/home/redacted/source/client/node_modules/bedrock-protocol/src/connection.js:128:10)
    at Client.write (/home/redacted/source/client/node_modules/bedrock-protocol/src/connection.js:70:12)
    at Client.sendLogin (/home/redacted/source/client/node_modules/bedrock-protocol/src/client.js:128:10)
    at RakNativeClient.connection.onConnected (/home/redacted/source/client/node_modules/bedrock-protocol/src/client.js:102:46)
    at Client.<anonymous> (/home/redacted/source/client/node_modules/bedrock-protocol/src/rak.js:42:12)
    at Client.emit (node:events:527:28)
    at /home/redacted/source/client/node_modules/raknet-native/lib/RakNet.js:35:20 +16ms
  minecraft-protocol Client closed! +21ms
  minecraft-protocol * new status 0 +14ms
  minecraft-protocol C <- Q <-  text {
  type: 'chat',
  needs_translation: false,
  source_name: 'xxxx',
  xuid: '',
  platform_chat_id: '',
  message: 'test'
} +4s
  minecraft-protocol C <- Q <-  text {
  type: 'chat',
  needs_translation: false,
  source_name: 'xxxx',
  xuid: '',
  platform_chat_id: '',
  message: 'test'
} +5s

ghost avatar Jul 25 '22 22:07 ghost

You wrote the debug line wrong. It's minecraft-protocol case sensitive and must go all the way at the top of your code which is before any require() statements. This sets an environment variable for the Node.JS environment, as explained in our README.

extremeheat avatar Jul 25 '22 22:07 extremeheat

https://github.com/PrismarineJS/bedrock-protocol/blob/370ca96f2e7e2adcf5c42672acc129b5d7cc68ea/src/client.js#L124 this seems wrong, it shouldn't be wrapped in an object

rob9315 avatar Jul 25 '22 22:07 rob9315

@rob9315

https://github.com/PrismarineJS/bedrock-protocol/blob/370ca96f2e7e2adcf5c42672acc129b5d7cc68ea/src/client.js#L124

this seems wrong, it shouldn't be wrapped in an object

This is an unrelated issue, in JS { chain } without colons equals { chain: chain }

extremeheat avatar Jul 25 '22 22:07 extremeheat

no i know that, the problem is that the packets description (for 1.19.10) says that it's an array: image

rob9315 avatar Jul 25 '22 22:07 rob9315

Removing {} breaks the authentication. On a related note, when connected to a Realm on my mobile and laptop chat isn't sent to either clients not even involving bedrock-protocol

LucienHH avatar Jul 25 '22 22:07 LucienHH

Yeah, client joining is pretty well tested on CI. The issue here seems to be possibly wrong login sequence (missing a packet to send) so Realms is not accepting the client spawn request or something wrt authentication.

extremeheat avatar Jul 25 '22 22:07 extremeheat

My bedrock-protocol client can receive text however only from certain accounts. image

LucienHH avatar Jul 25 '22 22:07 LucienHH

Using /msg will send the chat to the bot irrespective of account used

LucienHH avatar Jul 25 '22 23:07 LucienHH

Let's keep this issue focused on the matter @MrWilco and @nagytech have. If there are orthogonal problems not directly related please open new issues/discussion so things are easier to track.

extremeheat avatar Jul 26 '22 00:07 extremeheat

Are there any suggestions on how I can compare the difference in between the prismarine client and the official client? Wireshark perhaps? Or any tool that you already have as a part of your dev process?

On Tue, 26 Jul 2022 at 10:15, extremeheat @.***> wrote:

Let's keep this issue focused on the matter @MrWilco https://github.com/MrWilco and @nagytech https://github.com/nagytech have. If there are orthogonal problems not directly related please open new issues/discussion so things are easier to track.

— Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/bedrock-protocol/issues/239#issuecomment-1194805064, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACBFOUNS5QYTNAJEQSQD6S3VV4U3TANCNFSM54OIGELQ . You are receiving this because you were mentioned.Message ID: @.***>

ghost avatar Jul 26 '22 00:07 ghost

@nagytech

As stated above , please correct this:

You wrote the debug line wrong. It's minecraft-protocol case sensitive and must go all the way at the top of your code which is before any require() statements. This sets an environment variable for the Node.JS environment, as explained in our README.

And provide a log with a vanilla client connected to the Relay which is connected to the backend server. It will make it easier to understand the login procedure and anything incorrect with how bedrock-protocol's client is initializing the connection.

extremeheat avatar Jul 26 '22 00:07 extremeheat

Vanilla client -> Relay -> Realms? Sorry, I can't do that.

Might be easier for someone who knows this system to simply run the code and find the issue themselves.

Good luck!

ghost avatar Jul 26 '22 03:07 ghost

Hi @nagytech - I've corrected the code that would be great if you could run. I don't have a Realms subscription myself, so just trying to help out those that do :)

process.env.DEBUG = "minecraft-protocol"
const { Relay } = require('bedrock-protocol')


function createRelay () {
  console.log('Creating relay')
  /* Example to create a non-transparent proxy (or 'Relay') connection to destination server */
  const relay = new Relay({
    /* host and port for clients to listen to */
    host: '0.0.0.0',
    port: 19130,
    logging: true,
    offline: false,
    /* Where to send upstream packets to */
    destination: {
      realms: {
        pickRealm: (realms) => realms[0] // I only have one realm, this is fine.
      },
      offline: false
    }
  })
  relay.conLog = console.debug
  relay.listen()
  relay.on('connect', player => {
    // Server is sending a message to the client.
    player.on('clientbound', ({ name, params }) => {
      console.log(params)
    })
    player.on('serverbound', ({ name, params }) => {
        console.log(params)
    })
  })
}

createRelay()

Or if anyone is having similar problems, please run code above which makes a proxy server to connect to a Realm. You can connect to it and it should log many things to the console, drop that over to https://gist.github.com/ and post a link.

extremeheat avatar Jul 26 '22 06:07 extremeheat

@extremeheat What I was debugging is related to this issue, I don't believe the errors encountered here are to do with bedrock-protocol but more so to do with an issue with Realms itself. See REALMS-9150, REALMS-9191 & REALMS-10537

LucienHH avatar Jul 26 '22 07:07 LucienHH

Unfortunately I forgot to unsub to this issue, so I read a few comments that I'm obligated to respond to.

@LucienHH I can join the exact same realm with the same two accounts on proper clients with no issues. The moment one of the clients is one of yours things start failing. There is clearly an issue with something in prismarine - I don't think it's worthwhile to shift the blame.

@extremeheat I've uninstalled Node and have no intention of using Prismarine in the future so I'm not able to help contribute any further. The first post on the issue includes everything you need to repro the fault including a realm invite.

(Also, if you're encouraging people to dump the DEBUG output of your application, you should be providing extra configuration to obfuscate tokens. Otherwise, you're just luring people into compromising their accounts).

ghost avatar Jul 26 '22 08:07 ghost

I think listening to chat stopped working again in 1.19.11 realms. It no longer logs packets. Nothing is being printed to console and I have process.env.DEBUG = 'minecraft-protocol' at the top of the script

MrWilco avatar Jul 26 '22 23:07 MrWilco

  • The client won't get chat messages if it has not spawned. The spawn event will be triggered as mentioned in our documentation.
  • If this issue has happened because your client has not spawned, then you should provide a proxy log as mentioned prior.

extremeheat avatar Jul 27 '22 01:07 extremeheat

The client is spawning in properly as the spawn event is being emitted. It console logs a string when spawn is emitted

MrWilco avatar Jul 27 '22 01:07 MrWilco

OK, if the client spawns then it should be able to correctly receive chat messages. Can you reproduce this on other servers? If not, this certainly seems to be an issue on server side (see Lucien's links to bug reports on the topic).

extremeheat avatar Jul 27 '22 01:07 extremeheat

I think listening to chat stopped working again in 1.19.11 realms. It no longer logs packets. Nothing is being printed to console and I have process.env.DEBUG = 'minecraft-protocol' at the top of the script

I also have some packages that are not displayed after the update

frizib avatar Jul 27 '22 07:07 frizib

Quick, get someone who knows nothing about how to fix the issue to debug everything.

ghost avatar Jul 27 '22 07:07 ghost

OK, if the client spawns then it should be able to correctly receive chat messages. Can you reproduce this on other servers? If not, this certainly seems to be an issue on server side (see Lucien's links to bug reports on the topic).

It is working on my BDS which is running 1.19.10. my realm running 1.19.11 is not logging chat packets at all.

MrWilco avatar Jul 28 '22 00:07 MrWilco

No updates to this, closing. Seems this is a Realms issue as it cannot be reproduced outside of Realms and happens to non-bedrock-protocol clients also - https://bugs.mojang.com/browse/REALMS-9150. Please re-open if this you think is a confirmed issue with bedrock-protocol specifically.

extremeheat avatar Aug 25 '22 16:08 extremeheat