diff options
Diffstat (limited to 'planetwars-server/src/modules/matches.rs')
-rw-r--r-- | planetwars-server/src/modules/matches.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/planetwars-server/src/modules/matches.rs b/planetwars-server/src/modules/matches.rs index 4f538ed..ecc7976 100644 --- a/planetwars-server/src/modules/matches.rs +++ b/planetwars-server/src/modules/matches.rs @@ -7,6 +7,7 @@ use tokio::task::JoinHandle; use crate::{ db::{ self, + maps::Map, matches::{MatchData, MatchResult}, }, util::gen_alphanumeric, @@ -17,6 +18,11 @@ pub struct RunMatch { log_file_name: String, players: Vec<MatchPlayer>, config: Arc<GlobalConfig>, + is_public: bool, + // Map is mandatory for now. + // It would be nice to allow "anonymous" (eg. randomly generated) maps + // in the future, too. + map: Map, } pub enum MatchPlayer { @@ -30,19 +36,27 @@ pub enum MatchPlayer { } impl RunMatch { - pub fn from_players(config: Arc<GlobalConfig>, players: Vec<MatchPlayer>) -> Self { + // TODO: create a MatchParams struct + pub fn new( + config: Arc<GlobalConfig>, + is_public: bool, + map: Map, + players: Vec<MatchPlayer>, + ) -> Self { let log_file_name = format!("{}.log", gen_alphanumeric(16)); RunMatch { config, log_file_name, players, + is_public, + map, } } fn into_runner_config(self) -> runner::MatchConfig { runner::MatchConfig { - map_path: PathBuf::from(&self.config.maps_directory).join("hex.json"), - map_name: "hex".to_string(), + map_path: PathBuf::from(&self.config.maps_directory).join(self.map.file_path), + map_name: self.map.name, log_path: PathBuf::from(&self.config.match_logs_directory).join(&self.log_file_name), players: self .players @@ -80,6 +94,8 @@ impl RunMatch { let new_match_data = db::matches::NewMatch { state: db::matches::MatchState::Playing, log_path: &self.log_file_name, + is_public: self.is_public, + map_id: Some(self.map.id), }; let new_match_players = self .players |