From b1e9490f55e4f360c249a107dcc5809a663dec42 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sat, 25 Dec 2021 21:49:16 +0100 Subject: add match meta header to logs --- planetwars-localdev/src/match_runner/mod.rs | 37 ++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'planetwars-localdev/src/match_runner/mod.rs') diff --git a/planetwars-localdev/src/match_runner/mod.rs b/planetwars-localdev/src/match_runner/mod.rs index 2715b96..50b7a3b 100644 --- a/planetwars-localdev/src/match_runner/mod.rs +++ b/planetwars-localdev/src/match_runner/mod.rs @@ -3,23 +3,38 @@ mod match_context; mod pw_match; use std::{ + io::Write, path::PathBuf, sync::{Arc, Mutex}, }; use match_context::MatchCtx; use planetwars_rules::PwConfig; +use serde::{Deserialize, Serialize}; use crate::BotConfig; use self::match_context::{EventBus, PlayerHandle}; pub struct MatchConfig { + pub map_name: String, pub map_path: PathBuf, pub log_path: PathBuf, pub players: Vec, } +#[derive(Serialize, Deserialize)] +pub struct MatchMeta { + pub map_name: String, + pub timestamp: chrono::DateTime, + pub players: Vec, +} + +#[derive(Serialize, Deserialize)] +pub struct PlayerInfo { + pub name: String, +} + pub struct MatchBot { pub name: String, pub bot_config: BotConfig, @@ -48,7 +63,27 @@ pub async fn run_match(config: MatchConfig) { (player_id, Box::new(handle) as Box) }) .collect(); - let log_file = std::fs::File::create(config.log_path).expect("could not create log file"); + let mut log_file = std::fs::File::create(config.log_path).expect("could not create log file"); + + // assemble the math meta struct + let match_meta = MatchMeta { + map_name: config.map_name.clone(), + timestamp: chrono::Local::now(), + players: config + .players + .iter() + .map(|bot| PlayerInfo { + name: bot.name.clone(), + }) + .collect(), + }; + write!( + log_file, + "{}\n", + serde_json::to_string(&match_meta).unwrap() + ) + .unwrap(); + let match_ctx = MatchCtx::new(event_bus, players, log_file); let match_state = pw_match::PwMatch::create(match_ctx, pw_config); -- cgit v1.2.3