aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-09-02 21:58:32 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-09-02 21:58:32 +0200
commit2fec5e4509aeb4520691bce57016707a399dffa6 (patch)
tree35e4c5b26bee2a0f99e982f790d9460f57d62525
parentd95eedcc83f8d07a49c25c5240beb8a0105d877a (diff)
downloadplanetwars.dev-2fec5e4509aeb4520691bce57016707a399dffa6.tar.xz
planetwars.dev-2fec5e4509aeb4520691bce57016707a399dffa6.zip
implement map selection in cli
-rw-r--r--planetwars-client/src/main.rs19
-rw-r--r--planetwars-server/src/modules/client_api.rs7
-rw-r--r--proto/client_api.proto1
3 files changed, 21 insertions, 6 deletions
diff --git a/planetwars-client/src/main.rs b/planetwars-client/src/main.rs
index 21da005..1821fd3 100644
--- a/planetwars-client/src/main.rs
+++ b/planetwars-client/src/main.rs
@@ -22,6 +22,9 @@ struct PlayMatch {
#[clap(value_parser)]
opponent_name: String,
+ #[clap(value_parser, long = "map")]
+ map_name: Option<String>,
+
#[clap(
value_parser,
long,
@@ -69,9 +72,13 @@ async fn main() {
let channel = Channel::builder(uri).connect().await.unwrap();
- let created_match = create_match(channel.clone(), play_match.opponent_name)
- .await
- .unwrap();
+ let created_match = create_match(
+ channel.clone(),
+ play_match.opponent_name,
+ play_match.map_name,
+ )
+ .await
+ .unwrap();
run_player(bot_config, created_match.player_key, channel).await;
println!(
"Match completed. Watch the replay at {}",
@@ -83,10 +90,14 @@ async fn main() {
async fn create_match(
channel: Channel,
opponent_name: String,
+ map_name: Option<String>,
) -> Result<pb::CreateMatchResponse, Status> {
let mut client = ClientApiServiceClient::new(channel);
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;
res.map(|response| response.into_inner())
}
diff --git a/planetwars-server/src/modules/client_api.rs b/planetwars-server/src/modules/client_api.rs
index 0efc000..3402964 100644
--- a/planetwars-server/src/modules/client_api.rs
+++ b/planetwars-server/src/modules/client_api.rs
@@ -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)
.map_err(|_| Status::not_found("opponent not found"))?;
- // TODO: allow map as parameter here
- let map = db::maps::find_map_by_name(&"hex", &conn)
+ let map_name = match match_request.map_name.as_str() {
+ "" => "hex",
+ name => name,
+ };
+ let map = db::maps::find_map_by_name(map_name, &conn)
.map_err(|_| Status::not_found("map not found"))?;
let player_key = gen_alphanumeric(32);
diff --git a/proto/client_api.proto b/proto/client_api.proto
index 3f1b956..07164e5 100644
--- a/proto/client_api.proto
+++ b/proto/client_api.proto
@@ -10,6 +10,7 @@ service ClientApiService {
message CreateMatchRequest {
string opponent_name = 1;
+ string map_name = 2;
}
message CreateMatchResponse {