From 3f6419e5f8c9cecd2c5811f4f69f1d15e5542957 Mon Sep 17 00:00:00 2001 From: Condorra Date: Mon, 13 Mar 2023 18:28:03 +1100 Subject: [PATCH] Enforce consent check on use command. --- .../src/message_handler/user_commands/use_cmd.rs | 9 +++++++++ blastmud_game/src/services.rs | 4 ++++ .../src/static_content/possession_type/trauma_kit.rs | 6 +++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/blastmud_game/src/message_handler/user_commands/use_cmd.rs b/blastmud_game/src/message_handler/user_commands/use_cmd.rs index 7e7a312d..ff636b6e 100644 --- a/blastmud_game/src/message_handler/user_commands/use_cmd.rs +++ b/blastmud_game/src/message_handler/user_commands/use_cmd.rs @@ -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()) { diff --git a/blastmud_game/src/services.rs b/blastmud_game/src/services.rs index dccf0abd..0d048645 100644 --- a/blastmud_game/src/services.rs +++ b/blastmud_game/src/services.rs @@ -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? { diff --git a/blastmud_game/src/static_content/possession_type/trauma_kit.rs b/blastmud_game/src/static_content/possession_type/trauma_kit.rs index c7c18b34..0981d4ac 100644 --- a/blastmud_game/src/static_content/possession_type/trauma_kit.rs +++ b/blastmud_game/src/static_content/possession_type/trauma_kit.rs @@ -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),