atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
c4d70621d377d45e3d418ac9197443c1b5d36399
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git

Blame: src/game/clinic.rs

782069860236atagen2026-10-10 12:44 UTC1
use axum::http::{StatusCode, header};
782069860236atagen2026-10-10 12:44 UTC2
use serde_json::json;
782069860236atagen2026-10-10 12:44 UTC3
159f0998263batagen2026-10-12 11:01 UTC4
use super::{Floor, Outcome, Run, body::volume, etag_matches, parse_credentials, round2};
058650ec79d6atagen2026-10-12 10:49 UTC5
use crate::{
058650ec79d6atagen2026-10-12 10:49 UTC6
    headers::{SERVER_TIMING, X_DIAGNOSIS},
058650ec79d6atagen2026-10-12 10:49 UTC7
    problem::Problem,
058650ec79d6atagen2026-10-12 10:49 UTC8
};
782069860236atagen2026-10-10 12:44 UTC9
782069860236atagen2026-10-10 12:44 UTC10
const INTAKE: [&str; 3] = [
782069860236atagen2026-10-10 12:44 UTC11
    "The clinic does not accept excuses.",
782069860236atagen2026-10-10 12:44 UTC12
    "The clinic accepts one token. You have not been carrying it.",
782069860236atagen2026-10-10 12:44 UTC13
    "Be honest.",
782069860236atagen2026-10-10 12:44 UTC14
];
782069860236atagen2026-10-10 12:44 UTC15
782069860236atagen2026-10-10 12:44 UTC16
impl Run {
782069860236atagen2026-10-10 12:44 UTC17
    pub fn diagnose(
782069860236atagen2026-10-10 12:44 UTC18
        &mut self,
782069860236atagen2026-10-10 12:44 UTC19
        authorization: Option<&str>,
782069860236atagen2026-10-10 12:44 UTC20
        if_none_match: Option<&str>,
782069860236atagen2026-10-10 12:44 UTC21
    ) -> Result<Outcome, Problem> {
782069860236atagen2026-10-10 12:44 UTC22
        if self.floor != Floor::Clinic {
782069860236atagen2026-10-10 12:44 UTC23
            let floors = Floor::Clinic.number() - self.floor.number();
782069860236atagen2026-10-10 12:44 UTC24
            return Err(Problem::new(
782069860236atagen2026-10-10 12:44 UTC25
                StatusCode::TOO_EARLY,
782069860236atagen2026-10-10 12:44 UTC26
                "no-appointment",
782069860236atagen2026-10-10 12:44 UTC27
                format!("The clinic's next available appointment is {floors} floors away."),
782069860236atagen2026-10-10 12:44 UTC28
            ));
782069860236atagen2026-10-10 12:44 UTC29
        }
782069860236atagen2026-10-10 12:44 UTC30
        let intake = Problem::new(
782069860236atagen2026-10-10 12:44 UTC31
            StatusCode::UNAUTHORIZED,
782069860236atagen2026-10-10 12:44 UTC32
            "intake",
9683736a2c5eatagen2026-10-10 13:15 UTC33
            "The clinic requires authorisation.",
782069860236atagen2026-10-10 12:44 UTC34
        );
782069860236atagen2026-10-10 12:44 UTC35
        let Some(authorization) = authorization else {
782069860236atagen2026-10-10 12:44 UTC36
            return Err(intake.header(header::WWW_AUTHENTICATE, "Bearer realm=\"clinic\""));
782069860236atagen2026-10-10 12:44 UTC37
        };
782069860236atagen2026-10-10 12:44 UTC38
        let truthful = parse_credentials(authorization, "bearer")
782069860236atagen2026-10-10 12:44 UTC39
            .is_some_and(|token| token.eq_ignore_ascii_case("honesty"));
782069860236atagen2026-10-10 12:44 UTC40
        if !truthful {
782069860236atagen2026-10-10 12:44 UTC41
            let hint = INTAKE[self.clinic.intake_attempts.min(INTAKE.len() - 1)];
782069860236atagen2026-10-10 12:44 UTC42
            self.clinic.intake_attempts += 1;
782069860236atagen2026-10-10 12:44 UTC43
            return Err(intake.header(
782069860236atagen2026-10-10 12:44 UTC44
                header::WWW_AUTHENTICATE,
782069860236atagen2026-10-10 12:44 UTC45
                format!(
782069860236atagen2026-10-10 12:44 UTC46
                    "Bearer realm=\"clinic\", error=\"invalid_token\", error_description=\"{hint}\""
782069860236atagen2026-10-10 12:44 UTC47
                ),
782069860236atagen2026-10-10 12:44 UTC48
            ));
782069860236atagen2026-10-10 12:44 UTC49
        }
782069860236atagen2026-10-10 12:44 UTC50
782069860236atagen2026-10-10 12:44 UTC51
        self.conditions.peyronie = false;
782069860236atagen2026-10-10 12:44 UTC52
        self.conditions.priapism_turns = 0;
782069860236atagen2026-10-10 12:44 UTC53
        let etag = self.origin_etag();
782069860236atagen2026-10-10 12:44 UTC54
        if if_none_match.is_some_and(|inm| etag_matches(inm, &etag)) {
782069860236atagen2026-10-10 12:44 UTC55
            self.clinic.cured = true;
782069860236atagen2026-10-10 12:44 UTC56
            return Ok(Outcome::empty(StatusCode::NOT_MODIFIED)
782069860236atagen2026-10-10 12:44 UTC57
                .header(header::ETAG, etag)
782069860236atagen2026-10-10 12:44 UTC58
                .header(X_DIAGNOSIS, "normal"));
782069860236atagen2026-10-10 12:44 UTC59
        }
782069860236atagen2026-10-10 12:44 UTC60
        if !self.clinic.measured {
782069860236atagen2026-10-10 12:44 UTC61
            self.clinic.measured = true;
782069860236atagen2026-10-10 12:44 UTC62
            if !self.items.ruler {
782069860236atagen2026-10-10 12:44 UTC63
                self.shame += 15;
782069860236atagen2026-10-10 12:44 UTC64
            }
782069860236atagen2026-10-10 12:44 UTC65
        }
159f0998263batagen2026-10-12 11:01 UTC66
        let volume = volume(self.length, self.girth);
058650ec79d6atagen2026-10-12 10:49 UTC67
        let foreskin = self.foreskin.unwrap_or(0.0);
058650ec79d6atagen2026-10-12 10:49 UTC68
        let timing = format!(
058650ec79d6atagen2026-10-12 10:49 UTC69
            "length;dur={:.2}, girth;dur={:.2}, foreskin;dur={foreskin:.2}, volume;desc=\"cubic inches\";dur={volume:.2}",
058650ec79d6atagen2026-10-12 10:49 UTC70
            self.length, self.girth
058650ec79d6atagen2026-10-12 10:49 UTC71
        );
c4d70621d377atagen2026-10-12 11:56 UTC72
        self.clinic.prescribed = true;
c4d70621d377atagen2026-10-12 11:56 UTC73
        self.touch();
782069860236atagen2026-10-10 12:44 UTC74
        Ok(Outcome::json(
782069860236atagen2026-10-10 12:44 UTC75
            StatusCode::OK,
782069860236atagen2026-10-10 12:44 UTC76
            json!({
782069860236atagen2026-10-10 12:44 UTC77
                "diagnosis": "within normal range",
c4d70621d377atagen2026-10-12 11:56 UTC78
                "detail": "Congratulations. You have been cured of a condition you never had. The run is over.",
782069860236atagen2026-10-10 12:44 UTC79
                "measured_length": round2(self.length),
058650ec79d6atagen2026-10-12 10:49 UTC80
                "measured_girth": round2(self.girth),
058650ec79d6atagen2026-10-12 10:49 UTC81
                "volume": round2(volume),
782069860236atagen2026-10-10 12:44 UTC82
                "prescription": "Please stop.",
782069860236atagen2026-10-10 12:44 UTC83
            }),
782069860236atagen2026-10-10 12:44 UTC84
        )
058650ec79d6atagen2026-10-12 10:49 UTC85
        .header(header::ETAG, etag)
058650ec79d6atagen2026-10-12 10:49 UTC86
        .header(SERVER_TIMING, timing))
782069860236atagen2026-10-10 12:44 UTC87
    }
782069860236atagen2026-10-10 12:44 UTC88
}