2023-07-24 22:46:50 +10:00
|
|
|
#[double]
|
|
|
|
use crate::db::DBTrans;
|
|
|
|
use crate::{models::item::Item, DResult};
|
2023-03-25 00:58:19 +11:00
|
|
|
use mockall_double::double;
|
|
|
|
|
2023-07-24 22:46:50 +10:00
|
|
|
pub async fn broadcast_to_room(
|
|
|
|
trans: &DBTrans,
|
|
|
|
location: &str,
|
|
|
|
from_item: Option<&Item>,
|
|
|
|
message_explicit_ok: &str,
|
|
|
|
message_nonexplicit: Option<&str>,
|
|
|
|
) -> DResult<()> {
|
2023-03-25 00:58:19 +11:00
|
|
|
for item in trans.find_items_by_location(location).await? {
|
2023-04-23 22:31:31 +10:00
|
|
|
if item.item_type != "player" || item.death_data.is_some() {
|
2023-03-25 00:58:19 +11:00
|
|
|
continue;
|
|
|
|
}
|
2023-07-24 22:46:50 +10:00
|
|
|
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)
|
|
|
|
{
|
2023-03-25 00:58:19 +11:00
|
|
|
if let Some(msg) = message_nonexplicit {
|
|
|
|
trans.queue_for_session(&session, Some(msg)).await?;
|
|
|
|
}
|
|
|
|
return Ok(());
|
|
|
|
}
|
2023-07-24 22:46:50 +10:00
|
|
|
trans
|
|
|
|
.queue_for_session(&session, Some(message_explicit_ok))
|
|
|
|
.await?;
|
2023-03-25 00:58:19 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|