mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2024-12-22 16:38:04 +01:00
Made account part of ProxyConnection
This commit is contained in:
parent
6d1834fc58
commit
b27d387418
@ -36,11 +36,9 @@ public class ViaProxyClassicMPPassProvider extends ClassicMPPassProvider {
|
||||
|
||||
@Override
|
||||
public String getMpPass(UserConnection user) {
|
||||
final String mppass = ProxyConnection.fromUserConnection(user).getClassicMpPass();
|
||||
final String mppass = ProxyConnection.fromUserConnection(user).getUserOptions().classicMpPass();
|
||||
if (mppass != null && !mppass.isEmpty() && !mppass.equals("0")) {
|
||||
return mppass;
|
||||
} else if (Options.CLASSIC_MP_PASS != null) {
|
||||
return Options.CLASSIC_MP_PASS;
|
||||
} else if (Options.BETACRAFT_AUTH) {
|
||||
final HandshakeStorage handshakeStorage = user.get(HandshakeStorage.class);
|
||||
return getBetacraftMpPass(user, user.getProtocolInfo().getUsername(), handshakeStorage.getHostname(), handshakeStorage.getPort());
|
||||
|
@ -42,6 +42,7 @@ import net.raphimc.viaproxy.proxy.proxy2server.Proxy2ServerHandler;
|
||||
import net.raphimc.viaproxy.proxy.session.BedrockProxyConnection;
|
||||
import net.raphimc.viaproxy.proxy.session.DummyProxyConnection;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
import net.raphimc.viaproxy.proxy.session.UserOptions;
|
||||
import net.raphimc.viaproxy.proxy.util.CloseAndReturn;
|
||||
import net.raphimc.viaproxy.proxy.util.ExceptionUtil;
|
||||
import net.raphimc.viaproxy.proxy.util.HAProxyUtil;
|
||||
@ -137,7 +138,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
|
||||
String connectIP = Options.CONNECT_ADDRESS;
|
||||
int connectPort = Options.CONNECT_PORT;
|
||||
VersionEnum serverVersion = Options.PROTOCOL_VERSION;
|
||||
String classicMpPass = null;
|
||||
String classicMpPass = Options.CLASSIC_MP_PASS;
|
||||
|
||||
if (Options.INTERNAL_SRV_MODE) {
|
||||
final ArrayHelper arrayHelper = ArrayHelper.instanceOf(handshakeParts[0].split("\7"));
|
||||
@ -211,7 +212,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
|
||||
this.proxyConnection.getC2P().attr(ProxyConnection.PROXY_CONNECTION_ATTRIBUTE_KEY).set(this.proxyConnection);
|
||||
this.proxyConnection.setClientVersion(clientVersion);
|
||||
this.proxyConnection.setC2pConnectionState(packet.intendedState);
|
||||
this.proxyConnection.setClassicMpPass(classicMpPass);
|
||||
this.proxyConnection.setUserOptions(new UserOptions(classicMpPass, Options.MC_ACCOUNT));
|
||||
this.proxyConnection.getPacketHandlers().add(new StatusPacketHandler(this.proxyConnection));
|
||||
this.proxyConnection.getPacketHandlers().add(new CustomPayloadPacketHandler(this.proxyConnection));
|
||||
this.proxyConnection.getPacketHandlers().add(new CompressionPacketHandler(this.proxyConnection));
|
||||
|
@ -38,6 +38,7 @@ import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1
|
||||
import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1_19_1;
|
||||
import net.raphimc.viaproxy.protocolhack.viaproxy.signature.storage.ChatSession1_19_3;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.Account;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.BedrockAccount;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.MicrosoftAccount;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
@ -57,15 +58,14 @@ public class ExternalInterface {
|
||||
public static void fillPlayerData(final ProxyConnection proxyConnection) {
|
||||
Logger.u_info("auth", proxyConnection.getC2P().remoteAddress(), proxyConnection.getGameProfile(), "Filling player data");
|
||||
try {
|
||||
if (Options.MC_ACCOUNT != null) {
|
||||
ViaProxy.saveManager.accountsSave.ensureRefreshed(Options.MC_ACCOUNT);
|
||||
if (proxyConnection.getUserOptions().account() != null) {
|
||||
final Account account = proxyConnection.getUserOptions().account();
|
||||
ViaProxy.saveManager.accountsSave.ensureRefreshed(account);
|
||||
|
||||
proxyConnection.setGameProfile(Options.MC_ACCOUNT.getGameProfile());
|
||||
proxyConnection.setGameProfile(account.getGameProfile());
|
||||
final UserConnection user = proxyConnection.getUserConnection();
|
||||
|
||||
if (Options.CHAT_SIGNING && proxyConnection.getServerVersion().isNewerThanOrEqualTo(VersionEnum.r1_19) && Options.MC_ACCOUNT instanceof MicrosoftAccount) {
|
||||
final MicrosoftAccount microsoftAccount = (MicrosoftAccount) Options.MC_ACCOUNT;
|
||||
|
||||
if (Options.CHAT_SIGNING && proxyConnection.getServerVersion().isNewerThanOrEqualTo(VersionEnum.r1_19) && account instanceof MicrosoftAccount microsoftAccount) {
|
||||
final StepPlayerCertificates.PlayerCertificates playerCertificates = microsoftAccount.getPlayerCertificates();
|
||||
final Instant expiresAt = Instant.ofEpochMilli(playerCertificates.expireTimeMs());
|
||||
final long expiresAtMillis = playerCertificates.expireTimeMs();
|
||||
@ -84,8 +84,7 @@ public class ExternalInterface {
|
||||
user.put(new ChatSession1_19_0(user, uuid, privateKey, new ProfileKey(expiresAtMillis, publicKeyBytes, playerCertificates.legacyPublicKeySignature())));
|
||||
user.put(new ChatSession1_19_1(user, uuid, privateKey, new ProfileKey(expiresAtMillis, publicKeyBytes, keySignature)));
|
||||
user.put(new ChatSession1_19_3(user, uuid, privateKey, new ProfileKey(expiresAtMillis, publicKeyBytes, keySignature)));
|
||||
} else if (proxyConnection.getServerVersion().equals(VersionEnum.bedrockLatest) && Options.MC_ACCOUNT instanceof BedrockAccount) {
|
||||
final BedrockAccount bedrockAccount = (BedrockAccount) Options.MC_ACCOUNT;
|
||||
} else if (proxyConnection.getServerVersion().equals(VersionEnum.bedrockLatest) && account instanceof BedrockAccount bedrockAccount) {
|
||||
final StepMCChain.MCChain mcChain = bedrockAccount.getMcChain();
|
||||
|
||||
final UUID deviceId = mcChain.prevResult().initialXblSession().prevResult2().id();
|
||||
@ -116,10 +115,9 @@ public class ExternalInterface {
|
||||
} catch (TimeoutException e) {
|
||||
proxyConnection.kickClient("§cAuthentication cancelled! You need to install OpenAuthMod in order to join this server.");
|
||||
}
|
||||
} else if (Options.MC_ACCOUNT instanceof MicrosoftAccount) {
|
||||
final MicrosoftAccount microsoftAccount = (MicrosoftAccount) Options.MC_ACCOUNT;
|
||||
} else if (proxyConnection.getUserOptions().account() instanceof MicrosoftAccount microsoftAccount) {
|
||||
try {
|
||||
AuthLibServices.SESSION_SERVICE.joinServer(Options.MC_ACCOUNT.getGameProfile(), microsoftAccount.getMcProfile().prevResult().prevResult().access_token(), serverIdHash);
|
||||
AuthLibServices.SESSION_SERVICE.joinServer(microsoftAccount.getGameProfile(), microsoftAccount.getMcProfile().prevResult().prevResult().access_token(), serverIdHash);
|
||||
} catch (Throwable e) {
|
||||
proxyConnection.kickClient("§cFailed to authenticate with Mojang servers! Please try again in a couple of seconds.");
|
||||
}
|
||||
|
@ -56,6 +56,26 @@ public class DummyProxyConnection extends ProxyConnection {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getGameProfile() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGameProfile(GameProfile gameProfile) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public C2SLoginHelloPacket1_7 getLoginHelloPacket() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoginHelloPacket(C2SLoginHelloPacket1_7 loginHelloPacket) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKeyForPreNettyEncryption(Key key) {
|
||||
throw new UnsupportedOperationException();
|
||||
@ -67,22 +87,7 @@ public class DummyProxyConnection extends ProxyConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGameProfile(GameProfile gameProfile) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getGameProfile() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoginHelloPacket(C2SLoginHelloPacket1_7 loginHelloPacket) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public C2SLoginHelloPacket1_7 getLoginHelloPacket() {
|
||||
public UserConnection getUserConnection() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -92,7 +97,12 @@ public class DummyProxyConnection extends ProxyConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserConnection getUserConnection() {
|
||||
public UserOptions getUserOptions() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserOptions(UserOptions userOptions) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -116,16 +126,6 @@ public class DummyProxyConnection extends ProxyConnection {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClassicMpPass(String classicMpPass) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassicMpPass() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return false;
|
||||
|
@ -68,18 +68,20 @@ public class ProxyConnection extends NetClient {
|
||||
private final Map<Integer, CompletableFuture<ByteBuf>> customPayloadListener = new ConcurrentHashMap<>();
|
||||
|
||||
private ServerAddress serverAddress;
|
||||
private VersionEnum serverVersion;
|
||||
|
||||
private VersionEnum serverVersion;
|
||||
private VersionEnum clientVersion;
|
||||
|
||||
private GameProfile gameProfile;
|
||||
private C2SLoginHelloPacket1_7 loginHelloPacket;
|
||||
private Key storedSecretKey;
|
||||
|
||||
private UserConnection userConnection;
|
||||
private UserOptions userOptions;
|
||||
|
||||
private ConnectionState c2pConnectionState = ConnectionState.HANDSHAKING;
|
||||
private ConnectionState p2sConnectionState = ConnectionState.HANDSHAKING;
|
||||
|
||||
private Key storedSecretKey;
|
||||
private String classicMpPass;
|
||||
|
||||
public ProxyConnection(final Supplier<ChannelHandler> handlerSupplier, final Function<Supplier<ChannelHandler>, ChannelInitializer<Channel>> channelInitializerSupplier, final Channel c2p) {
|
||||
super(handlerSupplier, channelInitializerSupplier);
|
||||
this.c2p = c2p;
|
||||
@ -128,6 +130,30 @@ public class ProxyConnection extends NetClient {
|
||||
return this.serverVersion;
|
||||
}
|
||||
|
||||
public VersionEnum getClientVersion() {
|
||||
return this.clientVersion;
|
||||
}
|
||||
|
||||
public void setClientVersion(final VersionEnum clientVersion) {
|
||||
this.clientVersion = clientVersion;
|
||||
}
|
||||
|
||||
public GameProfile getGameProfile() {
|
||||
return this.gameProfile;
|
||||
}
|
||||
|
||||
public void setGameProfile(final GameProfile gameProfile) {
|
||||
this.gameProfile = gameProfile;
|
||||
}
|
||||
|
||||
public C2SLoginHelloPacket1_7 getLoginHelloPacket() {
|
||||
return this.loginHelloPacket;
|
||||
}
|
||||
|
||||
public void setLoginHelloPacket(final C2SLoginHelloPacket1_7 loginHelloPacket) {
|
||||
this.loginHelloPacket = loginHelloPacket;
|
||||
}
|
||||
|
||||
public void setKeyForPreNettyEncryption(final Key key) {
|
||||
this.storedSecretKey = key;
|
||||
}
|
||||
@ -136,36 +162,28 @@ public class ProxyConnection extends NetClient {
|
||||
this.getChannel().attr(MCPipeline.ENCRYPTION_ATTRIBUTE_KEY).set(new AESEncryption(this.storedSecretKey));
|
||||
}
|
||||
|
||||
public void setClientVersion(final VersionEnum clientVersion) {
|
||||
this.clientVersion = clientVersion;
|
||||
}
|
||||
|
||||
public VersionEnum getClientVersion() {
|
||||
return this.clientVersion;
|
||||
}
|
||||
|
||||
public void setGameProfile(final GameProfile gameProfile) {
|
||||
this.gameProfile = gameProfile;
|
||||
}
|
||||
|
||||
public GameProfile getGameProfile() {
|
||||
return this.gameProfile;
|
||||
}
|
||||
|
||||
public void setLoginHelloPacket(final C2SLoginHelloPacket1_7 loginHelloPacket) {
|
||||
this.loginHelloPacket = loginHelloPacket;
|
||||
}
|
||||
|
||||
public C2SLoginHelloPacket1_7 getLoginHelloPacket() {
|
||||
return this.loginHelloPacket;
|
||||
public UserConnection getUserConnection() {
|
||||
return this.userConnection;
|
||||
}
|
||||
|
||||
public void setUserConnection(final UserConnection userConnection) {
|
||||
this.userConnection = userConnection;
|
||||
}
|
||||
|
||||
public UserConnection getUserConnection() {
|
||||
return this.userConnection;
|
||||
public UserOptions getUserOptions() {
|
||||
return this.userOptions;
|
||||
}
|
||||
|
||||
public void setUserOptions(final UserOptions userOptions) {
|
||||
this.userOptions = userOptions;
|
||||
}
|
||||
|
||||
public ConnectionState getC2pConnectionState() {
|
||||
return this.c2pConnectionState;
|
||||
}
|
||||
|
||||
public ConnectionState getP2sConnectionState() {
|
||||
return this.p2sConnectionState;
|
||||
}
|
||||
|
||||
public void setC2pConnectionState(final ConnectionState connectionState) {
|
||||
@ -215,14 +233,6 @@ public class ProxyConnection extends NetClient {
|
||||
}
|
||||
}
|
||||
|
||||
public ConnectionState getC2pConnectionState() {
|
||||
return this.c2pConnectionState;
|
||||
}
|
||||
|
||||
public ConnectionState getP2sConnectionState() {
|
||||
return this.p2sConnectionState;
|
||||
}
|
||||
|
||||
public CompletableFuture<ByteBuf> sendCustomPayload(final String channel, final ByteBuf data) {
|
||||
if (channel.length() > 20) throw new IllegalStateException("Channel name can't be longer than 20 characters");
|
||||
final CompletableFuture<ByteBuf> future = new CompletableFuture<>();
|
||||
@ -264,14 +274,6 @@ public class ProxyConnection extends NetClient {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setClassicMpPass(final String classicMpPass) {
|
||||
this.classicMpPass = classicMpPass;
|
||||
}
|
||||
|
||||
public String getClassicMpPass() {
|
||||
return this.classicMpPass;
|
||||
}
|
||||
|
||||
public void kickClient(final String message) throws CloseAndReturn {
|
||||
Logger.u_err("kick", this.c2p.remoteAddress(), this.getGameProfile(), message.replaceAll("§.", ""));
|
||||
|
||||
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.proxy.session;
|
||||
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.Account;
|
||||
|
||||
public record UserOptions(String classicMpPass, Account account) {
|
||||
}
|
Loading…
Reference in New Issue
Block a user