added clientInfo command
This commit is contained in:
parent
2d95678569
commit
9a09df6b25
|
|
@ -78,6 +78,7 @@ fn match_command(data: &Vec<String>) -> Commands{
|
|||
"!connect:" => Commands::Connect,
|
||||
"!disconnect:" => Commands::Disconnect,
|
||||
"!clientUpdate:" => Commands::ClientUpdate,
|
||||
"!clientInfo:" => Commands::ClientInfo,
|
||||
"!client:" => Commands::Client,
|
||||
"!test:" => Commands::Test,
|
||||
"!message:" => Commands::Message,
|
||||
|
|
|
|||
|
|
@ -5,15 +5,11 @@ mod error;
|
|||
mod connect;
|
||||
mod disconnect;
|
||||
mod client_update;
|
||||
mod client_info;
|
||||
mod client;
|
||||
mod test;
|
||||
mod message;
|
||||
|
||||
//use connect::Connect;
|
||||
//use crate::protocols::commands::connect::Connect;
|
||||
//use crate::protocols::commands::client_update::ClientUpdate;
|
||||
//use crate::protocols::commands::client::ClientQ;
|
||||
|
||||
use crate::client_management::client_profile::Client;
|
||||
|
||||
use std::sync::Mutex;
|
||||
|
|
@ -30,6 +26,7 @@ pub enum Commands{
|
|||
Connect,
|
||||
Disconnect,
|
||||
ClientUpdate,
|
||||
ClientInfo,
|
||||
Client,
|
||||
Test,
|
||||
Message,
|
||||
|
|
@ -48,17 +45,24 @@ impl Commands{
|
|||
Commands::Error => {
|
||||
}
|
||||
Commands::Connect => {
|
||||
let message = String::from("!success:");
|
||||
Commands::transmit_data(stream, &message);
|
||||
|
||||
connect::add_new_client(clients_ref, &data[1], &data[2], address);
|
||||
}
|
||||
Commands::Disconnect => {
|
||||
|
||||
}
|
||||
Commands::ClientUpdate => {
|
||||
let address = client_update::get_client_address(clients_ref, &data[1]);
|
||||
Commands::transmit_data(stream, &address);
|
||||
}
|
||||
Commands::ClientInfo => {
|
||||
let message = String::from("!success:");
|
||||
Commands::transmit_data(stream, &message);
|
||||
|
||||
let requested_address = client_info::get_client_address(clients_ref, &data[1]);
|
||||
Commands::transmit_data(stream, &requested_address);
|
||||
}
|
||||
Commands::Client => {
|
||||
let address = client::retrieve_requested_clients(clients_ref, &data[1]);
|
||||
Commands::transmit_data(stream, &address);
|
||||
}
|
||||
Commands::Test => {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,22 +3,3 @@ use crate::client_management::client_profile::Client;
|
|||
use std::sync::Mutex;
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn retrieve_requested_clients(clients_ref: &Arc<Mutex<HashMap<String,Client>>>, uuid: &String) -> String{
|
||||
//let address = String::new();
|
||||
//if data[1].starts_with("uuid:"){
|
||||
get_client_address(clients_ref, uuid)
|
||||
//}else if data[1].starts_with("name:"){
|
||||
// address = ClientQ::get_clients_addresses();
|
||||
//}
|
||||
}
|
||||
|
||||
fn get_client_address(clients_ref: &Arc<Mutex<HashMap<String,Client>>>, uuid: &String) -> String{
|
||||
// may not need to lock hashmap as it may cause difficulties later on
|
||||
let clients_hashmap = clients_ref.lock().unwrap();
|
||||
let client = clients_hashmap.get(uuid);
|
||||
match client{
|
||||
Some(data) => data.get_address().to_string(),
|
||||
None => String::from("client not online"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
use crate::client_management::client_profile::Client;
|
||||
|
||||
use std::sync::Mutex;
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn get_client_address(clients_ref: &Arc<Mutex<HashMap<String,Client>>>, uuid: &String) -> String{
|
||||
// may not need to lock hashmap as it may cause difficulties later on
|
||||
let clients_hashmap = clients_ref.lock().unwrap();
|
||||
let client = clients_hashmap.get(uuid);
|
||||
match client{
|
||||
Some(data) => data.get_address().to_string(),
|
||||
None => String::from("client not online"),
|
||||
}
|
||||
}
|
||||
|
|
@ -3,13 +3,3 @@ use crate::client_management::client_profile::Client;
|
|||
use std::sync::Mutex;
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn get_client_address(clients_ref: &Arc<Mutex<HashMap<String,Client>>>, uuid: &String) -> String{
|
||||
// may not need to lock hashmap as it may cause difficulties later on
|
||||
let clients_hashmap = clients_ref.lock().unwrap();
|
||||
let client = clients_hashmap.get(uuid);
|
||||
match client{
|
||||
Some(data) => data.get_address().to_string(),
|
||||
None => String::from("client not online"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue