Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenni0451 committed Nov 3, 2023
2 parents 4360aba + fd05568 commit 9a41bca
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 132 deletions.
19 changes: 10 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ dependencies {
exclude group: "com.google.guava", module: "guava"
}
include "com.viaversion:viarewind-common:3.0.3-SNAPSHOT"
include "net.raphimc:ViaLegacy:2.2.21-SNAPSHOT"
include("net.raphimc:ViaLegacy:2.2.21-SNAPSHOT") {
exclude group: "net.lenni0451.mcstructs", module: "text"
}
include "net.raphimc:ViaAprilFools:2.0.10-SNAPSHOT"
include("net.raphimc:ViaBedrock:0.0.3-SNAPSHOT") {
exclude group: "io.netty", module: "netty-codec-http"
exclude group: "io.jsonwebtoken", module: "jjwt-impl"
exclude group: "io.jsonwebtoken", module: "jjwt-gson"
exclude group: "io.netty"
exclude group: "io.jsonwebtoken"
exclude group: "net.lenni0451.mcstructs", module: "text"
}
include("net.raphimc:ViaLoader:2.2.11-SNAPSHOT") {
exclude group: "org.slf4j", module: "slf4j-api"
Expand All @@ -88,7 +90,9 @@ dependencies {
include "net.lenni0451.classtransform:additionalclassprovider:1.11.0"
include "net.lenni0451:Reflect:1.3.0"
include "net.lenni0451:LambdaEvents:2.3.2"
include "net.raphimc.netminecraft:all:2.3.7-SNAPSHOT"
include("net.raphimc.netminecraft:all:2.3.7-SNAPSHOT") {
exclude group: "com.google.code.gson", module: "gson"
}
include("net.raphimc:MinecraftAuth:2.1.7-SNAPSHOT") {
exclude group: "com.google.code.gson", module: "gson"
exclude group: "org.slf4j", module: "slf4j-api"
Expand All @@ -98,10 +102,7 @@ dependencies {
exclude group: "net.lenni0451.classtransform", module: "additionalclassprovider"
}
include("org.cloudburstmc.netty:netty-transport-raknet:1.0.0.CR1-SNAPSHOT") {
exclude group: "io.netty", module: "netty-common"
exclude group: "io.netty", module: "netty-buffer"
exclude group: "io.netty", module: "netty-codec"
exclude group: "io.netty", module: "netty-transport"
exclude group: "io.netty"
}
include "gs.mclo:api:3.0.1"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ org.gradle.configureondemand=true

maven_group=net.raphimc
maven_name=ViaProxy
maven_version=3.0.22
maven_version=3.0.23-SNAPSHOT
9 changes: 4 additions & 5 deletions src/main/java/net/raphimc/viaproxy/cli/ConsoleHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
import net.raphimc.viaproxy.util.ArrayHelper;
import net.raphimc.viaproxy.util.logging.Logger;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class ConsoleHandler {

Expand All @@ -43,10 +42,10 @@ public static void hookConsole() {
}

private static void listen() {
final BufferedReader reader = new BufferedReader(new InputStreamReader(new DelayedStream(System.in, 500)));
final Scanner scanner = new Scanner(System.in);
try {
String line;
while ((line = reader.readLine()) != null) {
while (scanner.hasNextLine()) {
final String line = scanner.nextLine();
try {
final String[] parts = line.split(" ");
if (parts.length == 0) continue;
Expand Down
94 changes: 0 additions & 94 deletions src/main/java/net/raphimc/viaproxy/cli/DelayedStream.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.cli.ConsoleFormatter;
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;
Expand Down Expand Up @@ -92,7 +93,7 @@ public boolean handleC2P(IPacket packet, List<ChannelFutureListener> listeners)
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));
Expand Down Expand Up @@ -122,21 +123,19 @@ public boolean handleC2P(IPacket packet, List<ChannelFutureListener> listeners)
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));
Expand All @@ -151,7 +150,9 @@ public boolean handleC2P(IPacket packet, List<ChannelFutureListener> listeners)

@Override
public boolean handleP2S(IPacket packet, List<ChannelFutureListener> listeners) throws GeneralSecurityException, ExecutionException, InterruptedException {
if (packet instanceof S2CLoginKeyPacket1_7 loginKeyPacket) {
if (packet instanceof S2CLoginDisconnectPacket1_7 loginDisconnectPacket) {
Logger.u_info("server kick", this.proxyConnection.getC2P().remoteAddress(), this.proxyConnection.getGameProfile(), ConsoleFormatter.convert(loginDisconnectPacket.reason.asLegacyFormatString()));
} else if (packet instanceof S2CLoginKeyPacket1_7 loginKeyPacket) {
final PublicKey publicKey = CryptUtil.decodeRsaPublicKey(loginKeyPacket.publicKey);
final SecretKey secretKey = CryptUtil.generateSecretKey();
final String serverHash = new BigInteger(CryptUtil.computeServerIdHash(loginKeyPacket.serverId, publicKey, secretKey)).toString(16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.netty.buffer.Unpooled;
import io.netty.channel.*;
import io.netty.util.AttributeKey;
import net.lenni0451.mcstructs.text.components.StringComponent;
import net.raphimc.netminecraft.constants.ConnectionState;
import net.raphimc.netminecraft.constants.MCPackets;
import net.raphimc.netminecraft.constants.MCPipeline;
Expand All @@ -35,11 +36,12 @@
import net.raphimc.netminecraft.packet.PacketTypes;
import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket1_7;
import net.raphimc.netminecraft.packet.impl.login.S2CLoginCustomPayloadPacket;
import net.raphimc.netminecraft.packet.impl.login.S2CLoginDisconnectPacket;
import net.raphimc.netminecraft.packet.impl.login.S2CLoginDisconnectPacket1_20_3;
import net.raphimc.netminecraft.packet.impl.status.S2CStatusResponsePacket;
import net.raphimc.netminecraft.packet.registry.PacketRegistryUtil;
import net.raphimc.netminecraft.util.ServerAddress;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.cli.ConsoleFormatter;
import net.raphimc.viaproxy.proxy.external_interface.OpenAuthModConstants;
import net.raphimc.viaproxy.proxy.packethandler.PacketHandler;
import net.raphimc.viaproxy.proxy.util.CloseAndReturn;
Expand Down Expand Up @@ -247,7 +249,7 @@ public CompletableFuture<ByteBuf> sendCustomPayload(final String channel, final
PacketTypes.writeString(disconnectPacketData, channel);
PacketTypes.writeVarInt(disconnectPacketData, id);
disconnectPacketData.writeBytes(data);
this.c2p.writeAndFlush(new S2CLoginDisconnectPacket(messageToJson("§cYou need to install OpenAuthMod in order to join this server.§k\n" + Base64.getEncoder().encodeToString(ByteBufUtil.getBytes(disconnectPacketData)) + "\n" + OpenAuthModConstants.LEGACY_MAGIC_STRING))).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
this.c2p.writeAndFlush(new S2CLoginDisconnectPacket1_20_3(new StringComponent("§cYou need to install OpenAuthMod in order to join this server.§k\n" + Base64.getEncoder().encodeToString(ByteBufUtil.getBytes(disconnectPacketData)) + "\n" + OpenAuthModConstants.LEGACY_MAGIC_STRING))).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
break;
case PLAY:
Expand Down Expand Up @@ -275,13 +277,13 @@ public boolean handleCustomPayload(final int id, final ByteBuf data) {
}

public void kickClient(final String message) throws CloseAndReturn {
Logger.u_err("kick", this.c2p.remoteAddress(), this.getGameProfile(), message.replaceAll("§.", ""));
Logger.u_err("proxy kick", this.c2p.remoteAddress(), this.getGameProfile(), ConsoleFormatter.convert(message));

final ChannelFuture future;
if (this.c2pConnectionState == ConnectionState.STATUS) {
future = this.c2p.writeAndFlush(new S2CStatusResponsePacket("{\"players\":{\"max\":0,\"online\":0},\"description\":" + new JsonPrimitive(message) + ",\"version\":{\"protocol\":-1,\"name\":\"ViaProxy\"}}"));
} else if (this.c2pConnectionState == ConnectionState.LOGIN) {
future = this.c2p.writeAndFlush(new S2CLoginDisconnectPacket(messageToJson(message)));
future = this.c2p.writeAndFlush(new S2CLoginDisconnectPacket1_20_3(new StringComponent(message)));
} else if (this.c2pConnectionState == ConnectionState.CONFIGURATION) {
final ByteBuf disconnectPacket = Unpooled.buffer();
PacketTypes.writeVarInt(disconnectPacket, MCPackets.S2C_CONFIG_DISCONNECT.getId(this.clientVersion.getVersion()));
Expand Down

0 comments on commit 9a41bca

Please sign in to comment.