diff options
Diffstat (limited to 'server/src/data')
-rw-r--r-- | server/src/data/mod.rs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/server/src/data/mod.rs b/server/src/data/mod.rs index dd916a93..7ec0707d 100644 --- a/server/src/data/mod.rs +++ b/server/src/data/mod.rs @@ -69,6 +69,8 @@ pub struct RecipeDecl { #[derive(Debug, Clone, Deserialize)] pub struct MapDecl { + #[serde(default)] + recipes: Option<String>, map: Vec<String>, tiles: HashMap<char, String>, #[serde(default)] @@ -96,7 +98,6 @@ pub struct DemandDecl { #[derive(Debug,Clone, Default)] #[rustfmt::skip] pub struct Serverdata { - pub spec: String, pub initial_map: HashMap<IVec2, (TileIndex, Option<ItemIndex>)>, pub chef_spawn: Vec2, pub customer_spawn: Vec2, @@ -125,8 +126,9 @@ impl DataIndex { } pub async fn read_map(&self, name: &str) -> Result<String> { - if !self.maps.contains_key(name) { - bail!("unknown map: {name:?}"); + // Scary! + if name.contains("..") || name.starts_with("/") || name.contains("//") { + bail!("illegal map path"); } let path = data_dir().join(format!("maps/{name}.yaml")); Ok(read_to_string(path).await?) @@ -138,26 +140,25 @@ impl DataIndex { let path = data_dir().join(format!("recipes/{name}.yaml")); Ok(read_to_string(path).await?) } - - pub async fn generate(&self, spec: String) -> Result<(Gamedata, Serverdata, Entities)> { - let (map, recipes) = spec.split_once("-").unwrap_or((spec.as_str(), "default")); - - let map_in = serde_yml::from_str(&self.read_map(map).await?)?; - let recipes_in = serde_yml::from_str(&self.read_recipes(recipes).await?)?; - - Ok(build_data( - &self.maps, - spec.clone(), - map.to_string(), - map_in, - recipes_in, - )?) + pub async fn generate(&self, map: &str) -> Result<(Gamedata, Serverdata, Entities)> { + let map_in: MapDecl = serde_yml::from_str(&self.read_map(map).await?)?; + let recipes_in = serde_yml::from_str( + &self + .read_recipes( + map_in + .recipes + .as_ref() + .map(|a| a.as_str()) + .unwrap_or("default"), + ) + .await?, + )?; + Ok(build_data(&self.maps, map.to_string(), map_in, recipes_in)?) } } pub fn build_data( maps: &HashMap<String, MapMetadata>, - spec: String, map_name: String, map_in: MapDecl, recipes_in: Vec<RecipeDecl>, @@ -301,7 +302,6 @@ pub fn build_data( tile_names, }, Serverdata { - spec, initial_map, chef_spawn, customer_spawn, |