diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyClassicMPPassProvider.java b/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyClassicMPPassProvider.java index f29e573..5ff45c5 100644 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyClassicMPPassProvider.java +++ b/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyClassicMPPassProvider.java @@ -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()); diff --git a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java index 0d309f3..06b9e49 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java @@ -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 { 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 { 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)); diff --git a/src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java b/src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java index 8e9aee6..7963136 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java @@ -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."); } diff --git a/src/main/java/net/raphimc/viaproxy/proxy/session/DummyProxyConnection.java b/src/main/java/net/raphimc/viaproxy/proxy/session/DummyProxyConnection.java index affcfc0..91ed3f7 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/session/DummyProxyConnection.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/session/DummyProxyConnection.java @@ -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; diff --git a/src/main/java/net/raphimc/viaproxy/proxy/session/ProxyConnection.java b/src/main/java/net/raphimc/viaproxy/proxy/session/ProxyConnection.java index f4e201a..e14a119 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/session/ProxyConnection.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/session/ProxyConnection.java @@ -68,18 +68,20 @@ public class ProxyConnection extends NetClient { private final Map> 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 handlerSupplier, final Function, ChannelInitializer> 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 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 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("§.", "")); diff --git a/src/main/java/net/raphimc/viaproxy/proxy/session/UserOptions.java b/src/main/java/net/raphimc/viaproxy/proxy/session/UserOptions.java new file mode 100644 index 0000000..388dc3c --- /dev/null +++ b/src/main/java/net/raphimc/viaproxy/proxy/session/UserOptions.java @@ -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 . + */ +package net.raphimc.viaproxy.proxy.session; + +import net.raphimc.viaproxy.saves.impl.accounts.Account; + +public record UserOptions(String classicMpPass, Account account) { +}