From fa75ca60c4991ded6449fb0cbb1c19ed32597782 Mon Sep 17 00:00:00 2001 From: MeexReay Date: Wed, 23 Apr 2025 00:39:49 +0300 Subject: [PATCH] rac urls and change nicks colors --- src/chat/gui.rs | 2 +- src/chat/styles/style.css | 8 ++--- src/proto/mod.rs | 62 +++++++++++++++++++++++++++++++++++---- 3 files changed, 62 insertions(+), 10 deletions(-) diff --git a/src/chat/gui.rs b/src/chat/gui.rs index 02314bc..06bd4b0 100644 --- a/src/chat/gui.rs +++ b/src/chat/gui.rs @@ -408,7 +408,7 @@ fn build_ui(ctx: Arc, app: &Application) -> UiModel { let server_list = ListBox::new(); - for url in ["meex.lol:42666", "meex.lol:11234", "91.192.22.20:42666"] { + for url in ["rac://meex.lol", "rac://meex.lol:11234", "rac://91.192.22.20"] { let url = url.to_string(); let label = Label::builder() diff --git a/src/chat/styles/style.css b/src/chat/styles/style.css index d8696bd..ee4000e 100644 --- a/src/chat/styles/style.css +++ b/src/chat/styles/style.css @@ -18,7 +18,7 @@ .message-name { font-weight: bold; } -.message-name-green { color: #16a516; } -.message-name-red { color: #b91818; } -.message-name-magenta { color: #b619b6; } -.message-name-cyan { color: #19b1b1; } \ No newline at end of file +.message-name-green { color: #70fa7a; } +.message-name-red { color: #fa7070; } +.message-name-magenta { color: #da70fa; } +.message-name-cyan { color: #70fadc; } \ No newline at end of file diff --git a/src/proto/mod.rs b/src/proto/mod.rs index 27765a0..c808059 100644 --- a/src/proto/mod.rs +++ b/src/proto/mod.rs @@ -53,6 +53,61 @@ pub fn parse_socks5_url(url: &str) -> Option<(String, Option<(String, String)>)> } } +/// url -> (host, ssl, wrac) \ +/// `127.0.0.1` -> `("127.0.0.1:42666", false, false)` \ +/// `127.0.0.1:12345` -> `("127.0.0.1:12345", false, false)` \ +/// `rac://127.0.0.1/` -> `("127.0.0.1:42666", false, false)` \ +/// `racs://127.0.0.1/` -> `("127.0.0.1:42667", true, false)` \ +/// `wrac://127.0.0.1/` -> `("127.0.0.1:52666", false, true)` \ +/// `wracs://127.0.0.1/` -> `(127.0.0.1:52667, true, true)` \ +pub fn parse_rac_url(url: &str) -> Option<(String, bool, bool)> { + let (scheme, url) = url.split_once("://").unwrap_or(("rac", url)); + let (host, _) = url.split_once("/").unwrap_or((url, "")); + match scheme.to_lowercase().as_str() { + "rac" => { + Some(( + if host.contains(":") { + host.to_string() + } else { + format!("{host}:42666") + }, + false, false + )) + }, + "racs" => { + Some(( + if host.contains(":") { + host.to_string() + } else { + format!("{host}:42667") + }, + true, false + )) + }, + "wrac" => { + Some(( + if host.contains(":") { + host.to_string() + } else { + format!("{host}:52666") + }, + false, true + )) + }, + "wracs" => { + Some(( + if host.contains(":") { + host.to_string() + } else { + format!("{host}:52667") + }, + true, true + )) + }, + _ => None, + } +} + /// Create RAC connection (also you can just TcpStream::connect) /// /// host - host string, example: "example.com:12345", "example.com" (default port is 42666) @@ -60,11 +115,8 @@ pub fn parse_socks5_url(url: &str) -> Option<(String, Option<(String, String)>)> /// proxy - socks5 proxy (host, (user, pass)) /// wrac - to use wrac protocol pub fn connect(host: &str, ssl: bool, proxy: Option, wrac: bool) -> Result> { - let host = if host.contains(":") { - host.to_string() - } else { - format!("{host}:42666") - }; + let (host, ssl_, wrac_) = parse_rac_url(host).ok_or::>("url parse error".into())?; + let (ssl, wrac) = (ssl_ || ssl, wrac_ || wrac); let stream: Box = if let Some(proxy) = proxy { if let Some((proxy, auth)) = parse_socks5_url(&proxy) {