added fetch all clients system

This commit is contained in:
Mitchell 2020-06-07 20:16:45 +01:00
parent 612c25c392
commit 830e5c9d64
6 changed files with 28 additions and 11 deletions

View File

@ -8,3 +8,9 @@ edition = "2018"
[dependencies]
regex = "1"
[profile.dev]
opt-level = 0
[profile.release]
opt-level = 3

View File

@ -43,10 +43,7 @@ impl ThreadPool{
}
}
pub fn execute<F>(&self, f: F)
where
F: FnOnce() + Send + 'static
{
pub fn execute<F>(&self, f: F) where F: FnOnce() + Send + 'static {
let job = Box::new(f);
self.sender.send(Message::NewJob(job)).unwrap();

View File

@ -8,6 +8,7 @@
* If no success, request ip from server to double check if theyre online, if ip match, assume
* theyre offline. If no response from server assume some error has occured or sender is offline.
* Save messages to be sent and check every few mins to see if they are online.
*
*/
mod client_management;
@ -30,9 +31,6 @@ use regex::Regex;
fn main(){
let listener = TcpListener::bind("127.0.0.1:6001").unwrap();
let pool = ThreadPool::new(10);
/*
* Always dedicate 1/4 size of the connected users for updating clients
*/
let connected_clients = Arc::new(Mutex::new(HashMap::new()));
loop{

View File

@ -57,6 +57,17 @@ impl Commands{
disconnect::remove_client(clients_ref, &data[1]);
}
Commands::ClientUpdate => {
let message = String::from("!success:");
Commands::transmit_data(&stream, &message);
let clients_hashmap = clients_ref.lock().unwrap();
for (key, value) in clients_hashmap.iter(){
let formatted_data = client_update::format_client_data(&key, &value);
Commands::transmit_data(&stream, &formatted_data);
}
let final_message = String::from("!finished:");
Commands::transmit_data(&stream, &final_message);
}
Commands::ClientInfo => {
let message = String::from("!success:");

View File

@ -1,5 +1,10 @@
use crate::client_management::client_profile::Client;
use std::sync::Mutex;
use std::sync::Arc;
use std::collections::HashMap;
// send a list of all clients.
// client !clientupdate:
// server !client: name:"vobo" uuid:24653526-23464562-46346-3563563 host:"127.0.0.1"
// server !client: name:"bovo" uuid:24643526-23464562-46346-3563563 host:"127.0.0.1"
pub fn format_client_data(uuid: &String, client: &Client) -> String{
["!client: ",client.get_username(), uuid, " host:\"", client.get_address(), "\""].concat()
}

View File

@ -17,4 +17,4 @@ fn create_client_profile(username: &String, uuid: &String, address: &String) ->
username: username.to_string(),
address: address.to_string(),
}
}
}