diff options
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/client.rs | 2 | ||||
-rw-r--r-- | src/bin/server.rs | 21 |
2 files changed, 18 insertions, 5 deletions
diff --git a/src/bin/client.rs b/src/bin/client.rs index 517076f..cbc7302 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -108,8 +108,8 @@ fn main() { ModuleType::Mining => client_mining(stream, buff_r), ModuleType::Engines => client_engines(stream, buff_r), ModuleType::Refinery => client_refinery(stream, buff_r), + ModuleType::Navigation => client_navigation(stream, buff_r), ModuleType::Tractorbeam => client_tractorbeam(stream, buff_r), ModuleType::Construction => client_construction(stream, buff_r), - ModuleType::Navigation => client_navigation(name, stream, buff_r), } } diff --git a/src/bin/server.rs b/src/bin/server.rs index 0429224..62da029 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -1,6 +1,7 @@ extern crate space; use std::collections::HashMap; +use std::io::Write; use std::net::TcpListener; use std::thread::sleep; use std::time::Duration; @@ -8,7 +9,7 @@ use std::time::Duration; use space::constants; use space::mass::Mass; use space::math::rand_name; -use space::server::connection::ServerConnection; +use space::server_connection::ServerConnection; fn populate() -> HashMap<String, Mass> { let mut masses: HashMap<String, Mass> = HashMap::new(); @@ -42,11 +43,23 @@ fn main() { } _ => { for connection in &mut connections { - connection.process(&mut masses); + if connection.open { + let mut ship = masses.remove(&connection.name).unwrap(); + + let send = ship.get_client_data(connection.module_type.clone(), &masses); + connection.open = connection.stream.write(send.as_bytes()).is_ok(); + + let recv = connection.receive(); + ship.give_received_data(connection.module_type.clone(), recv, &masses); + + masses.insert(connection.name.clone(), ship); + } } - for mass in masses.values_mut() { - mass.process(); + for key in masses.clone().keys() { + let mut mass = masses.remove(key).unwrap(); + mass.process(&mut masses); + masses.insert(key.to_string(), mass); } sleep(Duration::from_millis(constants::SLEEP_DURATION)); |