mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2024-11-22 11:55:24 +01:00
Actually fixed event to skip Mojang auth
This commit is contained in:
parent
2a662bd93b
commit
e2c712239c
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user