From 158b590c35ad48a9e72a5d6cb14b3394ae521e25 Mon Sep 17 00:00:00 2001 From: Condorra Date: Mon, 13 Mar 2023 22:38:54 +1100 Subject: [PATCH] Revoke 'until death' consent on death. --- blastmud_game/src/db.rs | 10 ++++++++++ .../src/message_handler/user_commands/help.rs | 2 +- .../src/message_handler/user_commands/parsing.rs | 2 +- blastmud_game/src/services/combat.rs | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/blastmud_game/src/db.rs b/blastmud_game/src/db.rs index 62c52a92..ab08b599 100644 --- a/blastmud_game/src/db.rs +++ b/blastmud_game/src/db.rs @@ -744,6 +744,16 @@ impl DBTrans { } } + pub async fn revoke_until_death_consent(&self, party: &str) -> DResult<()> { + self.pg_trans()?.execute( + "DELETE FROM user_consent WHERE (consenting_user = $1 OR \ + (consented_user = $1 AND consent_type = 'fight')) AND \ + details->>'until_death'='true'", + &[&party] + ).await?; + Ok(()) + } + pub async fn delete_expired_user_consent(&self) -> DResult<()> { self.pg_trans()?.execute( "DELETE FROM user_consent WHERE details->>'expires' < $1", diff --git a/blastmud_game/src/message_handler/user_commands/help.rs b/blastmud_game/src/message_handler/user_commands/help.rs index ff7e5a2b..f587bd09 100644 --- a/blastmud_game/src/message_handler/user_commands/help.rs +++ b/blastmud_game/src/message_handler/user_commands/help.rs @@ -126,7 +126,7 @@ static REGISTERED_HELP_PAGES: phf::Map<&'static str, &'static str> = phf_map! { \n\ To allow, an individual, use the syntax allow type from player options\n\ Options can be blank to use defaults, or can be one or more of the following, separated by spaces:\n\ - \tuntil n minutes - replace n with a number. You can use hours, days, or weeks instead of minutes. This makes the consent expire. Fight expires after a week if you don't give a shorter period, and all other consent types have no expiry unless you specify one.\n\ + \tfor n minutes - replace n with a number. You can use hours, days, or weeks instead of minutes. This makes the consent expire. Fight expires after a week if you don't give a shorter period, and all other consent types have no expiry unless you specify one.\n\ \tuntil death - makes the consent valid only until you next die.\n\ \tallow private - makes the consent valid even in privately owned places. This is the default for anything except fight.\n\ \tdisallow private - the opposite of allow private.\n\ diff --git a/blastmud_game/src/message_handler/user_commands/parsing.rs b/blastmud_game/src/message_handler/user_commands/parsing.rs index b0ee5a42..252db2c0 100644 --- a/blastmud_game/src/message_handler/user_commands/parsing.rs +++ b/blastmud_game/src/message_handler/user_commands/parsing.rs @@ -179,7 +179,7 @@ pub fn parse_allow<'l>(input: &'l str, is_explicit: bool) -> Result { let (tok, new_input) = match new_input.split_once(" ") { - None => (input, ""), + None => (new_input, ""), Some(v) => v }; if tok.trim_start().to_lowercase() != "death" { diff --git a/blastmud_game/src/services/combat.rs b/blastmud_game/src/services/combat.rs index ed31d1b2..99b78b16 100644 --- a/blastmud_game/src/services/combat.rs +++ b/blastmud_game/src/services/combat.rs @@ -242,6 +242,8 @@ pub async fn handle_death(trans: &DBTrans, whom: &mut Item) -> DResult<()> { npc_code: whom.item_code.clone() } }).await?; + } else if whom.item_type == "player" { + trans.revoke_until_death_consent(&whom.item_code).await?; } Ok(()) }