diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-06-06 14:25:56 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-06-06 14:25:56 +0200 |
commit | 2f915af91982073644be94bb2c68e095ffd35596 (patch) | |
tree | c59eb7330c9472fb9da02615cc08fb33e842961c /planetwars-server/src/modules | |
parent | d0faec7d1f4deb132554db7f946df4b9d4e9711b (diff) | |
download | planetwars.dev-2f915af91982073644be94bb2c68e095ffd35596.tar.xz planetwars.dev-2f915af91982073644be94bb2c68e095ffd35596.zip |
send player_id through request metadata
Diffstat (limited to 'planetwars-server/src/modules')
-rw-r--r-- | planetwars-server/src/modules/bot_api.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/planetwars-server/src/modules/bot_api.rs b/planetwars-server/src/modules/bot_api.rs index 2face62..f6e4d5c 100644 --- a/planetwars-server/src/modules/bot_api.rs +++ b/planetwars-server/src/modules/bot_api.rs @@ -62,10 +62,23 @@ impl pb::bot_api_service_server::BotApiService for BotApiServer { &self, req: Request<Streaming<pb::PlayerRequestResponse>>, ) -> Result<Response<Self::ConnectBotStream>, Status> { - println!("bot connected"); + // TODO: clean up errors + let player_id = req + .metadata() + .get("player_id") + .ok_or_else(|| Status::unauthenticated("no player_id provided"))?; + + let player_id_str = player_id + .to_str() + .map_err(|_| Status::invalid_argument("unreadable string"))?; + + let sync_data = self + .router + .get(player_id_str) + .ok_or_else(|| Status::not_found("player_id not found"))?; + let stream = req.into_inner(); - // TODO: return error when player does not exist - let sync_data = self.router.get("test_player").unwrap(); + sync_data.tx.send(stream).unwrap(); Ok(Response::new(UnboundedReceiverStream::new( sync_data.server_messages, |