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

emit noAuth event #1283

Closed
wants to merge 2 commits into from
Closed

emit noAuth event #1283

wants to merge 2 commits into from

Conversation

zardoy
Copy link
Contributor

@zardoy zardoy commented Jan 17, 2024

...so its possible to interrupt the client sending anything e.g.

client.on('noCredentials', () => {
    // possibly show message to user
    client.end()
})

@@ -51,6 +51,7 @@ declare module 'minecraft-protocol' {
on(event: `raw.${string}`, handler: (buffer: Buffer, packetMeta: PacketMeta) => PromiseLike): this
on(event: 'playerChat', handler: (data: { formattedMessage: string, message: string, type: string, sender: string, senderName: string, senderTeam: string, verified?: boolean }) => PromiseLike): this
on(event: 'systemChat', handler: (data: { positionId: number, formattedMessage: string }) => PromiseLike): this
on(event: 'noCredentials', handler: () => PromiseLike): this
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt it also use typed event emitter as mineflayer does?

@@ -24,6 +24,7 @@ module.exports = function (client, options) {
} else {
if (packet.serverId !== '-') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw looking at the code, what's the point of this check? so the response is sent anyway below...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of your PR ? What does this do?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be added to the doc

Copy link
Contributor Author

@zardoy zardoy Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was inspired by the pakkit patch, in my case it was also useful to have in the web app because I was not even getting an answer back from the server, so I was using this event to display an error message to the user

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not generally a good idea to make a change to code without understanding what's actually happening.

The creation of this event implies there is actually some credential issue here, can you look into what's happening here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not generally a good idea to make a change to code without understanding what's actually happening.

Yes, you are right, I just saw the message in the debug console and decided to also put an event there. But doesn't it mean what it says?

The creation of this event implies there is actually some credential issue here, can you look into what's happening here?

WDYM?
Do you mean there is an issue with my application instead?

Copy link
Contributor Author

@zardoy zardoy Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My goal is to end the connection as soon as I understand that the server is running online mode (and display it in UI)

@zardoy
Copy link
Contributor Author

zardoy commented Jan 17, 2024

btw let's add minimal esbuild web example here (I want to pick some other changes as well)

@@ -274,6 +274,10 @@ Emitted after the player enters the PLAY protocol state and can send and recieve

Called when an error occurs within the client. Takes an Error as parameter.

### `noCredentials` event

Emitted when client didn't supply credentials and server is in online mode (authenticating is required).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not sure if appears needs to be added here. Is it possible to encounter a case where noCredentials would be emitted and the connection is successful?

Copy link
Member

@extremeheat extremeheat Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a link to nmp/vanilla code or somewhere to doc how this gets triggered? I don't understand how packet.serverId relates to auth.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how packet.serverId relates to auth.

i don't know why there is packet.serverId check, sorry. That's why I raised the question below. Or did you mean something else? I wish we could improve clarity here. This is what I want to get: https://github.com/PrismarineJS/node-minecraft-protocol/pull/1283/files#r1454466037

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I mean we should not be formally emitting something like "no credentials" without being certain there is some credential issue and what's causing this. Usually this is what unit tests are supposed to catch. I don't think we need tests for this change, but an understanding of from where this issue originates, not just some debug comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I mean we should not be formally emitting something like "no credentials" without being certain there

Ok, I see your point. I have only my personal experience: whenever I try to connect to any online server I get it.
Not sure what to do here for now..

@rom1504
Copy link
Member

rom1504 commented Feb 26, 2024

the comments seem to indicate this PR is not the right fix. Please re-open if you want to find an other path @zardoy

@rom1504 rom1504 closed this Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

3 participants