//! Domain definitions and implementation of common chat logic. use anyhow::Result; use prometheus::Registry as MetricsRegistry; use crate::player::PlayerRegistry; use crate::repo::Storage; use crate::room::RoomRegistry; pub mod player; pub mod prelude; pub mod repo; pub mod room; pub mod terminator; mod table; #[derive(Clone)] pub struct LavinaCore { pub players: PlayerRegistry, pub rooms: RoomRegistry, } impl LavinaCore { pub async fn new(mut metrics: MetricsRegistry, storage: Storage) -> Result { // TODO shutdown all services in reverse order on error let rooms = RoomRegistry::new(&mut metrics, storage.clone())?; let players = PlayerRegistry::empty(rooms.clone(), storage.clone(), &mut metrics)?; Ok(LavinaCore { players, rooms }) } pub async fn shutdown(mut self) -> Result<()> { self.players.shutdown_all().await?; drop(self.players); drop(self.rooms); Ok(()) } }