Enforce consent check on use command.

This commit is contained in:
Condorra 2023-03-13 18:28:03 +11:00
parent b000f9830b
commit 3f6419e5f8
3 changed files with 18 additions and 1 deletions

View File

@ -25,6 +25,7 @@ use crate::{
broadcast_to_room,
skills::skill_check_and_grind,
effect::run_effects,
check_consent,
},
language,
};
@ -164,6 +165,14 @@ impl QueueCommandHandler for QueueHandler {
None => user_error("You can't use that!".to_owned())?,
Some(d) => d
};
if let Some(consent_type) = use_data.needs_consent_check.as_ref() {
if !check_consent(ctx.trans, "use", consent_type, &player_item, &target).await? {
user_error(format!("{} doesn't allow {} from you",
&target.display_for_sentence(!ctx.session_dat.less_explicit_mode,
1, true),
consent_type.to_str()))?
}
}
if let Some(charge_data) = item.possession_type.as_ref()
.and_then(|poss_type| possession_data().get(&poss_type))
.and_then(|poss_data| poss_data.charge_data.as_ref()) {

View File

@ -74,6 +74,10 @@ pub async fn check_consent(trans: &DBTrans, action: &str,
});
}
if target.item_code == by.item_code {
return Ok(true)
}
trans.delete_expired_user_consent().await?;
if let Some(consent) = trans.find_user_consent_by_parties_type(
&target.item_code, &by.item_code, consent_type).await? {

View File

@ -1,5 +1,8 @@
use super::{PossessionData, UseData, UseEffect, ChargeData};
use crate::models::item::SkillType;
use crate::models::{
item::SkillType,
consent::ConsentType,
};
use super::PossessionType::*;
@ -216,6 +219,7 @@ pub fn medium_data() -> PossessionData {
} else {
None
}),
needs_consent_check: Some(ConsentType::Medicine),
..Default::default()
}),
becomes_on_spent: Some(EmptyMedicalBox),