mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2024-12-22 16:38:04 +01:00
Added event to skip Mojang auth
This commit is contained in:
parent
f167a05148
commit
f97405604d
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2023 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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 {
|
||||
|
||||
private final ProxyConnection proxyConnection;
|
||||
|
||||
public PreMojangAuthEvent(final ProxyConnection proxyConnection) {
|
||||
this.proxyConnection = proxyConnection;
|
||||
}
|
||||
|
||||
public ProxyConnection getProxyConnection() {
|
||||
return this.proxyConnection;
|
||||
}
|
||||
|
||||
}
|
@ -32,6 +32,7 @@ import net.raphimc.vialoader.util.VersionEnum;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.plugins.PluginManager;
|
||||
import net.raphimc.viaproxy.plugins.events.ClientLoggedInEvent;
|
||||
import net.raphimc.viaproxy.plugins.events.PreMojangAuthEvent;
|
||||
import net.raphimc.viaproxy.proxy.LoginState;
|
||||
import net.raphimc.viaproxy.proxy.external_interface.AuthLibServices;
|
||||
import net.raphimc.viaproxy.proxy.external_interface.ExternalInterface;
|
||||
@ -121,20 +122,21 @@ 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));
|
||||
|
||||
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);
|
||||
if (!PluginManager.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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
PluginManager.EVENT_MANAGER.call(new ClientLoggedInEvent(proxyConnection));
|
||||
|
Loading…
Reference in New Issue
Block a user