forked from lavina/lavina
sass
This commit is contained in:
parent
b619ff5f00
commit
486bc17ec5
|
@ -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.
|
/// Receives updates from other nodes and broadcasts them to local player actors.
|
||||||
struct Broadcasting {
|
struct Broadcasting {
|
||||||
|
subscriptions: HashMap<RoomId, HashSet<PlayerId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue