From 2f915af91982073644be94bb2c68e095ffd35596 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Mon, 6 Jun 2022 14:25:56 +0200 Subject: send player_id through request metadata --- planetwars-server/src/modules/bot_api.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'planetwars-server/src/modules/bot_api.rs') 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>, ) -> Result, 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, -- cgit v1.2.3