From c0e43b4a4696bbd38a148fefa82005307fde8191 Mon Sep 17 00:00:00 2001 From: Phuntsok Drak-pa Date: Sun, 25 Mar 2018 16:31:53 +0200 Subject: [PATCH] Fixed request 4.2.2 in server and client --- Rust/src/client.rs | 14 ++++++++++---- Rust/src/server.rs | 6 ++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Rust/src/client.rs b/Rust/src/client.rs index d5230e1..e0f0d82 100644 --- a/Rust/src/client.rs +++ b/Rust/src/client.rs @@ -12,7 +12,7 @@ use self::chrono::Local; /* -0.1 [ ] +0.1 [X] 1.1 [X] 1.2 [ ] 1.3 [X] @@ -29,7 +29,7 @@ use self::chrono::Local; 4.1.1 [X] 4.1.2 [X] 4.2.1 [X] -4.2.2 [-] +4.2.2 [X] */ @@ -259,6 +259,7 @@ fn exchange_with_server(stream: TcpStream) { } msg = String::new(); #[allow(unused_assignments)] + #[allow(unused_assignments)] i = i - 1; } } @@ -296,8 +297,13 @@ fn exchange_with_server(stream: TcpStream) { return Ok("Ok"); } "LIST" => { - println!("{}", ">>>> LIST OF CLIENTS CONNECTED <<<<".bold().yellow()); - for i in 2..spliced_input.len() { + println!( + "{}{}{}", + ">>>> LIST OF CLIENTS CONNECTED (".bold().yellow(), + spliced_input[2], + ") <<<<".bold().yellow() + ); + for i in 3..spliced_input.len() { println!("\t\t{}", spliced_input[i]); } } diff --git a/Rust/src/server.rs b/Rust/src/server.rs index 653572b..9edc66c 100644 --- a/Rust/src/server.rs +++ b/Rust/src/server.rs @@ -31,7 +31,7 @@ use self::chrono::Local; 4.1.1 [X] 4.1.2 [X] 4.2.1 [X] -4.2.2 [-] +4.2.2 [X] */ @@ -100,7 +100,9 @@ fn distribute_message( fn send_clients_name(to: &SocketAddr, lock: &mut MutexGuard) { let mut clients = String::new(); + let mut num_client = 0usize; for (client, entry) in (*lock).iter() { + num_client += 1; clients.push_str(&format!( "{}{} ", &entry.0.trim(), @@ -112,7 +114,7 @@ fn send_clients_name(to: &SocketAddr, lock: &mut MutexGuard) { if client == to { let stream = &entry.1; let mut writer = BufWriter::new(stream); - let mut req = String::from("LIST CLIENTS "); + let mut req = String::from(format!("{}{} ", "LIST CLIENTS ", num_client)); req.push_str(clients); println!( "{time} to {nick}@{addr} : {message}",