From 486bc17ec5f2624d2025c3fa26bda3051c15a47e Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Wed, 8 May 2024 19:04:53 +0200 Subject: [PATCH] sass --- .../lavina-core/src/clustering/broadcast.rs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/lavina-core/src/clustering/broadcast.rs b/crates/lavina-core/src/clustering/broadcast.rs index 190698f..470db85 100644 --- a/crates/lavina-core/src/clustering/broadcast.rs +++ b/crates/lavina-core/src/clustering/broadcast.rs @@ -1,5 +1,29 @@ +use std::collections::{HashMap, HashSet}; +use crate::player::PlayerId; +use crate::prelude::Str; +use crate::room::RoomId; + /// Receives updates from other nodes and broadcasts them to local player actors. struct Broadcasting { - + subscriptions: HashMap>, } +impl Broadcasting { + /// Creates a new broadcasting instance. + pub fn new() -> Self { + Self { + subscriptions: HashMap::new(), + } + } + + /// Broadcasts the given update to player actors. + pub fn broadcast(&self, room_id: RoomId, author_id: PlayerId, message: Str) { + self.subscriptions.get(&room_id).map(|players| { + players.iter().for_each(|player_id| { + // Send the message to the player actor. + }); + }); + } + + +} \ No newline at end of file