diff options
| author | metamuffin <metamuffin@disroot.org> | 2024-07-23 13:36:45 +0200 | 
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2024-07-23 13:36:45 +0200 | 
| commit | 35a16fd090a49aca15c942b769d8c1f16dd2d33f (patch) | |
| tree | 8029b2a5c58fb28ab53aab65dc7b62620ff8a9c6 /server/src/entity/customers | |
| parent | 4899cad95fd2abe99d2057fb9c5425c18d8f2bcb (diff) | |
| download | hurrycurry-35a16fd090a49aca15c942b769d8c1f16dd2d33f.tar hurrycurry-35a16fd090a49aca15c942b769d8c1f16dd2d33f.tar.bz2 hurrycurry-35a16fd090a49aca15c942b769d8c1f16dd2d33f.tar.zst | |
check if demands are emtpy to prevent crash
Diffstat (limited to 'server/src/entity/customers')
| -rw-r--r-- | server/src/entity/customers/mod.rs | 11 | 
1 files changed, 7 insertions, 4 deletions
| diff --git a/server/src/entity/customers/mod.rs b/server/src/entity/customers/mod.rs index 06f99686..b5b9fa42 100644 --- a/server/src/entity/customers/mod.rs +++ b/server/src/entity/customers/mod.rs @@ -20,7 +20,7 @@ mod pathfinding;  use super::EntityT;  use crate::{data::Demand, game::Game}; -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, bail, Result};  use fake::{faker, Fake};  use hurrycurry_protocol::{glam::IVec2, DemandIndex, Message, PacketC, PacketS, PlayerID};  use log::{info, warn}; @@ -61,15 +61,18 @@ enum CustomerState {  }  impl Customers { -    pub fn new(chairs: HashMap<IVec2, bool>, demands: Vec<Demand>) -> Self { -        Self { +    pub fn new(chairs: HashMap<IVec2, bool>, demands: Vec<Demand>) -> Result<Self> { +        if demands.is_empty() { +            bail!("one or more demands required for customers entity") +        } +        Ok(Self {              chairs,              customer_id_counter: PlayerID(0),              customers: Default::default(),              demands,              spawn_cooldown: 0.,              cpackets: VecDeque::new(), -        } +        })      }  } | 
