diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-20 23:43:19 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-20 23:43:19 +0200 |
commit | 31f8271db6735a1c7abea4d93bb3b8d7a3ce4628 (patch) | |
tree | 5e8c511f86c535d3d6913ec326cef9888c8d0f12 /planetwars-client/src | |
parent | 73c536b4a6d8cbc788ca4a22ed1c62744f3fa12f (diff) | |
download | planetwars.dev-31f8271db6735a1c7abea4d93bb3b8d7a3ce4628.tar.xz planetwars.dev-31f8271db6735a1c7abea4d93bb3b8d7a3ce4628.zip |
update client for oneof messages
Diffstat (limited to 'planetwars-client/src')
-rw-r--r-- | planetwars-client/src/main.rs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/planetwars-client/src/main.rs b/planetwars-client/src/main.rs index 3ece5b3..25a6725 100644 --- a/planetwars-client/src/main.rs +++ b/planetwars-client/src/main.rs @@ -57,16 +57,27 @@ async fn run_player(bot_config: BotConfig, player_key: String, channel: Channel) let (tx, rx) = mpsc::unbounded_channel(); let mut stream = client - .connect_bot(UnboundedReceiverStream::new(rx)) + .connect_player(UnboundedReceiverStream::new(rx)) .await .unwrap() .into_inner(); while let Some(message) = stream.message().await.unwrap() { - let moves = bot_process.communicate(&message.content).await.unwrap(); - tx.send(pb::PlayerRequestResponse { - request_id: message.request_id, - content: moves.as_bytes().to_vec(), - }) - .unwrap(); + use pb::client_message::ClientMessage; + use pb::server_message::ServerMessage; + + match message.server_message { + Some(ServerMessage::PlayerRequest(req)) => { + let moves = bot_process.communicate(&req.content).await.unwrap(); + let resp = pb::PlayerRequestResponse { + request_id: req.request_id, + content: moves.as_bytes().to_vec(), + }; + let msg = pb::ClientMessage { + client_message: Some(ClientMessage::RequestResponse(resp)), + }; + tx.send(msg).unwrap(); + } + _ => {} // pass + } } } |