2023-02-04 01:01:49 +00:00
|
|
|
//! Domain definitions and implementation of common chat logic.
|
2024-04-21 17:45:50 +00:00
|
|
|
use anyhow::Result;
|
|
|
|
use prometheus::Registry as MetricsRegistry;
|
|
|
|
|
2024-05-03 22:37:49 +00:00
|
|
|
use crate::auth::Authenticator;
|
2024-04-23 16:26:40 +00:00
|
|
|
use crate::dialog::DialogRegistry;
|
2024-04-21 17:45:50 +00:00
|
|
|
use crate::player::PlayerRegistry;
|
|
|
|
use crate::repo::Storage;
|
|
|
|
use crate::room::RoomRegistry;
|
|
|
|
|
2024-04-23 10:10:10 +00:00
|
|
|
pub mod auth;
|
2024-04-23 16:26:40 +00:00
|
|
|
pub mod dialog;
|
2023-02-04 01:01:49 +00:00
|
|
|
pub mod player;
|
2023-09-30 23:34:35 +00:00
|
|
|
pub mod prelude;
|
2023-07-07 13:09:24 +00:00
|
|
|
pub mod repo;
|
2023-02-04 01:01:49 +00:00
|
|
|
pub mod room;
|
2023-09-30 23:34:35 +00:00
|
|
|
pub mod terminator;
|
2023-09-30 23:12:11 +00:00
|
|
|
|
|
|
|
mod table;
|
2024-04-21 17:45:50 +00:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct LavinaCore {
|
|
|
|
pub players: PlayerRegistry,
|
|
|
|
pub rooms: RoomRegistry,
|
2024-04-23 16:26:40 +00:00
|
|
|
pub dialogs: DialogRegistry,
|
2024-05-03 22:37:49 +00:00
|
|
|
pub authenticator: Authenticator,
|
2024-04-21 17:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl LavinaCore {
|
|
|
|
pub async fn new(mut metrics: MetricsRegistry, storage: Storage) -> Result<LavinaCore> {
|
|
|
|
// TODO shutdown all services in reverse order on error
|
|
|
|
let rooms = RoomRegistry::new(&mut metrics, storage.clone())?;
|
2024-04-23 16:26:40 +00:00
|
|
|
let dialogs = DialogRegistry::new(storage.clone());
|
|
|
|
let players = PlayerRegistry::empty(rooms.clone(), dialogs.clone(), storage.clone(), &mut metrics)?;
|
|
|
|
dialogs.set_players(players.clone()).await;
|
2024-05-03 22:37:49 +00:00
|
|
|
let authenticator = Authenticator::new(storage.clone());
|
2024-04-23 16:26:40 +00:00
|
|
|
Ok(LavinaCore {
|
|
|
|
players,
|
|
|
|
rooms,
|
|
|
|
dialogs,
|
2024-05-03 22:37:49 +00:00
|
|
|
authenticator,
|
2024-04-23 16:26:40 +00:00
|
|
|
})
|
2024-04-21 17:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn shutdown(mut self) -> Result<()> {
|
|
|
|
self.players.shutdown_all().await?;
|
2024-04-23 17:14:46 +00:00
|
|
|
self.dialogs.unset_players().await;
|
|
|
|
self.players.shutdown()?;
|
|
|
|
self.dialogs.shutdown()?;
|
|
|
|
self.rooms.shutdown()?;
|
2024-04-21 17:45:50 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|