diff --git a/build.gradle b/build.gradle
index aca5f27..3d14728 100644
--- a/build.gradle
+++ b/build.gradle
@@ -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"
@@ -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"
@@ -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"
}
diff --git a/gradle.properties b/gradle.properties
index 34c2be5..7a42fba 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -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
diff --git a/src/main/java/net/raphimc/viaproxy/cli/ConsoleHandler.java b/src/main/java/net/raphimc/viaproxy/cli/ConsoleHandler.java
index d3235fc..df9047f 100644
--- a/src/main/java/net/raphimc/viaproxy/cli/ConsoleHandler.java
+++ b/src/main/java/net/raphimc/viaproxy/cli/ConsoleHandler.java
@@ -24,10 +24,9 @@ import net.raphimc.viaproxy.protocolhack.viaproxy.ConsoleCommandSender;
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 {
@@ -43,10 +42,10 @@ public class ConsoleHandler {
}
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;
diff --git a/src/main/java/net/raphimc/viaproxy/cli/DelayedStream.java b/src/main/java/net/raphimc/viaproxy/cli/DelayedStream.java
deleted file mode 100644
index a7d1386..0000000
--- a/src/main/java/net/raphimc/viaproxy/cli/DelayedStream.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.cli;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-public class DelayedStream extends InputStream {
-
- private final InputStream parent;
- private final long sleepDelay;
-
- public DelayedStream(final InputStream parent, final long sleepDelay) {
- this.parent = parent;
- this.sleepDelay = sleepDelay;
- }
-
- public InputStream getParent() {
- return this.parent;
- }
-
- public long getSleepDelay() {
- return this.sleepDelay;
- }
-
- public void waitForInput() throws IOException {
- while (this.available() <= 0) {
- try {
- Thread.sleep(this.sleepDelay);
- } catch (InterruptedException e) {
- throw new IOException("Interrupted", e);
- }
- }
- }
-
- @Override
- public int read() throws IOException {
- this.waitForInput();
- return this.parent.read();
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- this.waitForInput();
- return this.parent.read(b);
- }
-
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- this.waitForInput();
- return this.parent.read(b, off, len);
- }
-
- @Override
- public int available() throws IOException {
- return this.parent.available();
- }
-
- @Override
- public void close() throws IOException {
- this.parent.close();
- }
-
- @Override
- public synchronized void mark(int readlimit) {
- this.parent.mark(readlimit);
- }
-
- @Override
- public synchronized void reset() throws IOException {
- this.parent.reset();
- }
-
- @Override
- public boolean markSupported() {
- return this.parent.markSupported();
- }
-
-}
diff --git a/src/main/java/net/raphimc/viaproxy/plugins/events/PreMojangAuthEvent.java b/src/main/java/net/raphimc/viaproxy/plugins/events/ShouldVerifyOnlineModeEvent.java
similarity index 88%
rename from src/main/java/net/raphimc/viaproxy/plugins/events/PreMojangAuthEvent.java
rename to src/main/java/net/raphimc/viaproxy/plugins/events/ShouldVerifyOnlineModeEvent.java
index e8fd357..0b97125 100644
--- a/src/main/java/net/raphimc/viaproxy/plugins/events/PreMojangAuthEvent.java
+++ b/src/main/java/net/raphimc/viaproxy/plugins/events/ShouldVerifyOnlineModeEvent.java
@@ -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;
}
diff --git a/src/main/java/net/raphimc/viaproxy/proxy/packethandler/LoginPacketHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/packethandler/LoginPacketHandler.java
index a63d908..a72de7b 100644
--- a/src/main/java/net/raphimc/viaproxy/proxy/packethandler/LoginPacketHandler.java
+++ b/src/main/java/net/raphimc/viaproxy/proxy/packethandler/LoginPacketHandler.java
@@ -30,9 +30,10 @@ import net.raphimc.netminecraft.packet.impl.login.*;
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;
@@ -92,7 +93,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 +123,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));
@@ -151,7 +150,9 @@ public class LoginPacketHandler extends PacketHandler {
@Override
public boolean handleP2S(IPacket packet, List 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);
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 f2aa5d1..379ffd9 100644
--- a/src/main/java/net/raphimc/viaproxy/proxy/session/ProxyConnection.java
+++ b/src/main/java/net/raphimc/viaproxy/proxy/session/ProxyConnection.java
@@ -27,6 +27,7 @@ import io.netty.buffer.ByteBufUtil;
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;
@@ -35,11 +36,12 @@ import net.raphimc.netminecraft.netty.crypto.AESEncryption;
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;
@@ -247,7 +249,7 @@ public class ProxyConnection extends NetClient {
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:
@@ -275,13 +277,13 @@ public class ProxyConnection extends NetClient {
}
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()));