diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-12 20:54:00 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-12 20:54:00 +0200 |
commit | e69bd14f1d64b0d8b2438a40a069d3647c1edd73 (patch) | |
tree | fd16f12c56a9f51716e7908cb7180b892d01edc9 /planetwars-server/src/modules/bot_api.rs | |
parent | 0b9a9f0eaafb68acb7896ade26b9ae4508096d5c (diff) | |
download | planetwars.dev-e69bd14f1d64b0d8b2438a40a069d3647c1edd73.tar.xz planetwars.dev-e69bd14f1d64b0d8b2438a40a069d3647c1edd73.zip |
refactor: delay BotSpec construction in RunMatch
Diffstat (limited to 'planetwars-server/src/modules/bot_api.rs')
-rw-r--r-- | planetwars-server/src/modules/bot_api.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/planetwars-server/src/modules/bot_api.rs b/planetwars-server/src/modules/bot_api.rs index 732aa21..962b33d 100644 --- a/planetwars-server/src/modules/bot_api.rs +++ b/planetwars-server/src/modules/bot_api.rs @@ -102,10 +102,10 @@ impl pb::bot_api_service_server::BotApiService for BotApiServer { let match_request = req.get_ref(); - let opponent = db::bots::find_bot_by_name(&match_request.opponent_name, &conn) + let opponent_bot = db::bots::find_bot_by_name(&match_request.opponent_name, &conn) .map_err(|_| Status::not_found("opponent not found"))?; - let opponent_code_bundle = db::bots::active_bot_version(opponent.id, &conn) - .map_err(|_| Status::not_found("opponent has no code"))?; + let opponent_bot_version = db::bots::active_bot_version(opponent_bot.id, &conn) + .map_err(|_| Status::not_found("no opponent version found"))?; let player_key = gen_alphanumeric(32); @@ -114,8 +114,13 @@ impl pb::bot_api_service_server::BotApiService for BotApiServer { router: self.router.clone(), }); let mut run_match = RunMatch::from_players(vec![ - MatchPlayer::from_bot_spec(remote_bot_spec), - MatchPlayer::from_bot_version(&opponent, &opponent_code_bundle), + MatchPlayer::BotSpec { + spec: remote_bot_spec, + }, + MatchPlayer::BotVersion { + bot: Some(opponent_bot), + version: opponent_bot_version, + }, ]); let created_match = run_match .store_in_database(&conn) |