From cdfd16f8c47c4ab2986d0957a40af3462e0b6d58 Mon Sep 17 00:00:00 2001 From: MeexReay Date: Sun, 15 Jun 2025 18:16:44 +0300 Subject: [PATCH] server list connection now changes mode --- src/chat/gui.rs | 12 +++++++++--- src/chat/mod.rs | 23 ++++++++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/chat/gui.rs b/src/chat/gui.rs index 06bd4b0..0ae243d 100644 --- a/src/chat/gui.rs +++ b/src/chat/gui.rs @@ -26,8 +26,10 @@ use gtk::{ Justification, Label, ListBox, Orientation, Overlay, Picture, ScrolledWindow, Settings, Window }; +use crate::proto::parse_rac_url; + use super::{config::{default_max_messages, default_update_time, get_config_path, save_config, Config}, -ctx::Context, on_send_message, parse_message, print_message, recv_tick, sanitize_message}; +ctx::Context, on_send_message, parse_message, print_message, recv_tick, sanitize_message, SERVER_LIST}; struct UiModel { chat_box: GtkBox, @@ -408,7 +410,7 @@ fn build_ui(ctx: Arc, app: &Application) -> UiModel { let server_list = ListBox::new(); - for url in ["rac://meex.lol", "rac://meex.lol:11234", "rac://91.192.22.20"] { + for url in SERVER_LIST.iter() { let url = url.to_string(); let label = Label::builder() @@ -422,7 +424,11 @@ fn build_ui(ctx: Arc, app: &Application) -> UiModel { #[weak] ctx, move |_, _, _, _| { let mut config = ctx.config.read().unwrap().clone(); - config.host = url.clone(); + if let Some((_, ssl, wrac)) = parse_rac_url(&url) { + config.host = url.clone(); + config.wrac_enabled = wrac; + config.ssl_enabled = ssl; + } ctx.set_config(&config); save_config(get_config_path(), &config); } diff --git a/src/chat/mod.rs b/src/chat/mod.rs index e7714d4..3a2cd58 100644 --- a/src/chat/mod.rs +++ b/src/chat/mod.rs @@ -15,6 +15,14 @@ use ctx::Context; pub use gui::run_main_loop; +const HELP_MESSAGE: &str = "Help message: +/help - show help message +/register password - register user +/login password - login user +/clear n - send empty message n times +/spam n text - send message with text n times +/ping - check server ping"; + lazy_static! { static ref ANSI_REGEX: Regex = Regex::new(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])").unwrap(); static ref CONTROL_CHARS_REGEX: Regex = Regex::new(r"[\x00-\x1F\x7F]").unwrap(); @@ -28,6 +36,12 @@ lazy_static! { (Regex::new(r"\u{00B0}\u{0298}<(.*?)> (.*)").unwrap(), "magenta".to_string()), // Mefidroniy (Regex::new(r"<(.*?)> (.*)").unwrap(), "cyan".to_string()), // clRAC ]; + + pub static ref SERVER_LIST: Vec = vec![ + "rac://meex.lol".to_string(), + "rac://meex.lol:11234".to_string(), + "rac://91.192.22.20".to_string() + ]; } @@ -35,15 +49,6 @@ pub mod gui; pub mod config; pub mod ctx; - -const HELP_MESSAGE: &str = "Help message: -/help - show help message -/register password - register user -/login password - login user -/clear n - send empty message n times -/spam n text - send message with text n times -/ping - check server ping"; - pub fn sanitize_text(input: &str) -> String { let without_ansi = ANSI_REGEX.replace_all(input, ""); let cleaned_text = CONTROL_CHARS_REGEX.replace_all(&without_ansi, "");