From c36ec24ffc5c4f547704173a860b354c0469cdcf Mon Sep 17 00:00:00 2001 From: CanardNocturne Date: Fri, 27 Oct 2023 12:49:37 +0200 Subject: [PATCH 1/4] Auth event called during "hello" state even if the server was on online mode --- .../ServerLoginPacketListenerImplMixin.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java index a5f4f28f9e7..95a944a32b5 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java @@ -185,21 +185,23 @@ public abstract class ServerLoginPacketListenerImplMixin implements ServerLoginP return event.isCancelled(); } - @Inject(method = "handleHello(Lnet/minecraft/network/protocol/login/ServerboundHelloPacket;)V", - at = @At( - value = "FIELD", - target = "Lnet/minecraft/server/network/ServerLoginPacketListenerImpl$State;KEY:Lnet/minecraft/server/network/ServerLoginPacketListenerImpl$State;", - opcode = Opcodes.GETSTATIC), - cancellable = true) - private void impl$fireAuthEventOffline(final CallbackInfo ci) { + @Inject(method = "startClientVerification(Lcom/mojang/authlib/GameProfile;)V", at = @At("HEAD"), cancellable = true) + private void impl$fireAuthEventOffline(final GameProfile gameProfile, final CallbackInfo ci) { // Move this check up here, so that the UUID isn't null when we fire the event // TODO broken /*if (!this.authenticatedProfile.isComplete()) { this.authenticatedProfile = this.shadow$createFakeProfile(this.authenticatedProfile); }*/ - if (this.bridge$fireAuthEvent()) { - ci.cancel(); + if(gameProfile.equals(createOfflineProfile(gameProfile.getName()))) { + if (this.bridge$fireAuthEvent()) { + ci.cancel(); + } } } + + @Shadow protected static GameProfile createOfflineProfile(String $$0) { + throw new UnsupportedOperationException("Shadowed createOfflineProfile"); + } + } From af812ca3638696ff08e9949ca2a10972a875c33e Mon Sep 17 00:00:00 2001 From: CanardNocturne Date: Sun, 29 Oct 2023 11:47:56 +0100 Subject: [PATCH 2/4] fix spotless java check errors --- .../core/server/network/ServerLoginPacketListenerImplMixin.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java index 95a944a32b5..1e2a83be947 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java @@ -34,7 +34,6 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerLoginPacketListenerImpl; import net.minecraft.server.players.PlayerList; -import org.objectweb.asm.Opcodes; import org.spongepowered.api.Sponge; import org.spongepowered.api.event.Cause; import org.spongepowered.api.event.EventContext; From f895a9b6ad463bd4c0c4829abc842b83260da96c Mon Sep 17 00:00:00 2001 From: CanardNocturne Date: Sun, 12 Nov 2023 19:52:41 +0100 Subject: [PATCH 3/4] changing the injection point --- .../ServerLoginPacketListenerImplMixin.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java index 1e2a83be947..3b25417f1f4 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java @@ -184,23 +184,19 @@ public abstract class ServerLoginPacketListenerImplMixin implements ServerLoginP return event.isCancelled(); } - @Inject(method = "startClientVerification(Lcom/mojang/authlib/GameProfile;)V", at = @At("HEAD"), cancellable = true) - private void impl$fireAuthEventOffline(final GameProfile gameProfile, final CallbackInfo ci) { + @Inject(method = "handleHello(Lnet/minecraft/network/protocol/login/ServerboundHelloPacket;)V", at = @At(value = "INVOKE", target = + "startClientVerification(Lcom/mojang/authlib/GameProfile;)V", ordinal = 1), cancellable = true) + private void impl$fireAuthEventOffline(final CallbackInfo ci) { // Move this check up here, so that the UUID isn't null when we fire the event // TODO broken /*if (!this.authenticatedProfile.isComplete()) { this.authenticatedProfile = this.shadow$createFakeProfile(this.authenticatedProfile); }*/ - if(gameProfile.equals(createOfflineProfile(gameProfile.getName()))) { - if (this.bridge$fireAuthEvent()) { - ci.cancel(); - } + if (this.bridge$fireAuthEvent()) { + ci.cancel(); + System.out.println("hello"); } } - @Shadow protected static GameProfile createOfflineProfile(String $$0) { - throw new UnsupportedOperationException("Shadowed createOfflineProfile"); - } - } From 189210f709c329188173c28d09246bbff4af6e98 Mon Sep 17 00:00:00 2001 From: CanardNocturne Date: Sun, 12 Nov 2023 19:59:18 +0100 Subject: [PATCH 4/4] remove the print --- .../core/server/network/ServerLoginPacketListenerImplMixin.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java index 3b25417f1f4..f12f51ed2a5 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java @@ -195,7 +195,6 @@ public abstract class ServerLoginPacketListenerImplMixin implements ServerLoginP if (this.bridge$fireAuthEvent()) { ci.cancel(); - System.out.println("hello"); } }