diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d218eff --- /dev/null +++ b/LICENSE @@ -0,0 +1,16 @@ +Copyright (c) [2025] [Methanium] +All rights reserved. + +This software is protected by copyright. Copying, editing, +distributing, publicly performing, or any other use of this software +or its components, in source or binary form, is strictly prohibited without the express +written permission of the copyright holder. + +FUTURE LICENSE ACCEPTANCE: +It is the copyright holder's intention to release this software in the future +under a license yet to be defined, which will, among other things, +allow private, non-commercial use. This statement does not constitute +a current license grant and does not alter the above +prohibition on use, copying, or modification. Until the formal +publication of such a future license, all rights remain +reserved. diff --git a/src/auth/auth_connector.rs b/src/auth/auth_connector.rs index 0a9ee36..fd48a2d 100644 --- a/src/auth/auth_connector.rs +++ b/src/auth/auth_connector.rs @@ -28,7 +28,7 @@ fn client() -> Client { } pub async fn unregister_user(user_id: Uuid, reset_token: &str) -> Option { - let url = format!("https:/auth.tensamin.methanium.net/api/delete/{}", user_id); + let url = format!("https:/auth.tensamin.net/api/delete/{}", user_id); let client = client(); let mut payload = JsonValue::new_object(); @@ -47,10 +47,7 @@ pub async fn unregister_user(user_id: Uuid, reset_token: &str) -> Option { } pub async fn get_uuid(username: &str) -> Option { - let url = format!( - "https://auth.tensamin.methanium.net/api/get/uuid/{}", - username - ); + let url = format!("https://auth.tensamin.net/api/get/uuid/{}", username); let client = client(); let res = client.get(&url).send().await.ok()?; let json = res.text().await.ok()?; @@ -62,7 +59,7 @@ pub async fn get_uuid(username: &str) -> Option { } pub async fn get_user(user_id: Uuid) -> Option { - let url = format!("https://auth.tensamin.methanium.net/api/get/{}", user_id); + let url = format!("https://auth.tensamin.net/api/get/{}", user_id); let client = client(); let res = client.get(&url).send().await.ok()?; let json = res.text().await.ok()?; @@ -101,7 +98,7 @@ pub async fn get_user(user_id: Uuid) -> Option { } pub async fn get_register() -> Option { - let url = "https://auth.tensamin.methanium.net/api/register/init".to_string(); + let url = "https://auth.tensamin.net/api/register/init".to_string(); let client = client(); let res = client.get(&url).send().await.ok()?; let json = res.text().await.ok()?; @@ -111,7 +108,7 @@ pub async fn get_register() -> Option { } pub async fn complete_register(user_profile: &UserProfile, iota_id: &str) -> bool { - let url = "https://auth.tensamin.methanium.net/api/register/complete"; + let url = "https://auth.tensamin.net/api/register/complete"; let client = client(); let mut payload = JsonValue::new_object(); @@ -139,7 +136,7 @@ pub async fn complete_register(user_profile: &UserProfile, iota_id: &str) -> boo pub async fn migrate_user(user_profile: &mut UserProfile) -> bool { let url = format!( - "https://auth.tensamin.methanium.net/api/change/iota-id/{}", + "https://auth.tensamin.net/api/change/iota-id/{}", user_profile.user_id ); let client = client(); diff --git a/src/communities/interactables/interactable.rs b/src/communities/interactables/interactable.rs index db99ebd..7982a69 100644 --- a/src/communities/interactables/interactable.rs +++ b/src/communities/interactables/interactable.rs @@ -4,8 +4,8 @@ use crate::{ }; use axum::Json; use json::JsonValue; -use std::any::Any; use std::sync::Arc; +use std::{any::Any, pin::Pin}; pub type InteractableFactory = fn() -> Box; diff --git a/src/communities/interactables/text_chat.rs b/src/communities/interactables/text_chat.rs index 5a3b2da..5bc0ead 100644 --- a/src/communities/interactables/text_chat.rs +++ b/src/communities/interactables/text_chat.rs @@ -1,5 +1,8 @@ use crate::{ - communities::{community::Community, interactables::interactable::Interactable}, + communities::{ + community::Community, community_connection::CommunityConnection, + interactables::interactable::Interactable, + }, data::communication::{CommunicationType, CommunicationValue, DataTypes}, gui::log_panel::log_message, util::file_util::{get_children, load_file, save_file}, @@ -7,9 +10,13 @@ use crate::{ use aes_gcm::aead::Payload; use axum::Json; use json::{JsonValue, array, object}; -use std::any::Any; -use std::fs::{self, File}; +use rustls::ClientConnection; use std::sync::Arc; +use std::{any::Any, collections::HashMap}; +use std::{ + fs::{self, File}, + pin::Pin, +}; use uuid::Uuid; pub struct TextChat { name: String, @@ -183,35 +190,61 @@ impl Interactable for TextChat { JsonValue::new_object() } fn run_function(&self, cv: CommunicationValue) -> CommunicationValue { - let payload = cv.get_data(DataTypes::payload).unwrap(); - if cv.get_data(DataTypes::function).unwrap().as_str().unwrap() == "get_messages" { - let amount = payload["amount"].as_i64().unwrap(); - let loaded_messages = payload["loaded_messages"].as_i64().unwrap(); - let messages = self.get_messages(loaded_messages, amount); - let mut payload = JsonValue::new_object(); - payload["messages"] = messages; - return CommunicationValue::new(CommunicationType::function) - .with_id(cv.get_id()) - .add_data_str(DataTypes::name, self.name.clone()) - .add_data_str(DataTypes::path, self.path.clone()) - .add_data_str(DataTypes::result, "message_chunk".to_string()) - .add_data(DataTypes::payload, payload); - } - if cv.get_data(DataTypes::function).unwrap().as_str().unwrap() == "send_message" { - let message = payload["message"].as_str().unwrap(); - let milliseconds_timestamp: u128 = std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .unwrap() - .as_millis(); - self.add_message(milliseconds_timestamp, cv.get_sender().unwrap(), message); - return CommunicationValue::new(CommunicationType::function) - .with_id(cv.get_id()) - .add_data_str(DataTypes::name, self.name.clone()) - .add_data_str(DataTypes::path, self.path.clone()) - .add_data_str(DataTypes::result, "message_received".to_string()) - .add_data(DataTypes::payload, JsonValue::new_object()); - } - CommunicationValue::new(CommunicationType::error).with_id(cv.get_id()) + let ret: Pin + Send>> = Box::pin(async move { + let payload = cv.get_data(DataTypes::payload).unwrap(); + if cv.get_data(DataTypes::function).unwrap().as_str().unwrap() == "get_messages" { + let amount = payload["amount"].as_i64().unwrap(); + let loaded_messages = payload["loaded_messages"].as_i64().unwrap(); + let messages = self.get_messages(loaded_messages, amount).clone(); + let mut payload = JsonValue::new_object(); + payload["messages"] = messages; + return CommunicationValue::new(CommunicationType::function) + .with_id(cv.get_id()) + .add_data_str(DataTypes::name, self.name.clone()) + .add_data_str(DataTypes::path, self.path.clone()) + .add_data_str(DataTypes::result, "message_chunk".to_string()) + .add_data(DataTypes::payload, payload); + } + if cv.get_data(DataTypes::function).unwrap().as_str().unwrap() == "send_message" { + let message = payload["message"].as_str().unwrap(); + let milliseconds_timestamp: u128 = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_millis(); + self.add_message(milliseconds_timestamp, cv.get_sender().unwrap(), message); + + let mut distribution_payload = JsonValue::new_object(); + distribution_payload["message"] = JsonValue::String(message.to_string()); + distribution_payload["sender_id"] = + JsonValue::String(cv.get_sender().unwrap().to_string()); + distribution_payload["send_time"] = + JsonValue::String(milliseconds_timestamp.to_string()); + let distribution = CommunicationValue::new(CommunicationType::update) + .with_id(cv.get_id()) + .add_data_str(DataTypes::name, self.name.clone()) + .add_data_str(DataTypes::path, self.path.clone()) + .add_data_str(DataTypes::result, "message_live".to_string()) + .add_data(DataTypes::payload, distribution_payload); + + let connections: HashMap>> = + self.get_community().get_connections().await.clone(); + + for con in connections.values() { + for c in con { + let cd: &Arc = c; + cd.send_message(&distribution).await; + } + } + return CommunicationValue::new(CommunicationType::function) + .with_id(cv.get_id()) + .add_data_str(DataTypes::name, self.name.clone()) + .add_data_str(DataTypes::path, self.path.clone()) + .add_data_str(DataTypes::result, "message_received".to_string()) + .add_data(DataTypes::payload, JsonValue::new_object()); + } + CommunicationValue::new(CommunicationType::error).with_id(cv.get_id()) + }); + CommunicationValue::new(CommunicationType::error) } fn to_json(&self) -> JsonValue { let mut v = JsonValue::new_object(); diff --git a/src/main.rs b/src/main.rs index 61b1fa0..5aff9df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,6 +59,7 @@ async fn main() { } if !sb.is_empty() { + {} sb.remove(0); sb = sb + ","; } diff --git a/src/omikron/omikron_connection.rs b/src/omikron/omikron_connection.rs index 584851e..aabc526 100644 --- a/src/omikron/omikron_connection.rs +++ b/src/omikron/omikron_connection.rs @@ -54,7 +54,7 @@ impl OmikronConnection { /// Connect loop with retry pub async fn connect(&self) { loop { - match connect_async("wss://tensamin.methanium.net/ws/iota/").await { + match connect_async("wss://app.tensamin.net/ws/iota/").await { Ok((ws_stream, _)) => { let (write_half, read_half) = ws_stream.split(); *self.writer.lock().await = Some(write_half);