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.
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,
}

View File

@ -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() };

View File

@ -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,

View File

@ -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<()> {