blastmud/blastmud_game/src/services/comms.rs
Condorra 590d4640dd Implement craft on benches
Initially just a stove
Also update Rust.
2023-07-24 22:46:50 +10:00

34 lines
1.0 KiB
Rust

#[double]
use crate::db::DBTrans;
use crate::{models::item::Item, DResult};
use mockall_double::double;
pub async fn broadcast_to_room(
trans: &DBTrans,
location: &str,
from_item: Option<&Item>,
message_explicit_ok: &str,
message_nonexplicit: Option<&str>,
) -> DResult<()> {
for item in trans.find_items_by_location(location).await? {
if item.item_type != "player" || item.death_data.is_some() {
continue;
}
if let Some((session, session_dat)) = trans.find_session_for_player(&item.item_code).await?
{
if session_dat.less_explicit_mode
&& Some(&item.item_code) != from_item.map(|i| &i.item_code)
{
if let Some(msg) = message_nonexplicit {
trans.queue_for_session(&session, Some(msg)).await?;
}
return Ok(());
}
trans
.queue_for_session(&session, Some(message_explicit_ok))
.await?;
}
}
Ok(())
}