aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-06-09 20:57:45 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-06-09 20:57:45 +0200
commitd1977b95c82f608bc558432cdfba8026aaf0648d (patch)
tree2e23b6553b444dc2e93130c035cf738c0e5a07a8
parente3cf0df4509fe5cb0ad114040f52f61436a6663f (diff)
downloadplanetwars.dev-d1977b95c82f608bc558432cdfba8026aaf0648d.tar.xz
planetwars.dev-d1977b95c82f608bc558432cdfba8026aaf0648d.zip
consistently use player_key and player_id
-rw-r--r--planetwars-client/src/main.rs4
-rw-r--r--planetwars-server/src/modules/bot_api.rs20
2 files changed, 12 insertions, 12 deletions
diff --git a/planetwars-client/src/main.rs b/planetwars-client/src/main.rs
index 9df100d..3ece5b3 100644
--- a/planetwars-client/src/main.rs
+++ b/planetwars-client/src/main.rs
@@ -44,8 +44,8 @@ async fn create_match(channel: Channel) -> Result<pb::CreatedMatch, Status> {
async fn run_player(bot_config: BotConfig, player_key: String, channel: Channel) {
let mut client = BotApiServiceClient::with_interceptor(channel, |mut req: Request<()>| {
- let player_id: MetadataValue<_> = player_key.parse().unwrap();
- req.metadata_mut().insert("player_id", player_id);
+ let player_key: MetadataValue<_> = player_key.parse().unwrap();
+ req.metadata_mut().insert("player_key", player_key);
Ok(req)
});
diff --git a/planetwars-server/src/modules/bot_api.rs b/planetwars-server/src/modules/bot_api.rs
index 8aa5d29..4eb13c1 100644
--- a/planetwars-server/src/modules/bot_api.rs
+++ b/planetwars-server/src/modules/bot_api.rs
@@ -45,15 +45,15 @@ impl PlayerRouter {
// TODO: implement a way to expire entries
impl PlayerRouter {
- fn put(&self, player_id: String, entry: SyncThingData) {
+ fn put(&self, player_key: String, entry: SyncThingData) {
let mut routing_table = self.routing_table.lock().unwrap();
- routing_table.insert(player_id, entry);
+ routing_table.insert(player_key, entry);
}
- fn take(&self, player_id: &str) -> Option<SyncThingData> {
+ fn take(&self, player_key: &str) -> Option<SyncThingData> {
// TODO: this design does not allow for reconnects. Is this desired?
let mut routing_table = self.routing_table.lock().unwrap();
- routing_table.remove(player_id)
+ routing_table.remove(player_key)
}
}
@@ -66,19 +66,19 @@ impl pb::bot_api_service_server::BotApiService for BotApiServer {
req: Request<Streaming<pb::PlayerRequestResponse>>,
) -> Result<Response<Self::ConnectBotStream>, Status> {
// TODO: clean up errors
- let player_id = req
+ let player_key = req
.metadata()
- .get("player_id")
- .ok_or_else(|| Status::unauthenticated("no player_id provided"))?;
+ .get("player_key")
+ .ok_or_else(|| Status::unauthenticated("no player_key provided"))?;
- let player_id_str = player_id
+ let player_key_str = player_key
.to_str()
.map_err(|_| Status::invalid_argument("unreadable string"))?;
let sync_data = self
.router
- .take(player_id_str)
- .ok_or_else(|| Status::not_found("player_id not found"))?;
+ .take(player_key_str)
+ .ok_or_else(|| Status::not_found("player_key not found"))?;
let stream = req.into_inner();