diff --git a/src/chat.rs b/src/chat.rs index 5acd4ec..8a56bfa 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -225,6 +225,7 @@ fn format_message(ctx: Arc, message: String) -> Option { let message = message .trim_start_matches("(UNREGISTERED)") .trim_start_matches("(UNAUTHORIZED)") + .trim_start_matches("(UNAUTHENTICATED)") .trim() .to_string()+" "; diff --git a/src/proto.rs b/src/proto.rs index 948baf6..6bc2a47 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -22,20 +22,14 @@ pub fn connect(host: &str, ssl: bool) -> Result, Box Result<(), Box> { - stream.write_all(&[0x01])?; - stream.write_all(message.as_bytes())?; + stream.write_all(format!("\x01{message}").as_bytes())?; Ok(()) } pub fn send_message_auth(stream: &mut (impl Read + Write), message: &str) -> Result<(), Box> { let Some((name, message)) = message.split_once("> ") else { return send_message(stream, message) }; - stream.write_all(&[0x02])?; - stream.write_all(name.as_bytes())?; - stream.write_all(b"\n")?; - stream.write_all(name.as_bytes())?; - stream.write_all(b"\n")?; - stream.write_all(message.as_bytes())?; + stream.write_all(format!("\x02{name}\n{name}\n{message}").as_bytes())?; let mut buf = vec![0; 1]; if let Ok(_) = stream.read_exact(&mut buf) { @@ -49,10 +43,7 @@ pub fn send_message_auth(stream: &mut (impl Read + Write), message: &str) -> Res } pub fn register_user(stream: &mut (impl Read + Write), name: &str, password: &str) -> Result<(), Box> { - stream.write_all(&[0x03])?; - stream.write_all(name.as_bytes())?; - stream.write_all(&[b'\n'])?; - stream.write_all(password.as_bytes())?; + stream.write_all(format!("\x03{name}\n{password}").as_bytes())?; Ok(()) }