forked from lavina/lavina
1
0
Fork 0

de-arcify PlayerRegistry

This commit is contained in:
Nikita Vilunov 2023-09-06 18:03:12 +02:00
parent c114de7dfa
commit 5818c0f516
4 changed files with 13 additions and 13 deletions

View File

@ -227,12 +227,12 @@ pub enum Updates {
} }
/// Handle to a player registry — a shared data structure containing information about players. /// Handle to a player registry — a shared data structure containing information about players.
pub struct PlayerRegistry(RwLock<PlayerRegistryInner>); pub struct PlayerRegistry<'a>(RwLock<PlayerRegistryInner<'a>>);
impl PlayerRegistry { impl<'a> PlayerRegistry<'a> {
pub fn empty( pub fn empty(
room_registry: RoomRegistry, room_registry: &'a RoomRegistry,
metrics: &mut MetricsRegistry, metrics: &MetricsRegistry,
) -> Result<PlayerRegistry> { ) -> Result<PlayerRegistry<'a>> {
let metric_active_players = let metric_active_players =
IntGauge::new("chat_players_active", "Number of alive player actors")?; IntGauge::new("chat_players_active", "Number of alive player actors")?;
metrics.register(Box::new(metric_active_players.clone()))?; metrics.register(Box::new(metric_active_players.clone()))?;
@ -276,8 +276,8 @@ impl PlayerRegistry {
} }
/// The player registry state representation. /// The player registry state representation.
struct PlayerRegistryInner { struct PlayerRegistryInner<'a> {
room_registry: RoomRegistry, room_registry: &'a RoomRegistry,
players: HashMap<PlayerId, (PlayerHandle, JoinHandle<Player>)>, players: HashMap<PlayerId, (PlayerHandle, JoinHandle<Player>)>,
metric_active_players: IntGauge, metric_active_players: IntGauge,
} }

View File

@ -54,7 +54,7 @@ async fn main() -> Result<()> {
let mut metrics = MetricsRegistry::new(); let mut metrics = MetricsRegistry::new();
let storage = Storage::open(storage_config).await?; let storage = Storage::open(storage_config).await?;
let rooms = RoomRegistry::new(&mut metrics, storage.clone())?; let rooms = RoomRegistry::new(&mut metrics, storage.clone())?;
let mut players = PlayerRegistry::empty(rooms.clone(), &mut metrics)?; let mut players = PlayerRegistry::empty(&rooms, &metrics)?;
// unsafe: outer future is never dropped, scope is joined on `scope.collect` // unsafe: outer future is never dropped, scope is joined on `scope.collect`
let mut scope = unsafe { Scope::create() }; let mut scope = unsafe { Scope::create() };

View File

@ -42,7 +42,7 @@ async fn handle_socket(
config: ServerConfig, config: ServerConfig,
mut stream: TcpStream, mut stream: TcpStream,
socket_addr: &SocketAddr, socket_addr: &SocketAddr,
players: &PlayerRegistry, players: &PlayerRegistry<'_>,
rooms: &RoomRegistry, rooms: &RoomRegistry,
termination: Deferred<()>, // TODO use it to stop the connection gracefully termination: Deferred<()>, // TODO use it to stop the connection gracefully
storage: &Storage, storage: &Storage,
@ -175,7 +175,7 @@ async fn handle_registration<'a>(
async fn handle_registered_socket<'a>( async fn handle_registered_socket<'a>(
config: ServerConfig, config: ServerConfig,
players: &PlayerRegistry, players: &PlayerRegistry<'_>,
rooms: &RoomRegistry, rooms: &RoomRegistry,
reader: &mut BufReader<ReadHalf<'a>>, reader: &mut BufReader<ReadHalf<'a>>,
writer: &mut BufWriter<WriteHalf<'a>>, writer: &mut BufWriter<WriteHalf<'a>>,
@ -690,7 +690,7 @@ async fn produce_on_join_cmd_messages(
pub async fn launch<'a>( pub async fn launch<'a>(
config: &'a ServerConfig, config: &'a ServerConfig,
players: &'a PlayerRegistry, players: &'a PlayerRegistry<'_>,
rooms: &'a RoomRegistry, rooms: &'a RoomRegistry,
metrics: &'a MetricsRegistry, metrics: &'a MetricsRegistry,
storage: &'a Storage, storage: &'a Storage,

View File

@ -54,7 +54,7 @@ struct Authenticated {
pub async fn launch<'a>( pub async fn launch<'a>(
config: ServerConfig, config: ServerConfig,
players: &'a PlayerRegistry, players: &'a PlayerRegistry<'_>,
rooms: &'a RoomRegistry, rooms: &'a RoomRegistry,
metrics: &'a MetricsRegistry, metrics: &'a MetricsRegistry,
scope: &mut Scope<'a>, scope: &mut Scope<'a>,
@ -139,7 +139,7 @@ async fn handle_socket(
config: Arc<LoadedConfig>, config: Arc<LoadedConfig>,
mut stream: TcpStream, mut stream: TcpStream,
socket_addr: &SocketAddr, socket_addr: &SocketAddr,
players: &PlayerRegistry, players: &PlayerRegistry<'_>,
rooms: &RoomRegistry, rooms: &RoomRegistry,
termination: Deferred<()>, // TODO use it to stop the connection gracefully termination: Deferred<()>, // TODO use it to stop the connection gracefully
) -> Result<()> { ) -> Result<()> {