|
|
|
@ -149,7 +149,6 @@ impl GameService { |
|
|
|
} |
|
|
|
|
|
|
|
async fn get_default_status(&self, uuid: uuid::Uuid) -> Result<Option<MessageStatus>, Status> { |
|
|
|
|
|
|
|
log::info!("Getting the deafult status for {}", uuid); |
|
|
|
let lobby = { |
|
|
|
let mut conn = self.conn.write().await; |
|
|
|
@ -159,8 +158,7 @@ impl GameService { |
|
|
|
}; |
|
|
|
lobby |
|
|
|
}; |
|
|
|
let r =
|
|
|
|
Ok(self |
|
|
|
let r = Ok(self |
|
|
|
.running_games |
|
|
|
.read() |
|
|
|
.await |
|
|
|
@ -214,7 +212,6 @@ impl game_server::Game for GameService { |
|
|
|
// log::info!("Loading back image [{:?}]", time.elapsed());
|
|
|
|
let back_buf = tokio::fs::read(back).await.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
log::info!("Loaded images [{:?}]", time.elapsed()); |
|
|
|
Ok(Response::new(Image { |
|
|
|
face: face_buf, |
|
|
|
@ -228,13 +225,17 @@ impl game_server::Game for GameService { |
|
|
|
) -> Result<tonic::Response<()>, Status> { |
|
|
|
let uuid = client_id::get(request.metadata()).map_err(|x| match x { |
|
|
|
client_id::Error::NotSet => Status::failed_precondition("client_id must be set"), |
|
|
|
client_id::Error::MalformedUuid => Status::failed_precondition("malformed client_id"), |
|
|
|
client_id::Error::MalformedUuid => { |
|
|
|
Status::failed_precondition("malformed client_id") |
|
|
|
} |
|
|
|
})?; |
|
|
|
{ |
|
|
|
let mut conn = self.conn.write().await; |
|
|
|
let lobby: u32 = match conn.get_lobby_for_user(uuid).await { |
|
|
|
Some(l) => l, |
|
|
|
None => return Err(Status::failed_precondition("User isn't in a lobby")), |
|
|
|
}; |
|
|
|
log::debug!("{} clicked a card in the lobby {}", uuid, lobby); |
|
|
|
let games_lock = self.running_games.read().await; |
|
|
|
let mut game_lock = match games_lock.get(&lobby) { |
|
|
|
Some(x) => x.write().await, |
|
|
|
@ -261,6 +262,7 @@ impl game_server::Game for GameService { |
|
|
|
pile_name: card.pile_name, |
|
|
|
}; |
|
|
|
game.on_click(card, game.get_player_for_uuid(&uuid).unwrap()); |
|
|
|
} // drop the connection so that the lock is released
|
|
|
|
self.update_status(uuid).await?; |
|
|
|
Ok(Response::new(())) |
|
|
|
} |
|
|
|
@ -282,9 +284,7 @@ impl game_server::Game for GameService { |
|
|
|
r |
|
|
|
}); |
|
|
|
log::info!("Status is acquired"); |
|
|
|
let r= Ok(Response::new( |
|
|
|
status, |
|
|
|
)); |
|
|
|
let r = Ok(Response::new(status)); |
|
|
|
log::info!("Given game status to {}", uuid); |
|
|
|
r |
|
|
|
} |
|
|
|
|