diff --git a/src/main/java/net/raphimc/viaproxy/plugins/events/PreMojangAuthEvent.java b/src/main/java/net/raphimc/viaproxy/plugins/events/ShouldVerifyOnlineModeEvent.java similarity index 88% rename from src/main/java/net/raphimc/viaproxy/plugins/events/PreMojangAuthEvent.java rename to src/main/java/net/raphimc/viaproxy/plugins/events/ShouldVerifyOnlineModeEvent.java index e8fd357..0b97125 100644 --- a/src/main/java/net/raphimc/viaproxy/plugins/events/PreMojangAuthEvent.java +++ b/src/main/java/net/raphimc/viaproxy/plugins/events/ShouldVerifyOnlineModeEvent.java @@ -20,11 +20,11 @@ package net.raphimc.viaproxy.plugins.events; import net.raphimc.viaproxy.plugins.events.types.EventCancellable; import net.raphimc.viaproxy.proxy.session.ProxyConnection; -public class PreMojangAuthEvent extends EventCancellable { +public class ShouldVerifyOnlineModeEvent extends EventCancellable { private final ProxyConnection proxyConnection; - public PreMojangAuthEvent(final ProxyConnection proxyConnection) { + public ShouldVerifyOnlineModeEvent(final ProxyConnection proxyConnection) { this.proxyConnection = proxyConnection; } diff --git a/src/main/java/net/raphimc/viaproxy/proxy/packethandler/LoginPacketHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/packethandler/LoginPacketHandler.java index a63d908..9e658a8 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/packethandler/LoginPacketHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/packethandler/LoginPacketHandler.java @@ -32,7 +32,7 @@ import net.raphimc.vialoader.util.VersionEnum; import net.raphimc.viaproxy.ViaProxy; import net.raphimc.viaproxy.cli.options.Options; import net.raphimc.viaproxy.plugins.events.ClientLoggedInEvent; -import net.raphimc.viaproxy.plugins.events.PreMojangAuthEvent; +import net.raphimc.viaproxy.plugins.events.ShouldVerifyOnlineModeEvent; import net.raphimc.viaproxy.proxy.LoginState; import net.raphimc.viaproxy.proxy.external_interface.AuthLibServices; import net.raphimc.viaproxy.proxy.external_interface.ExternalInterface; @@ -92,7 +92,7 @@ public class LoginPacketHandler extends PacketHandler { proxyConnection.setGameProfile(new GameProfile(null, loginHelloPacket.name)); } - if (Options.ONLINE_MODE) { + if (Options.ONLINE_MODE && !ViaProxy.EVENT_MANAGER.call(new ShouldVerifyOnlineModeEvent(this.proxyConnection)).isCancelled()) { this.proxyConnection.getC2P().writeAndFlush(new S2CLoginKeyPacket1_8("", KEY_PAIR.getPublic().getEncoded(), this.verifyToken)).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); } else { ViaProxy.EVENT_MANAGER.call(new ClientLoggedInEvent(proxyConnection)); @@ -122,21 +122,19 @@ public class LoginPacketHandler extends PacketHandler { final SecretKey secretKey = CryptUtil.decryptSecretKey(KEY_PAIR.getPrivate(), loginKeyPacket.encryptedSecretKey); this.proxyConnection.getC2P().attr(MCPipeline.ENCRYPTION_ATTRIBUTE_KEY).set(new AESEncryption(secretKey)); - if (!ViaProxy.EVENT_MANAGER.call(new PreMojangAuthEvent(this.proxyConnection)).isCancelled()) { - final String userName = this.proxyConnection.getGameProfile().getName(); - try { - final String serverHash = new BigInteger(CryptUtil.computeServerIdHash("", KEY_PAIR.getPublic(), secretKey)).toString(16); - final GameProfile mojangProfile = AuthLibServices.SESSION_SERVICE.hasJoinedServer(this.proxyConnection.getGameProfile(), serverHash, null); - if (mojangProfile == null) { - Logger.u_err("auth", this.proxyConnection.getC2P().remoteAddress(), this.proxyConnection.getGameProfile(), "Invalid session"); - this.proxyConnection.kickClient("§cInvalid session! Please restart minecraft (and the launcher) and try again."); - } else { - this.proxyConnection.setGameProfile(mojangProfile); - } - Logger.u_info("auth", this.proxyConnection.getC2P().remoteAddress(), this.proxyConnection.getGameProfile(), "Authenticated as " + this.proxyConnection.getGameProfile().getId().toString()); - } catch (Throwable e) { - throw new RuntimeException("Failed to make session request for user '" + userName + "'!", e); + final String userName = this.proxyConnection.getGameProfile().getName(); + try { + final String serverHash = new BigInteger(CryptUtil.computeServerIdHash("", KEY_PAIR.getPublic(), secretKey)).toString(16); + final GameProfile mojangProfile = AuthLibServices.SESSION_SERVICE.hasJoinedServer(this.proxyConnection.getGameProfile(), serverHash, null); + if (mojangProfile == null) { + Logger.u_err("auth", this.proxyConnection.getC2P().remoteAddress(), this.proxyConnection.getGameProfile(), "Invalid session"); + this.proxyConnection.kickClient("§cInvalid session! Please restart minecraft (and the launcher) and try again."); + } else { + this.proxyConnection.setGameProfile(mojangProfile); } + Logger.u_info("auth", this.proxyConnection.getC2P().remoteAddress(), this.proxyConnection.getGameProfile(), "Authenticated as " + this.proxyConnection.getGameProfile().getId().toString()); + } catch (Throwable e) { + throw new RuntimeException("Failed to make session request for user '" + userName + "'!", e); } ViaProxy.EVENT_MANAGER.call(new ClientLoggedInEvent(proxyConnection));