Skip to content

Commit 650ab71

Browse files
Commonized networking (#3310)
* Fix not being able to connect to local friends socket * Start basic work on tunneling protocol and move some code into a common crate * Commonize message serialization logic * Serialize Base62Ids as u64 when human-readability is not required * Move ActiveSockets tuple into struct * Make CI run when rust-common is updated CI is currently broken for labrinth, however * Fix theseus-release.yml to reference itself correctly * Implement Labrinth side of tunneling * Implement non-friend part of theseus tunneling * Implement client-side except for socket loop * Implement the socket loop Doesn't work though. Debugging time! * Fix config.rs * Fix deadlock in labrinth socket handling * Update dockerfile * switch to workspace prepare at root level * Wait for connection before tunneling in playground * Move rust-common into labrinth * Remove rust-common references from Actions * Revert "Update dockerfile" This reverts commit 3caad59. * Fix Docker build * Rebuild Theseus if common code changes * Allow multiple connections from the same user * Fix test building * Move FriendSocketListening and FriendSocketStoppedListening to non-panicking TODO for now * Make message_serialization macro take varargs for binary messages * Improve syntax of message_serialization macro * Remove the ability to connect to a virtual socket, and disable the ability to listen on one * Allow the app to compile without running labrinth * Clippy fix * Update Rust and Clippy fix again --------- Co-authored-by: Jai A <jaiagr+gpg@pm.me>
1 parent 90def72 commit 650ab71

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1133
-585
lines changed

.github/workflows/theseus-release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ on:
66
tags:
77
- 'v*'
88
paths:
9-
- .github/workflows/app-release.yml
9+
- .github/workflows/theseus-release.yml
1010
- 'apps/app/**'
1111
- 'apps/app-frontend/**'
12+
- 'apps/labrinth/src/common/**'
13+
- 'apps/labrinth/Cargo.toml'
1214
- 'packages/app-lib/**'
1315
- 'packages/app-macros/**'
1416
- 'packages/assets/**'

.idea/code.iml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.lock

Lines changed: 47 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ strip = true # Remove debug symbols
2121
opt-level = 3
2222

2323
[patch.crates-io]
24-
wry = { git = "https://github.com/modrinth/wry", rev = "51907c6" }
24+
wry = { git = "https://github.com/modrinth/wry", rev = "51907c6" }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[env]
2+
SQLX_OFFLINE = "true"

apps/app-playground/src/main.rs

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
windows_subsystem = "windows"
44
)]
55

6+
use std::time::Duration;
67
use theseus::prelude::*;
7-
8-
use theseus::profile::create::profile_create;
8+
use tokio::signal::ctrl_c;
99

1010
// A simple Rust implementation of the authentication run
1111
// 1) call the authenticate_begin_flow() function to get the URL to open (like you would in the frontend)
@@ -41,54 +41,21 @@ async fn main() -> theseus::Result<()> {
4141
// Initialize state
4242
State::init().await?;
4343

44-
if minecraft_auth::users().await?.is_empty() {
45-
println!("No users found, authenticating.");
46-
authenticate_run().await?; // could take credentials from here direct, but also deposited in state users
47-
}
48-
//
49-
// st.settings
50-
// .write()
51-
// .await
52-
// .java_globals
53-
// .insert(JAVA_8_KEY.to_string(), check_jre(path).await?.unwrap());
54-
// Clear profiles
55-
println!("Clearing profiles.");
56-
{
57-
let h = profile::list().await?;
58-
for profile in h.into_iter() {
59-
profile::remove(&profile.path).await?;
44+
loop {
45+
if State::get().await?.friends_socket.is_connected().await {
46+
break;
6047
}
48+
tokio::time::sleep(Duration::from_millis(500)).await;
6149
}
6250

63-
println!("Creating/adding profile.");
64-
65-
let name = "Example".to_string();
66-
let game_version = "1.16.1".to_string();
67-
let modloader = ModLoader::Forge;
68-
let loader_version = "stable".to_string();
69-
70-
let profile_path = profile_create(
71-
name,
72-
game_version,
73-
modloader,
74-
Some(loader_version),
75-
None,
76-
None,
77-
None,
78-
)
79-
.await?;
80-
81-
println!("running");
82-
// Run a profile, running minecraft and store the RwLock to the process
83-
let process = profile::run(&profile_path).await?;
84-
85-
println!("Minecraft UUID: {}", process.uuid);
51+
tracing::info!("Starting host");
8652

87-
println!("All running process UUID {:?}", process::get_all().await?);
53+
let socket = State::get().await?.friends_socket.open_port(25565).await?;
54+
tracing::info!("Running host on socket {}", socket.socket_id());
8855

89-
// hold the lock to the process until it ends
90-
println!("Waiting for process to end...");
91-
process::wait_for(process.uuid).await?;
56+
ctrl_c().await?;
57+
tracing::info!("Stopping host");
58+
socket.shutdown().await?;
9259

9360
Ok(())
9461
}

apps/app/.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[env]
2+
SQLX_OFFLINE = "true"

apps/labrinth/.sqlx/query-11344e920ea606504c2fdc3c5a3cb1b1e990def66cf260cb5d648cab72cc34f1.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/.sqlx/query-2b097a9a1b24b9648d3558e348c7d8cd467e589504c6e754f1f6836203946590.json

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

apps/labrinth/.sqlx/query-527291243eb3684e956d7d49c579857ce857ff462c830dd0cb74574f415d4105.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)