an http based roguelike rpg about jelqing
Blame: src/game/household.rs
782069860236 | atagen | 2026-10-10 12:44 UTC | 1 | use std::collections::HashMap; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 2 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 3 | use axum::http::{StatusCode, header}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 4 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 5 | use super::{ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 6 | Cause, Floor, Notice, Run, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 7 | balance::{PATIENCE, VIRAL_ERRAND}, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 8 | credentials::{Scheme, parse_credentials}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 9 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 10 | use crate::problem::Problem; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 11 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 12 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 13 | pub enum Excuse { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 14 | Changing, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 15 | Homework, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 16 | PulledAMuscle, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 17 | Tidying, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 18 | TheWashingUp, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 19 | FedTheCat, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 20 | Revising, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 21 | OnACall, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 22 | WrappingPresents, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 23 | FoldingTheWashing, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 24 | HangingTheLights, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 25 | HelpingNan, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 26 | PeelingSprouts, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 27 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 28 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 29 | impl Excuse { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 30 | const EVERYDAY: [Self; 7] = [ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 31 | Self::Changing, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 32 | Self::Homework, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 33 | Self::PulledAMuscle, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 34 | Self::Tidying, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 35 | Self::TheWashingUp, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 36 | Self::FedTheCat, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 37 | Self::Revising, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 38 | ]; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 39 | const CHRISTMAS: [Self; 6] = [ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 40 | Self::OnACall, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 41 | Self::WrappingPresents, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 42 | Self::FoldingTheWashing, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 43 | Self::HangingTheLights, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 44 | Self::HelpingNan, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 45 | Self::PeelingSprouts, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 46 | ]; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 47 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 48 | pub fn phrase(self) -> &'static str { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 49 | match self { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 50 | Self::Changing => "changing", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 51 | Self::Homework => "homework", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 52 | Self::PulledAMuscle => "pulled a muscle", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 53 | Self::Tidying => "tidying", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 54 | Self::TheWashingUp => "the washing up", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 55 | Self::FedTheCat => "fed the cat", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 56 | Self::Revising => "revising", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 57 | Self::OnACall => "on a call", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 58 | Self::WrappingPresents => "wrapping presents", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 59 | Self::FoldingTheWashing => "folding the washing", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 60 | Self::HangingTheLights => "hanging the lights", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 61 | Self::HelpingNan => "helping Nan", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 62 | Self::PeelingSprouts => "peeling sprouts", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 63 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 64 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 65 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 66 | fn all() -> impl Iterator<Item = Self> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 67 | Self::EVERYDAY.into_iter().chain(Self::CHRISTMAS) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 68 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 69 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 70 | fn parse(spoken: &str) -> Option<Self> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 71 | Self::all().find(|excuse| excuse.phrase().eq_ignore_ascii_case(spoken)) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 72 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 73 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 74 | |
c4d70621d377 | atagen | 2026-10-12 11:56 UTC | 75 | /// Every excuse Mum might hear, so a localised one can be traced back to the phrase she checks. |
c4d70621d377 | atagen | 2026-10-12 11:56 UTC | 76 | pub fn vocabulary() -> impl Iterator<Item = &'static str> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 77 | Excuse::all().map(Excuse::phrase) |
c4d70621d377 | atagen | 2026-10-12 11:56 UTC | 78 | } |
c4d70621d377 | atagen | 2026-10-12 11:56 UTC | 79 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 80 | fn is_truth(spoken: &str) -> bool { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 81 | ["the truth", "truth", "honesty"] |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 82 | .iter() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 83 | .any(|truth| truth.eq_ignore_ascii_case(spoken)) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 84 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 85 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 86 | const BEDROOM_ERRANDS: [&str; 4] = [ |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 87 | "She has brought your washing.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 88 | "She wants to know if you have eaten.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 89 | "She needs the wifi password.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 90 | "She would like to talk about your future.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 91 | ]; |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 92 | const CHRISTMAS_ERRANDS: [&str; 4] = [ |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 93 | "Nan would like to see you.", |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 94 | "Christmas dinner is in ten minutes.", |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 95 | "The King's speech is about to start.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 96 | "An uncle has asked where you went.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 97 | ]; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 98 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 99 | #[derive(Default)] |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 100 | pub struct Household { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 101 | pub(crate) mum: Option<MumVisit>, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 102 | /// Every excuse Mum has accepted this run. Digest Mum remembers them all. |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 103 | pub(crate) heard: Vec<Excuse>, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 104 | pub(crate) kitchen_tellings: u8, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 105 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 106 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 107 | pub struct MumVisit { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 108 | pub(crate) errand: &'static str, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 109 | pub(crate) nonce: String, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 110 | pub(crate) strikes: u8, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 111 | pub(crate) knocked: bool, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 112 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 113 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 114 | fn digest_params(authorization: &str) -> Option<HashMap<String, String>> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 115 | let (scheme, rest) = authorization.trim().split_once(' ')?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 116 | if !scheme.eq_ignore_ascii_case("digest") { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 117 | return None; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 118 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 119 | Some( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 120 | rest.split(',') |
782069860236 | atagen | 2026-10-10 12:44 UTC | 121 | .filter_map(|pair| { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 122 | let (key, value) = pair.split_once('=')?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 123 | Some(( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 124 | key.trim().to_ascii_lowercase(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 125 | value.trim().trim_matches('"').to_owned(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 126 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 127 | }) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 128 | .collect(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 129 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 130 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 131 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 132 | fn spoken(authorization: &str) -> &str { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 133 | authorization |
782069860236 | atagen | 2026-10-10 12:44 UTC | 134 | .split_once(' ') |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 135 | .map_or("", |(_, rest)| rest.trim().trim_matches('"')) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 136 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 137 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 138 | fn turned_away(code: &'static str, detail: &'static str) -> Problem { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 139 | Problem::new(StatusCode::UNAUTHORIZED, code, detail) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 140 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 141 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 142 | impl Run { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 143 | pub fn excuses(&self) -> Vec<Excuse> { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 144 | if self.floor.number() < Floor::Nans.number() { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 145 | return Excuse::EVERYDAY.to_vec(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 146 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 147 | Excuse::all() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 148 | .filter(|excuse| !self.household.heard.contains(excuse)) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 149 | .collect() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 150 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 151 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 152 | pub(super) fn errand(&mut self, summoned: bool) -> &'static str { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 153 | if summoned { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 154 | return "She heard a noise."; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 155 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 156 | if self.online.filmed_at.is_some() |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 157 | && self.chance( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 158 | self.decision("viral", "Has a neighbour already sent Mum the footage?"), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 159 | VIRAL_ERRAND, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 160 | ) |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 161 | { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 162 | return "A neighbour has sent her something."; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 163 | } |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 164 | let errands = if self.floor == Floor::Nans { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 165 | CHRISTMAS_ERRANDS |
782069860236 | atagen | 2026-10-10 12:44 UTC | 166 | } else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 167 | BEDROOM_ERRANDS |
782069860236 | atagen | 2026-10-10 12:44 UTC | 168 | }; |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 169 | let weights = vec![1; errands.len()]; |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 170 | let i = self.oracle.pick( |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 171 | self.decision("errand", "What has brought Mum to the door?"), |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 172 | &weights, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 173 | &errands, |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 174 | ); |
3f9091557ec3 | atagen | 2026-10-11 11:43 UTC | 175 | errands[i] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 176 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 177 | |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 178 | /// Mum answers every request on the run until she has been given something she believes. |
782069860236 | atagen | 2026-10-10 12:44 UTC | 179 | pub fn answer_door(&mut self, authorization: Option<&str>) -> Result<(), Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 180 | let Some(visit) = &self.household.mum else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 181 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 182 | }; |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 183 | let digest = self.floor == Floor::Nans; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 184 | let challenge = if digest { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 185 | format!("Digest realm=\"household\", nonce=\"{}\"", visit.nonce) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 186 | } else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 187 | "Excuse realm=\"household\"".to_owned() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 188 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 189 | let result = match authorization { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 190 | None => Err(self.knock()), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 191 | Some(authorization) => self.hear(authorization, digest), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 192 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 193 | if self.ended.is_some() { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 194 | return result; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 195 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 196 | result.map_err(|problem| problem.header(header::WWW_AUTHENTICATE, &challenge)) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 197 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 198 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 199 | /// The first knock is free. Every one after it is a strike. |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 200 | fn knock(&mut self) -> Problem { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 201 | let Some(visit) = &mut self.household.mum else { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 202 | unreachable!("knock is only called while Mum is at the door"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 203 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 204 | let errand = visit.errand; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 205 | if !std::mem::replace(&mut visit.knocked, true) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 206 | self.touch(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 207 | return Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 208 | StatusCode::UNAUTHORIZED, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 209 | "someone-at-the-door", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 210 | format!("Someone is at the door. {errand}"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 211 | ) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 212 | .with("inventory", self.path("/inventory")); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 213 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 214 | self.strike( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 215 | Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 216 | StatusCode::UNAUTHORIZED, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 217 | "knocking-again", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 218 | format!("Mum is knocking again. {errand}"), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 219 | ), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 220 | Cause::Opened, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 221 | ) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 222 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 223 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 224 | fn hear(&mut self, authorization: &str, digest: bool) -> Result<(), Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 225 | if is_truth(spoken(authorization)) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 226 | self.confess(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 227 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 228 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 229 | if parse_credentials(authorization, Scheme::Basic).is_some() { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 230 | return Err(self.mum_strike(turned_away( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 231 | "basic", |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 232 | "Mum does not accept Basic authentication. Nobody should.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 233 | ))); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 234 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 235 | let said = if digest { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 236 | self.digest_username(authorization)? |
782069860236 | atagen | 2026-10-10 12:44 UTC | 237 | } else { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 238 | parse_credentials(authorization, Scheme::Excuse) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 239 | .unwrap_or_default() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 240 | .to_owned() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 241 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 242 | if is_truth(&said) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 243 | self.confess(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 244 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 245 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 246 | let excuse = Excuse::parse(&said); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 247 | let true_now = self.body.conditions.pulled_muscle && excuse == Some(Excuse::PulledAMuscle); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 248 | if digest && !true_now && excuse.is_some_and(|e| self.household.heard.contains(&e)) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 249 | self.standing.shame += 3; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 250 | return Err(self.mum_strike(turned_away( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 251 | "excuse-replayed", |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 252 | "Mum has heard that one before. She would have preferred the truth.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 253 | ))); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 254 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 255 | if let Some(excuse) = excuse.filter(|e| true_now || self.excuses().contains(e)) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 256 | self.household.heard.push(excuse); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 257 | self.leave_door(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 258 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 259 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 260 | self.standing.shame += 3; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 261 | Err(self.mum_strike(turned_away( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 262 | "excuse-rejected", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 263 | if digest { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 264 | "Mum has not heard that one before. She does not believe it. She would have preferred the truth." |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 265 | } else { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 266 | "Mum has not heard that one before. She does not believe it." |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 267 | }, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 268 | ))) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 269 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 270 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 271 | fn digest_username(&mut self, authorization: &str) -> Result<String, Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 272 | let Some(mut params) = digest_params(authorization) else { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 273 | return Err(self.mum_strike(turned_away( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 274 | "digest-required", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 275 | "Mum has started using Digest authentication.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 276 | ))); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 277 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 278 | let current = self |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 279 | .household |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 280 | .mum |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 281 | .as_ref() |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 282 | .is_some_and(|visit| params.get("nonce") == Some(&visit.nonce)); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 283 | if !current { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 284 | return Err(self.mum_strike(turned_away( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 285 | "stale-nonce", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 286 | "That was a different conversation.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 287 | ))); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 288 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 289 | Ok(params.remove("username").unwrap_or_default()) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 290 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 291 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 292 | fn confess(&mut self) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 293 | self.standing.shame += 10; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 294 | self.leave_door(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 295 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 296 | |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 297 | fn mum_strike(&mut self, problem: Problem) -> Problem { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 298 | self.strike(problem, Cause::Caught) |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 299 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 300 | |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 301 | fn strike(&mut self, problem: Problem, cause: Cause) -> Problem { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 302 | self.touch(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 303 | let Some(visit) = &mut self.household.mum else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 304 | return problem; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 305 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 306 | visit.strikes += 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 307 | if visit.strikes < PATIENCE { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 308 | return problem; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 309 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 310 | self.end(cause) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 311 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 312 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 313 | fn leave_door(&mut self) { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 314 | self.household.mum = None; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 315 | self.standing.suspicion = 0; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 316 | self.notices.push(Notice::MumSatisfied); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 317 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 318 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 319 | } |