Actually fixed event to skip Mojang auth

This commit is contained in:
RaphiMC 2023-11-02 20:34:27 +01:00
parent 2a662bd93b
commit e2c712239c
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94
2 changed files with 16 additions and 18 deletions

View File

@ -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;
}

View File

@ -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,7 +122,6 @@ 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);
@ -137,7 +136,6 @@ public class LoginPacketHandler extends PacketHandler {
} catch (Throwable e) {
throw new RuntimeException("Failed to make session request for user '" + userName + "'!", e);
}
}
ViaProxy.EVENT_MANAGER.call(new ClientLoggedInEvent(proxyConnection));
ExternalInterface.fillPlayerData(this.proxyConnection);