From e26f13c8bba24e6f966888d5909f2803665c55a0 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Fri, 26 Aug 2022 19:21:30 +0200 Subject: add maps to matches api --- planetwars-server/src/routes/demo.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'planetwars-server/src/routes') diff --git a/planetwars-server/src/routes/demo.rs b/planetwars-server/src/routes/demo.rs index 99b62d6..1ec8825 100644 --- a/planetwars-server/src/routes/demo.rs +++ b/planetwars-server/src/routes/demo.rs @@ -14,12 +14,13 @@ use serde::{Deserialize, Serialize}; use super::matches::ApiMatch; const DEFAULT_OPPONENT_NAME: &str = "simplebot"; +const DEFAULT_MAP_NAME: &str = "hex"; #[derive(Serialize, Deserialize, Debug)] pub struct SubmitBotParams { pub code: String, - // TODO: would it be better to pass an ID here? pub opponent_name: Option, + pub map_name: Option, } #[derive(Serialize, Deserialize)] @@ -40,17 +41,24 @@ pub async fn submit_bot( .opponent_name .unwrap_or_else(|| DEFAULT_OPPONENT_NAME.to_string()); + let map_name = params + .map_name + .unwrap_or_else(|| DEFAULT_MAP_NAME.to_string()); + let (opponent_bot, opponent_bot_version) = db::bots::find_bot_with_version_by_name(&opponent_name, &conn) .map_err(|_| StatusCode::BAD_REQUEST)?; + let map = db::maps::find_map_by_name(&map_name, &conn).map_err(|_| StatusCode::BAD_REQUEST)?; + let player_bot_version = save_code_string(¶ms.code, None, &conn, &config) // TODO: can we recover from this? .expect("could not save bot code"); - let run_match = RunMatch::from_players( + let run_match = RunMatch::new( config, false, + map.clone(), vec![ MatchPlayer::BotVersion { bot: None, @@ -82,8 +90,7 @@ pub async fn submit_bot( bot: Some(opponent_bot), }, ], - // TODO! - map: None, + map: Some(map), }; let api_match = super::matches::match_data_to_api(full_match_data); -- cgit v1.2.3