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

Auth event called twice #3911

Merged

Conversation

AlexandreArcil
Copy link
Contributor

@AlexandreArcil AlexandreArcil commented Oct 29, 2023

Version

Minecraft: 1.20.2
SpongeAPI: 11.0.0-SNAPSHOT
Sponge: 1.20.2-11.0.0-SNAPSHOT
SpongeVanilla: 1.20.2-11.0.0-RC0

The bug

During the login of a player, the event ServerSideConnectionEvent.Auth was called twice.
Reported by #3907.

Description

When a player logs in, the event ServerSideConnectionEvent.Auth is called for the first time by ServerLoginPacketListenerImplMixin and then by ServerLoginPacketListenerImpl_1Mixin if the server is on online mode, but and not called if it is on offline mode.
The reason for this is due to how the mixin ServerLoginPacketListenerImpl#impl$fireAuthEventOffline was injected: at the assignment of the field state with the value KEY. In API-10 (1.19.4), this was done in singleplayer or if the server is in offline mode, but on API-11 (1.20.2), this is done if the server is on online mode. Later in the login process, the mixin ServerLoginPacketListenerImpl_1Mixin will trigger the event if the player was authenticated on an online server.

The fix

As the name suggests, fireAuthEventOffline should only call the event when the server is in offline mode.
The fix changes the injection point to the method startClientVerification because it's called when the server is in offline mode. It then checks whether if the game profile given as argument is an "offline profile". This is done by comparing it with the result of a call to the method createOfflineProfile because the profile argument comes from that method (ie: this.startClientVerification(createOfflineProfile(this.requestedUsername))).

startClientVerification is also called in other cases: when it is on a singleplayer, but we were in the context of a server, and when the player is authenticated to the server, but the check skips the event trigger.

@aromaa aromaa added type: bug Something isn't working system: event version: 1.20 API: 11 labels Nov 2, 2023
@AlexandreArcil
Copy link
Contributor Author

Ok I changed the injection point to what you wanted !

@ImMorpheus
Copy link
Contributor

Thanks! Can you rebase on api-11 ?

@AlexandreArcil
Copy link
Contributor Author

Done!

@ImMorpheus
Copy link
Contributor

I don't think that's it, the PR has ~30 commits.

Please see https://docs.spongepowered.org/stable/en/contributing/howtogit.html

@AlexandreArcil AlexandreArcil force-pushed the fix/auth-event-called-twice branch from 3f0b2ef to bb49179 Compare November 14, 2023 18:14
@AlexandreArcil AlexandreArcil force-pushed the fix/auth-event-called-twice branch from bb49179 to 189210f Compare November 14, 2023 18:17
@AlexandreArcil
Copy link
Contributor Author

Ok I did some force push and now everything is correct, no ?

@ImMorpheus ImMorpheus merged commit 0a25a00 into SpongePowered:api-11 Nov 14, 2023
4 of 5 checks passed
@ImMorpheus
Copy link
Contributor

Yep, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
system: event type: bug Something isn't working version: 1.20 API: 11
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants