aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/routes
diff options
context:
space:
mode:
Diffstat (limited to 'planetwars-server/src/routes')
-rw-r--r--planetwars-server/src/routes/demo.rs15
1 files changed, 11 insertions, 4 deletions
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<String>,
+ pub map_name: Option<String>,
}
#[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(&params.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);