implement map selection in cli

This commit is contained in:
Ilion Beyst 2022-09-02 21:58:32 +02:00
parent d95eedcc83
commit 2fec5e4509
3 changed files with 21 additions and 6 deletions

View file

@ -22,6 +22,9 @@ struct PlayMatch {
#[clap(value_parser)] #[clap(value_parser)]
opponent_name: String, opponent_name: String,
#[clap(value_parser, long = "map")]
map_name: Option<String>,
#[clap( #[clap(
value_parser, value_parser,
long, long,
@ -69,7 +72,11 @@ async fn main() {
let channel = Channel::builder(uri).connect().await.unwrap(); let channel = Channel::builder(uri).connect().await.unwrap();
let created_match = create_match(channel.clone(), play_match.opponent_name) let created_match = create_match(
channel.clone(),
play_match.opponent_name,
play_match.map_name,
)
.await .await
.unwrap(); .unwrap();
run_player(bot_config, created_match.player_key, channel).await; run_player(bot_config, created_match.player_key, channel).await;
@ -83,10 +90,14 @@ async fn main() {
async fn create_match( async fn create_match(
channel: Channel, channel: Channel,
opponent_name: String, opponent_name: String,
map_name: Option<String>,
) -> Result<pb::CreateMatchResponse, Status> { ) -> Result<pb::CreateMatchResponse, Status> {
let mut client = ClientApiServiceClient::new(channel); let mut client = ClientApiServiceClient::new(channel);
let res = client let res = client
.create_match(Request::new(pb::CreateMatchRequest { opponent_name })) .create_match(Request::new(pb::CreateMatchRequest {
opponent_name,
map_name: map_name.unwrap_or_default(),
}))
.await; .await;
res.map(|response| response.into_inner()) res.map(|response| response.into_inner())
} }

View file

@ -111,8 +111,11 @@ impl pb::client_api_service_server::ClientApiService for ClientApiServer {
db::bots::find_bot_with_version_by_name(&match_request.opponent_name, &conn) db::bots::find_bot_with_version_by_name(&match_request.opponent_name, &conn)
.map_err(|_| Status::not_found("opponent not found"))?; .map_err(|_| Status::not_found("opponent not found"))?;
// TODO: allow map as parameter here let map_name = match match_request.map_name.as_str() {
let map = db::maps::find_map_by_name(&"hex", &conn) "" => "hex",
name => name,
};
let map = db::maps::find_map_by_name(map_name, &conn)
.map_err(|_| Status::not_found("map not found"))?; .map_err(|_| Status::not_found("map not found"))?;
let player_key = gen_alphanumeric(32); let player_key = gen_alphanumeric(32);

View file

@ -10,6 +10,7 @@ service ClientApiService {
message CreateMatchRequest { message CreateMatchRequest {
string opponent_name = 1; string opponent_name = 1;
string map_name = 2;
} }
message CreateMatchResponse { message CreateMatchResponse {