diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-25 22:16:50 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-25 22:16:50 +0200 |
commit | 67276bd0bbac15fe087edafd59d164c686509b35 (patch) | |
tree | b844126c3d0987c4beb12cb60a968a9f53fc6ce9 /planetwars-client | |
parent | 93c4306b1015594bb6d7e08d03138c12229ac598 (diff) | |
download | planetwars.dev-67276bd0bbac15fe087edafd59d164c686509b35.tar.xz planetwars.dev-67276bd0bbac15fe087edafd59d164c686509b35.zip |
rename bot_api to client_api
Diffstat (limited to 'planetwars-client')
-rw-r--r-- | planetwars-client/build.rs | 2 | ||||
-rw-r--r-- | planetwars-client/src/main.rs | 31 |
2 files changed, 18 insertions, 15 deletions
diff --git a/planetwars-client/build.rs b/planetwars-client/build.rs index acabd08..b58ef08 100644 --- a/planetwars-client/build.rs +++ b/planetwars-client/build.rs @@ -4,6 +4,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { tonic_build::configure() .build_server(false) .build_client(true) - .compile(&["../proto/bot_api.proto"], &["../proto"])?; + .compile(&["../proto/client_api.proto"], &["../proto"])?; Ok(()) } diff --git a/planetwars-client/src/main.rs b/planetwars-client/src/main.rs index 6edcc2e..5053c51 100644 --- a/planetwars-client/src/main.rs +++ b/planetwars-client/src/main.rs @@ -1,9 +1,12 @@ pub mod pb { - tonic::include_proto!("grpc.planetwars.bot_api"); + tonic::include_proto!("grpc.planetwars.client_api"); + + pub use player_api_client_message::ClientMessage as PlayerApiClientMessageType; + pub use player_api_server_message::ServerMessage as PlayerApiServerMessageType; } use clap::Parser; -use pb::bot_api_service_client::BotApiServiceClient; +use pb::client_api_service_client::ClientApiServiceClient; use planetwars_matchrunner::bot_runner::Bot; use serde::Deserialize; use std::{path::PathBuf, time::Duration}; @@ -77,16 +80,19 @@ async fn main() { tokio::time::sleep(Duration::from_secs(1)).await; } -async fn create_match(channel: Channel, opponent_name: String) -> Result<pb::CreatedMatch, Status> { - let mut client = BotApiServiceClient::new(channel); +async fn create_match( + channel: Channel, + opponent_name: String, +) -> Result<pb::CreateMatchResponse, Status> { + let mut client = ClientApiServiceClient::new(channel); let res = client - .create_match(Request::new(pb::MatchRequest { opponent_name })) + .create_match(Request::new(pb::CreateMatchRequest { opponent_name })) .await; res.map(|response| response.into_inner()) } async fn run_player(bot_config: BotConfig, player_key: String, channel: Channel) { - let mut client = BotApiServiceClient::with_interceptor(channel, |mut req: Request<()>| { + let mut client = ClientApiServiceClient::with_interceptor(channel, |mut req: Request<()>| { let player_key: MetadataValue<_> = player_key.parse().unwrap(); req.metadata_mut().insert("player_key", player_key); Ok(req) @@ -109,18 +115,15 @@ async fn run_player(bot_config: BotConfig, player_key: String, channel: Channel) .unwrap() .into_inner(); while let Some(message) = stream.message().await.unwrap() { - use pb::client_message::ClientMessage; - use pb::server_message::ServerMessage; - match message.server_message { - Some(ServerMessage::PlayerRequest(req)) => { + Some(pb::PlayerApiServerMessageType::ActionRequest(req)) => { let moves = bot_process.communicate(&req.content).await.unwrap(); - let resp = pb::PlayerRequestResponse { - request_id: req.request_id, + let action = pb::PlayerAction { + action_request_id: req.action_request_id, content: moves.as_bytes().to_vec(), }; - let msg = pb::ClientMessage { - client_message: Some(ClientMessage::RequestResponse(resp)), + let msg = pb::PlayerApiClientMessage { + client_message: Some(pb::PlayerApiClientMessageType::Action(action)), }; tx.send(msg).unwrap(); } |