forked from lavina/lavina
de-arcify PlayerRegistry
This commit is contained in:
parent
c114de7dfa
commit
5818c0f516
|
@ -227,12 +227,12 @@ pub enum Updates {
|
|||
}
|
||||
|
||||
/// Handle to a player registry — a shared data structure containing information about players.
|
||||
pub struct PlayerRegistry(RwLock<PlayerRegistryInner>);
|
||||
impl PlayerRegistry {
|
||||
pub struct PlayerRegistry<'a>(RwLock<PlayerRegistryInner<'a>>);
|
||||
impl<'a> PlayerRegistry<'a> {
|
||||
pub fn empty(
|
||||
room_registry: RoomRegistry,
|
||||
metrics: &mut MetricsRegistry,
|
||||
) -> Result<PlayerRegistry> {
|
||||
room_registry: &'a RoomRegistry,
|
||||
metrics: &MetricsRegistry,
|
||||
) -> Result<PlayerRegistry<'a>> {
|
||||
let metric_active_players =
|
||||
IntGauge::new("chat_players_active", "Number of alive player actors")?;
|
||||
metrics.register(Box::new(metric_active_players.clone()))?;
|
||||
|
@ -276,8 +276,8 @@ impl PlayerRegistry {
|
|||
}
|
||||
|
||||
/// The player registry state representation.
|
||||
struct PlayerRegistryInner {
|
||||
room_registry: RoomRegistry,
|
||||
struct PlayerRegistryInner<'a> {
|
||||
room_registry: &'a RoomRegistry,
|
||||
players: HashMap<PlayerId, (PlayerHandle, JoinHandle<Player>)>,
|
||||
metric_active_players: IntGauge,
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ async fn main() -> Result<()> {
|
|||
let mut metrics = MetricsRegistry::new();
|
||||
let storage = Storage::open(storage_config).await?;
|
||||
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`
|
||||
let mut scope = unsafe { Scope::create() };
|
||||
|
|
|
@ -42,7 +42,7 @@ async fn handle_socket(
|
|||
config: ServerConfig,
|
||||
mut stream: TcpStream,
|
||||
socket_addr: &SocketAddr,
|
||||
players: &PlayerRegistry,
|
||||
players: &PlayerRegistry<'_>,
|
||||
rooms: &RoomRegistry,
|
||||
termination: Deferred<()>, // TODO use it to stop the connection gracefully
|
||||
storage: &Storage,
|
||||
|
@ -175,7 +175,7 @@ async fn handle_registration<'a>(
|
|||
|
||||
async fn handle_registered_socket<'a>(
|
||||
config: ServerConfig,
|
||||
players: &PlayerRegistry,
|
||||
players: &PlayerRegistry<'_>,
|
||||
rooms: &RoomRegistry,
|
||||
reader: &mut BufReader<ReadHalf<'a>>,
|
||||
writer: &mut BufWriter<WriteHalf<'a>>,
|
||||
|
@ -690,7 +690,7 @@ async fn produce_on_join_cmd_messages(
|
|||
|
||||
pub async fn launch<'a>(
|
||||
config: &'a ServerConfig,
|
||||
players: &'a PlayerRegistry,
|
||||
players: &'a PlayerRegistry<'_>,
|
||||
rooms: &'a RoomRegistry,
|
||||
metrics: &'a MetricsRegistry,
|
||||
storage: &'a Storage,
|
||||
|
|
|
@ -54,7 +54,7 @@ struct Authenticated {
|
|||
|
||||
pub async fn launch<'a>(
|
||||
config: ServerConfig,
|
||||
players: &'a PlayerRegistry,
|
||||
players: &'a PlayerRegistry<'_>,
|
||||
rooms: &'a RoomRegistry,
|
||||
metrics: &'a MetricsRegistry,
|
||||
scope: &mut Scope<'a>,
|
||||
|
@ -139,7 +139,7 @@ async fn handle_socket(
|
|||
config: Arc<LoadedConfig>,
|
||||
mut stream: TcpStream,
|
||||
socket_addr: &SocketAddr,
|
||||
players: &PlayerRegistry,
|
||||
players: &PlayerRegistry<'_>,
|
||||
rooms: &RoomRegistry,
|
||||
termination: Deferred<()>, // TODO use it to stop the connection gracefully
|
||||
) -> Result<()> {
|
||||
|
|
Loading…
Reference in New Issue