aboutsummaryrefslogtreecommitdiff
path: root/server/src/entity
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-23 13:36:45 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-23 13:36:45 +0200
commit35a16fd090a49aca15c942b769d8c1f16dd2d33f (patch)
tree8029b2a5c58fb28ab53aab65dc7b62620ff8a9c6 /server/src/entity
parent4899cad95fd2abe99d2057fb9c5425c18d8f2bcb (diff)
downloadhurrycurry-35a16fd090a49aca15c942b769d8c1f16dd2d33f.tar
hurrycurry-35a16fd090a49aca15c942b769d8c1f16dd2d33f.tar.bz2
hurrycurry-35a16fd090a49aca15c942b769d8c1f16dd2d33f.tar.zst
check if demands are emtpy to prevent crash
Diffstat (limited to 'server/src/entity')
-rw-r--r--server/src/entity/customers/mod.rs11
-rw-r--r--server/src/entity/mod.rs2
2 files changed, 8 insertions, 5 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(),
- }
+ })
}
}
diff --git a/server/src/entity/mod.rs b/server/src/entity/mod.rs
index ec5ec744..95172ed0 100644
--- a/server/src/entity/mod.rs
+++ b/server/src/entity/mod.rs
@@ -108,7 +108,7 @@ pub fn construct_entity(
.filter(|(_, (tile, _))| *tile == chair)
.map(|(e, _)| (*e, true))
.collect();
- Entity::Customers(Customers::new(chairs, demands))
+ Entity::Customers(Customers::new(chairs, demands)?)
}
})
}