diff --git a/src/cli.rs b/src/cli.rs index a7c5527..1168b9c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -46,7 +46,7 @@ use crate::process::*; use crate::project::*; use crate::template::*; -const DEFAULT_BASE_URL: &str = "https://editor.netsblox.org"; +const DEFAULT_BASE_URL: &str = "https://cloud.netsblox.org"; const STEPS_PER_IO_ITER: usize = 64; const MAX_REQUEST_SIZE_BYTES: usize = 1024 * 1024 * 1024; const YIELDS_BEFORE_IDLE_SLEEP: usize = 256; diff --git a/src/std_system.rs b/src/std_system.rs index aa79e52..9c93fc7 100644 --- a/src/std_system.rs +++ b/src/std_system.rs @@ -100,7 +100,7 @@ type MessageReplies = BTreeMap; async fn call_rpc_async>>(context: &Context, client: &reqwest::Client, service: &str, rpc: &str, args: &[(&str, &Json)]) -> Result { let time = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(); - let url = format!("{base_url}/services/{service}/{rpc}?uuid={client_id}&projectId={project_id}&roleId={role_id}&t={time}", + let url = format!("{base_url}/{service}/{rpc}?uuid={client_id}&projectId={project_id}&roleId={role_id}&t={time}", base_url = context.base_url, client_id = context.client_id, project_id = context.project_id, role_id = context.role_id); let args: BTreeMap<&str, &Json> = args.iter().copied().collect(); @@ -156,11 +156,13 @@ impl>> StdSystem { pub async fn new_sync(base_url: String, project_name: Option<&str>, config: Config, utc_offset: UtcOffset) -> Self { Self::new_async(base_url, project_name, config, utc_offset).await } - /// Initializes a new instance of [`StdSystem`] targeting the given NetsBlox server base url (e.g., `https://editor.netsblox.org`). + /// Initializes a new instance of [`StdSystem`] targeting the given NetsBlox server base url (e.g., `https://cloud.netsblox.org`). pub async fn new_async(base_url: String, project_name: Option<&str>, config: Config, utc_offset: UtcOffset) -> Self { + let configuration = reqwest::get(format!("{}/configuration", base_url)).await.unwrap().json::>().await.unwrap(); + let mut context = Context { base_url, - client_id: format!("vm-{}", names::Generator::default().next().unwrap()), + client_id: configuration["clientId"].as_str().unwrap().to_owned(), project_name: project_name.unwrap_or("untitled").to_owned(), project_id: String::new(), @@ -176,7 +178,7 @@ impl>> StdSystem { #[tokio::main(flavor = "multi_thread", worker_threads = 1)] async fn handler>>(base_url: String, client_id: String, project_name: String, message_replies: Arc>, out_receiver: Receiver>>, in_sender: Sender>>) { - let ws_url = if let Some(x) = base_url.strip_prefix("http") { format!("ws{}", x) } else { format!("wss://{}", base_url) }; + let ws_url = format!("{}/network/{}/connect", if let Some(x) = base_url.strip_prefix("http") { format!("ws{}", x) } else { format!("wss://{}", base_url) }, client_id); let (ws, _) = tokio_tungstenite::connect_async(ws_url).await.unwrap(); let (mut ws_sender, ws_receiver) = ws.split(); let (ws_sender_sender, ws_sender_receiver) = async_channel::unbounded(); @@ -272,19 +274,17 @@ impl>> StdSystem { }; let client = Arc::new(reqwest::Client::builder().build().unwrap()); - let meta = client.post(format!("{}/api/newProject", context.base_url)) - .json(&json!({ "clientId": context.client_id, "roleName": "monad" })) + let meta = client.post(format!("{}/projects/", context.base_url)) + .json(&json!({ "clientId": context.client_id, "name": context.project_name })) .send().await.unwrap() .json::>().await.unwrap(); - context.project_id = meta["projectId"].as_str().unwrap().to_owned(); - context.role_id = meta["roleId"].as_str().unwrap().to_owned(); - context.role_name = meta["roleName"].as_str().unwrap().to_owned(); + context.project_id = meta["id"].as_str().unwrap().to_owned(); - let meta = client.post(format!("{}/api/setProjectName", context.base_url)) - .json(&json!({ "projectId": context.project_id, "name": context.project_name })) - .send().await.unwrap() - .json::>().await.unwrap(); - context.project_name = meta["name"].as_str().unwrap().to_owned(); + let roles = &meta["roles"].as_object().unwrap(); + let (first_role_id, first_role_meta) = roles.get_key_value(roles.keys().next().unwrap()).unwrap(); + let first_role_meta = first_role_meta.as_object().unwrap(); + context.role_id = first_role_id.to_owned(); + context.role_name = first_role_meta.get("name").unwrap().as_str().unwrap().to_owned(); let context = Arc::new(context); let rpc_request_pipe = { diff --git a/src/test/mod.rs b/src/test/mod.rs index db687b9..d405453 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -12,7 +12,7 @@ use crate::gc::*; mod process; mod project; -const BASE_URL: &'static str = "https://editor.netsblox.org"; +const BASE_URL: &'static str = "https://cloud.netsblox.org"; #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum NativeType {}