diff options
Diffstat (limited to 'server')
| -rw-r--r-- | server/src/commands.rs | 5 | ||||
| -rw-r--r-- | server/src/data/mod.rs | 57 | ||||
| -rw-r--r-- | server/src/server.rs | 10 | 
3 files changed, 35 insertions, 37 deletions
| diff --git a/server/src/commands.rs b/server/src/commands.rs index 6fd95eac..9d34c28c 100644 --- a/server/src/commands.rs +++ b/server/src/commands.rs @@ -35,8 +35,7 @@ enum Command {          #[arg(default_value = "junior")]          spec: String,          /// Duration in seconds -        #[arg(default_value = "420")] -        timer: u64, +        timer: Option<u64>,      },      /// Shows the best entries of the scoreboard for this map.      #[clap(alias = "top5")] @@ -146,7 +145,7 @@ impl Server {                          .ok();                  }                  let data = self.index.generate(&spec).await?; -                self.load(data, Some(Duration::from_secs(timer))); +                self.load(data, timer.map(Duration::from_secs));              }              Command::End => {                  self.tx diff --git a/server/src/data/mod.rs b/server/src/data/mod.rs index 91b32a42..39684c6f 100644 --- a/server/src/data/mod.rs +++ b/server/src/data/mod.rs @@ -34,6 +34,7 @@ use std::{      path::PathBuf,      str::FromStr,      sync::{Mutex, RwLock}, +    time::Duration,  };  use tokio::fs::read_to_string; @@ -48,44 +49,34 @@ pub enum RecipeDeclAction {      Demand,  } +#[rustfmt::skip]  #[derive(Debug, Clone, Deserialize, Serialize)]  pub struct RecipeDecl { -    #[serde(default)] -    tile: Option<String>, -    #[serde(default)] -    inputs: Vec<String>, -    #[serde(default)] -    outputs: Vec<String>, -    #[serde(default)] -    action: RecipeDeclAction, -    #[serde(default)] -    warn: bool, -    #[serde(default)] -    revert_duration: Option<f32>, -    #[serde(default)] -    duration: Option<f32>, -    #[serde(default)] -    points: Option<i64>, +    #[serde(default)] tile: Option<String>, +    #[serde(default)] inputs: Vec<String>, +    #[serde(default)] outputs: Vec<String>, +    #[serde(default)] action: RecipeDeclAction, +    #[serde(default)] warn: bool, +    #[serde(default)] revert_duration: Option<f32>, +    #[serde(default)] duration: Option<f32>, +    #[serde(default)] points: Option<i64>,  } +#[rustfmt::skip]  #[derive(Debug, Clone, Deserialize)]  pub struct MapDecl { -    #[serde(default)] -    recipes: Option<String>, +    #[serde(default)] recipes: Option<String>,      map: Vec<String>,      tiles: HashMap<char, String>, -    #[serde(default)] -    items: HashMap<char, String>, +    #[serde(default)] items: HashMap<char, String>,      collider: Vec<String>,      walkable: Vec<String>,      chef_spawn: char,      customer_spawn: char, -    #[serde(default)] -    entities: Vec<EntityDecl>, -    #[serde(default)] -    tile_entities: HashMap<char, EntityDecl>, -    #[serde(default)] -    score_baseline: i64, +    #[serde(default)] entities: Vec<EntityDecl>, +    #[serde(default)] tile_entities: HashMap<char, EntityDecl>, +    #[serde(default)] score_baseline: i64, +    #[serde(default)] default_timer: Option<u64>,  }  #[derive(Debug, Clone, Serialize, Deserialize)] @@ -103,6 +94,7 @@ pub struct Serverdata {      pub chef_spawn: Vec2,      pub customer_spawn: Vec2,      pub score_baseline: i64, +    pub default_timer: Option<Duration>  }  #[derive(Debug, Deserialize, Default)] @@ -150,11 +142,7 @@ impl DataIndex {          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_deref() -                        .unwrap_or("default"), -                ) +                .read_recipes(map_in.recipes.as_deref().unwrap_or("default"))                  .await?,          )?;          build_data(&self.maps, map.to_string(), map_in, recipes_in) @@ -293,6 +281,12 @@ pub fn build_data(          .map(|i| !map_in.collider.contains(i) && !map_in.walkable.contains(i))          .collect(); +    let default_timer = if map_name.ends_with("lobby") { +        None +    } else { +        Some(Duration::from_secs(map_in.default_timer.unwrap_or(420))) +    }; +      Ok((          Gamedata {              bot_algos, @@ -309,6 +303,7 @@ pub fn build_data(              initial_map,              chef_spawn,              customer_spawn, +            default_timer,              score_baseline: map_in.score_baseline,          },          entities, diff --git a/server/src/server.rs b/server/src/server.rs index 9ee98b97..5efddaa1 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -336,8 +336,12 @@ impl Server {                  load_map: &mut None,              });          } -        self.game -            .load(gamedata, &serverdata, timer, &mut self.packet_out); +        self.game.load( +            gamedata, +            &serverdata, +            timer.or(serverdata.default_timer), +            &mut self.packet_out, +        );          self.gamedata_index.update(&self.game.data);          self.data = serverdata.into();          self.entities = entities; @@ -697,7 +701,7 @@ impl Server {          });          if let Some(map) = load_map { -            return Some((map, Some(Duration::from_secs(300)))); +            return Some((map, None));          }          while let Some(p) = self.packet_loopback.pop_front() { | 
