diff options
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/construction.rs | 11 | ||||
-rw-r--r-- | src/server/engines.rs | 19 | ||||
-rw-r--r-- | src/server/mining.rs | 31 | ||||
-rw-r--r-- | src/server/navigation.rs | 18 | ||||
-rw-r--r-- | src/server/refinery.rs | 10 |
5 files changed, 37 insertions, 52 deletions
diff --git a/src/server/construction.rs b/src/server/construction.rs index 0eb2179..94a6b0f 100644 --- a/src/server/construction.rs +++ b/src/server/construction.rs @@ -32,6 +32,7 @@ impl ServerConnection { } if construction_data.status == ConstructionStatus::Constructed { + println!("inserted"); construction.take(); masses.insert("Station".to_string(), Mass::new_station(ModuleType::Refinery, ship_clone.position, ship_clone.velocity)); } @@ -42,14 +43,13 @@ impl ServerConnection { fn txrx_construction(&mut self, construction_data : &ConstructionData) -> bool { let send = serde_json::to_string(construction_data).unwrap() + "\n"; - match self.stream.write(send.as_bytes()) { - Err(_error) => self.open = false, - _ => (), + if let Err(_err) = self.stream.write(send.as_bytes()) { + self.open = false; } let mut recv = String::new(); - match self.buff_r.read_line(&mut recv) { - Ok(result) => match recv.as_bytes() { + if let Ok(result) = self.buff_r.read_line(&mut recv) { + match recv.as_bytes() { b"c\n" => { if construction_data.has_refined { return true @@ -61,7 +61,6 @@ impl ServerConnection { } }, } - _ => (), } false diff --git a/src/server/engines.rs b/src/server/engines.rs index 2c96920..c0d4ad5 100644 --- a/src/server/engines.rs +++ b/src/server/engines.rs @@ -20,24 +20,21 @@ impl ServerConnection { let targeted = navigation.status == NavigationStatus::Targeted; let send = serde_json::to_string(&targeted).unwrap() + "\n"; - match self.stream.write(send.as_bytes()) { - Ok(_result) => (), - Err(_error) => self.open = false, + if let Err(_err) = self.stream.write(send.as_bytes()) { + self.open = false; } let target = match navigation.target_name { Some(name) => masses.get(&name), None => None, }; + let mut recv = String::new(); - match self.buff_r.read_line(&mut recv) { - Ok(result) => { - engines.give_client_data(&ship_clone, target, recv); - if result == 0 { - self.open = false; - } - }, - Err(_error) => (), + if let Ok(result) = self.buff_r.read_line(&mut recv) { + engines.give_client_data(&ship_clone, target, recv); + if result == 0 { + self.open = false; + } } } diff --git a/src/server/mining.rs b/src/server/mining.rs index 115c034..bfe9223 100644 --- a/src/server/mining.rs +++ b/src/server/mining.rs @@ -42,26 +42,19 @@ impl ServerConnection { else { if mining.status == MiningStatus::Mined { mining.take(); - match navigation.target_name.clone() { - Some(name) => { - let target = masses.get_mut(&name).unwrap(); - item = target.take("Mineral"); - } - _ => (), + if let Some(name) = navigation.target_name.clone() { + let target = masses.get_mut(&name).unwrap(); + item = target.take("Mineral"); } } } } - match item { - Some(item) => match ship.give(item.clone()) { - false => { - let mass = Mass::new_item(item.clone(), ship.position, ship.velocity); - masses.insert(item.name.clone(), mass); - } - true => (), + if let Some(item) = item { + if !ship.give(item.clone()) { + let mass = Mass::new_item(item.clone(), ship.position, ship.velocity); + masses.insert(item.name.clone(), mass); } - None => (), } masses.insert(self.name.clone(), ship); @@ -69,14 +62,13 @@ impl ServerConnection { fn txrx_mining(&mut self, mining_data : &MiningData) -> bool { let send = serde_json::to_string(mining_data).unwrap() + "\n"; - match self.stream.write(send.as_bytes()) { - Err(_error) => self.open = false, - _ => (), + if let Err(_err) = self.stream.write(send.as_bytes()) { + self.open = false; } let mut recv = String::new(); - match self.buff_r.read_line(&mut recv) { - Ok(result) => match recv.as_bytes() { + if let Ok(result) = self.buff_r.read_line(&mut recv) { + match recv.as_bytes() { b"F\n" => { if mining_data.is_within_range { return true; @@ -88,7 +80,6 @@ impl ServerConnection { } }, } - _ => (), } false } diff --git a/src/server/navigation.rs b/src/server/navigation.rs index 461a2b8..3eaaa8d 100644 --- a/src/server/navigation.rs +++ b/src/server/navigation.rs @@ -24,18 +24,18 @@ impl ServerConnection { if self.open { let send = serde_json::to_string(&within_range).unwrap() + "\n"; - match self.stream.write(send.as_bytes()) { - Ok(_result) => (), - Err(_error) => self.open = false, + if let Err(_err) = self.stream.write(send.as_bytes()) { + self.open = false; }; let mut recv = String::new(); - match self.buff_r.read_line(&mut recv) { - Ok(_result) => (), - Err(_error) => (), - } - if !recv.is_empty() { - navigation.give_target(recv.replace("\n", "")); + if let Ok(result) = self.buff_r.read_line(&mut recv) { + if result == 0 { + self.open = false; + } + if !recv.is_empty() { + navigation.give_target(recv.replace("\n", "")); + } } } } diff --git a/src/server/refinery.rs b/src/server/refinery.rs index 1f7628f..eb82bb2 100644 --- a/src/server/refinery.rs +++ b/src/server/refinery.rs @@ -55,14 +55,13 @@ impl ServerConnection { fn txrx_refinery(&mut self, refinery_data : &RefineryData) -> bool { let send = serde_json::to_string(refinery_data).unwrap() + "\n"; - match self.stream.write(send.as_bytes()) { - Err(_error) => self.open = false, - _ => (), + if let Err(_err) = self.stream.write(send.as_bytes()) { + self.open = false; } let mut recv = String::new(); - match self.buff_r.read_line(&mut recv) { - Ok(result) => match recv.as_bytes() { + if let Ok(result) = self.buff_r.read_line(&mut recv) { + match recv.as_bytes() { b"R\n" => { if refinery_data.has_minerals { return true @@ -74,7 +73,6 @@ impl ServerConnection { } }, } - _ => (), } false |