modified client to multiple params instead of map

This commit is contained in:
michael-bailey 2021-03-18 17:03:15 +00:00
commit 30d9e5ba2d
3 changed files with 18 additions and 6 deletions

View File

@ -80,16 +80,22 @@ pub struct Client {
// client funciton implmentations
impl IClient<ClientMessage> for Client {
fn new(map: HashMap<String, String>, stream: TcpStream, server_channel: Sender<ServerMessages> ) -> Arc<Client> {
fn new(
uuid: String,
username: String,
address: String,
stream: TcpStream,
server_channel: Sender<ServerMessages>
) -> Arc<Client> {
let (sender, receiver) = unbounded();
let out_stream = stream.try_clone().unwrap();
let in_stream = stream.try_clone().unwrap();
Arc::new(Client {
username: map.get(&"name".to_string()).unwrap().clone(),
uuid: Uuid::parse_str(map.get(&"uuid".to_string()).unwrap().as_str()).expect("invalid id"),
address: map.get(&"host".to_string()).unwrap().clone(),
username,
uuid: Uuid::parse_str(&uuid).expect("invalid id"),
address,
server_channel: Some(server_channel),

View File

@ -17,7 +17,13 @@ use crate::lib::server::ServerMessages;
/// - send_msg: sends a event message to the client
/// - recv_msg: used by the client to receive and process event messages
pub trait IClient<TClientMessage> {
fn new(map: HashMap<String, String>, stream: TcpStream, server_channel: Sender<ServerMessages> ) -> Arc<Self>;
fn new(
uuid: String,
username: String,
address: String,
stream: TcpStream,
server_channel: Sender<ServerMessages>
) -> Arc<Self>;
fn send(&self, bytes: Vec<u8>) -> Result<(), &str>;
fn recv(&self) -> Option<Vec<u8>>;

View File

@ -89,7 +89,7 @@ impl ICooperative for NetworkManager {
writer.flush().unwrap();
}
NetworkSockIn::Connect { uuid, username, address } => {
println!("Connection requested")
self.server_channel.send().unwrap_or_default()
}
}
}