Skip to content

Commit e25d726

Browse files
committed
Revert "Implement a more robust IPC system between the launcher and client (#4159)"
This reverts commit 5ffcc48.
1 parent 11e99cb commit e25d726

File tree

15 files changed

+70
-568
lines changed

15 files changed

+70
-568
lines changed

apps/app/src/api/oauth_utils/auth_code_reply.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@
1111
//! [RFC 8252]: https://datatracker.ietf.org/doc/html/rfc8252
1212
1313
use std::{
14-
net::SocketAddr,
14+
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
1515
sync::{LazyLock, Mutex},
1616
time::Duration,
1717
};
1818

1919
use hyper::body::Incoming;
2020
use hyper_util::rt::{TokioIo, TokioTimer};
2121
use theseus::ErrorKind;
22-
use theseus::prelude::tcp_listen_any_loopback;
23-
use tokio::sync::{broadcast, oneshot};
22+
use tokio::{
23+
net::TcpListener,
24+
sync::{broadcast, oneshot},
25+
};
2426

2527
static SERVER_SHUTDOWN: LazyLock<broadcast::Sender<()>> =
2628
LazyLock::new(|| broadcast::channel(1024).0);
@@ -33,7 +35,17 @@ static SERVER_SHUTDOWN: LazyLock<broadcast::Sender<()>> =
3335
pub async fn listen(
3436
listen_socket_tx: oneshot::Sender<Result<SocketAddr, theseus::Error>>,
3537
) -> Result<Option<String>, theseus::Error> {
36-
let listener = match tcp_listen_any_loopback().await {
38+
// IPv4 is tried first for the best compatibility and performance with most systems.
39+
// IPv6 is also tried in case IPv4 is not available. Resolving "localhost" is avoided
40+
// to prevent failures deriving from improper name resolution setup. Any available
41+
// ephemeral port is used to prevent conflicts with other services. This is all as per
42+
// RFC 8252's recommendations
43+
const ANY_LOOPBACK_SOCKET: &[SocketAddr] = &[
44+
SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 0),
45+
SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 0),
46+
];
47+
48+
let listener = match TcpListener::bind(ANY_LOOPBACK_SOCKET).await {
3749
Ok(listener) => {
3850
listen_socket_tx
3951
.send(listener.local_addr().map_err(|e| {

packages/app-lib/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ fn build_java_jars() {
5353
.arg("build")
5454
.arg("--no-daemon")
5555
.arg("--console=rich")
56+
.arg("--info")
5657
.current_dir(dunce::canonicalize("java").unwrap())
5758
.status()
5859
.expect("Failed to wait on Gradle build");

packages/app-lib/java/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ repositories {
1111
dependencies {
1212
implementation("org.ow2.asm:asm:9.8")
1313
implementation("org.ow2.asm:asm-tree:9.8")
14-
implementation("com.google.code.gson:gson:2.13.1")
1514

1615
testImplementation(libs.junit.jupiter)
1716
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

packages/app-lib/java/src/main/java/com/modrinth/theseus/MinecraftLaunch.java

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,57 @@
11
package com.modrinth.theseus;
22

3-
import com.modrinth.theseus.rpc.RpcHandlers;
4-
import com.modrinth.theseus.rpc.TheseusRpc;
3+
import java.io.ByteArrayOutputStream;
54
import java.io.IOException;
65
import java.lang.reflect.AccessibleObject;
76
import java.lang.reflect.Method;
87
import java.lang.reflect.Modifier;
98
import java.util.Arrays;
10-
import java.util.concurrent.CompletableFuture;
119

1210
public final class MinecraftLaunch {
1311
public static void main(String[] args) throws IOException, ReflectiveOperationException {
1412
final String mainClass = args[0];
1513
final String[] gameArgs = Arrays.copyOfRange(args, 1, args.length);
1614

1715
System.setProperty("modrinth.process.args", String.join("\u001f", gameArgs));
16+
parseInput();
1817

19-
final CompletableFuture<Void> waitForLaunch = new CompletableFuture<>();
20-
TheseusRpc.connectAndStart(
21-
System.getProperty("modrinth.internal.ipc.host"),
22-
Integer.getInteger("modrinth.internal.ipc.port"),
23-
new RpcHandlers()
24-
.handler("set_system_property", String.class, String.class, System::setProperty)
25-
.handler("launch", () -> waitForLaunch.complete(null)));
26-
27-
waitForLaunch.join();
2818
relaunch(mainClass, gameArgs);
2919
}
3020

21+
private static void parseInput() throws IOException {
22+
final ByteArrayOutputStream line = new ByteArrayOutputStream();
23+
while (true) {
24+
final int b = System.in.read();
25+
if (b < 0) {
26+
throw new IllegalStateException("Stdin terminated while parsing");
27+
}
28+
if (b != '\n') {
29+
line.write(b);
30+
continue;
31+
}
32+
if (handleLine(line.toString("UTF-8"))) {
33+
break;
34+
}
35+
line.reset();
36+
}
37+
}
38+
39+
private static boolean handleLine(String line) {
40+
final String[] parts = line.split("\t", 2);
41+
switch (parts[0]) {
42+
case "property": {
43+
final String[] keyValue = parts[1].split("\t", 2);
44+
System.setProperty(keyValue[0], keyValue[1]);
45+
return false;
46+
}
47+
case "launch":
48+
return true;
49+
}
50+
51+
System.err.println("Unknown input line " + line);
52+
return false;
53+
}
54+
3155
private static void relaunch(String mainClassName, String[] args) throws ReflectiveOperationException {
3256
final int javaVersion = getJavaVersion();
3357
final Class<?> mainClass = Class.forName(mainClassName);

packages/app-lib/java/src/main/java/com/modrinth/theseus/rpc/RpcHandlers.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

packages/app-lib/java/src/main/java/com/modrinth/theseus/rpc/RpcMethodException.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/app-lib/java/src/main/java/com/modrinth/theseus/rpc/TheseusRpc.java

Lines changed: 0 additions & 183 deletions
This file was deleted.

packages/app-lib/src/api/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ pub mod prelude {
3535
jre, metadata, minecraft_auth, mr_auth, pack, process,
3636
profile::{self, Profile, create},
3737
settings,
38-
util::{
39-
io::{IOError, canonicalize},
40-
network::tcp_listen_any_loopback,
41-
},
38+
util::io::{IOError, canonicalize},
4239
};
4340
}

packages/app-lib/src/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,6 @@ pub enum ErrorKind {
151151
"A skin texture must have a dimension of either 64x64 or 64x32 pixels"
152152
)]
153153
InvalidSkinTexture,
154-
155-
#[error("RPC error: {0}")]
156-
RpcError(String),
157154
}
158155

159156
#[derive(Debug)]

0 commit comments

Comments
 (0)