diff --git a/README.md b/README.md index c5dea05..1bfc718 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ better RAC client - plays sound when users receive your messages - coloring usernames by their clients (CRAB, clRAC, Mefidroniy, etc) - configurable message format -- RACv1.99.x compatible +- RACv1.99.x and RACv2.0 compatible ![image](https://github.com/user-attachments/assets/a2858662-50f1-4554-949c-f55addf48fcc) @@ -71,8 +71,9 @@ max_messages: 100 # chat messages limit ## see also -- [RAC protocol (v1.99.2)](https://gitea.bedohswe.eu.org/pixtaded/crab#rac-protocol) +- [RAC protocol (v2.0)](https://gitea.bedohswe.eu.org/pixtaded/crab#rac-protocol) - [CRAB - client & server for RAC](https://gitea.bedohswe.eu.org/pixtaded/crab) +- [Mefidroniy - client for RAC](https://github.com/OctoBanon-Main/mefedroniy-client) - [Colored usernames](https://github.com/MeexReay/bRAC/blob/main/docs/colored_usernames.md) -- [AlmatyD - server for RAC](https://gitea.bedohswe.eu.org/bedohswe/almatyd) +- [AlmatyD - server for RACv1.0](https://gitea.bedohswe.eu.org/bedohswe/almatyd) - [RAC protocol (v1.0)](https://bedohswe.eu.org/text/rac/protocol.md.html) diff --git a/docs/rac_protocol.md b/docs/rac_protocol.md deleted file mode 100644 index 4d94406..0000000 --- a/docs/rac_protocol.md +++ /dev/null @@ -1 +0,0 @@ -todo \ No newline at end of file diff --git a/src/chat.rs b/src/chat.rs index 024658b..83e7e38 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -161,15 +161,15 @@ pub fn print_console(ctx: Arc, messages: Vec, input: &str) -> R fn prepare_message(context: Arc, message: &str) -> String { - format!("{}{}{}", + format!("{}{}{}\r", if !context.disable_hiding_ip { "\r\x07" } else { "" }, message, - if !context.disable_hiding_ip && message.chars().count() < 39 { - " ".repeat(39-message.chars().count()) + if !context.disable_hiding_ip && message.chars().count() < 53 { + " ".repeat(53-message.chars().count()) } else { String::new() } @@ -300,12 +300,12 @@ fn poll_events(ctx: Arc) -> Result<(), Box> { if message.starts_with("/") && !ctx.disable_commands { on_command(ctx.clone(), &message)?; } else { - if let Some(password) = &ctx.auth_password { - send_message_auth(&ctx.host, &ctx.name, password, &message)?; + let message = prepare_message(ctx.clone(), &ctx.message_format + .replace("{name}", &ctx.name) + .replace("{text}", &message)); + if ctx.auth { + send_message_auth(&ctx.host, &message)?; } else { - let message = ctx.message_format - .replace("{name}", &ctx.name) - .replace("{text}", &message); send_message(&ctx.host, &message)?; } } diff --git a/src/config.rs b/src/config.rs index a767860..457a05f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -174,8 +174,8 @@ pub struct Args { pub configure: bool, /// Authentication password - #[arg(short='a', long, value_name="PASSWORD")] - pub auth: Option, + #[arg(short='a', long)] + pub auth: bool, } pub struct Context { @@ -191,7 +191,7 @@ pub struct Context { pub max_messages: usize, pub enable_ip_viewing: bool, pub scroll: Arc, - pub auth_password: Option, + pub auth: bool, } impl Context { @@ -209,7 +209,7 @@ impl Context { max_messages: config.max_messages, enable_ip_viewing: args.enable_users_ip_viewing || config.enable_ip_viewing, scroll: Arc::new(AtomicUsize::new(0)), - auth_password: args.auth.clone() + auth: args.auth } } } \ No newline at end of file diff --git a/src/proto.rs b/src/proto.rs index b314814..8bdd7c1 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -9,37 +9,31 @@ pub fn send_message(host: &str, message: &str) -> Result<(), Box> { Ok(()) } -pub fn send_message_auth(host: &str, name: &str, password: &str, message: &str) -> Result<(), Box> { +pub fn send_message_auth(host: &str, message: &str) -> Result<(), Box> { + register_user(host, message, message)?; let mut stream = TcpStream::connect(host)?; stream.write_all(&[0x02])?; - stream.write_all(name.as_bytes())?; - stream.write_all(&[b'\n'])?; - stream.write_all(password.as_bytes())?; + stream.write_all(message.as_bytes())?; stream.write_all(&[b'\n'])?; stream.write_all(message.as_bytes())?; + stream.write_all(b"\n\r ")?; let mut buf = vec![0; 1]; - stream.read_exact(&mut buf)?; - if buf[0] == 0x01 { - register_user(host, name, password)?; - send_message_auth(host, name, password, message)? - } else if buf[0] == 0x02 { - println!("Password is incorrect"); - panic!() + if let Ok(_) = stream.read_exact(&mut buf) { + if buf[0] == 0x02 { + let message = format!("\x1f{message}"); + register_user(host, &message, &message)?; + send_message_auth(host, &message)?; + } } Ok(()) } pub fn register_user(host: &str, name: &str, password: &str) -> Result<(), Box> { let mut stream = TcpStream::connect(host)?; - stream.write_all(&[0x00])?; + stream.write_all(&[0x03])?; stream.write_all(name.as_bytes())?; stream.write_all(&[b'\n'])?; stream.write_all(password.as_bytes())?; - // let mut buf = vec![0; 1]; - // stream.read(&mut buf)?; - // if buf[0] == 0x01 { - // // похуй - // } Ok(()) }