an http based roguelike rpg about jelqing
Blame: src/game/forum.rs
782069860236 | atagen | 2026-10-10 12:44 UTC | 1 | use axum::http::{StatusCode, header}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 2 | use serde_json::{Value, json}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 3 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 4 | use super::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 5 | Cause, Elder, Floor, Outcome, Run, Story, |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 6 | balance::{EXAGGERATION, MEDITATION_ODDS, PATIENCE}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 7 | body::exaggeration, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 8 | honest, parse_credentials, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 9 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 10 | use crate::{headers::X_FORUM_NOTE, problem::Problem}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 11 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 12 | pub const FORUM_THREAD: &str = "/forum/threads/2009"; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 13 | pub const ELDER_LAST_MODIFIED: &str = "Sun, 14 Jun 2009 03:12:00 GMT"; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 14 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | const SPREADSHEET: &str = "\ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | date,length,girth,technique,notes,honest? |
782069860236 | atagen | 2026-10-10 12:44 UTC | 17 | 2007-01-03,7.50,5.50,wet,baseline,no |
782069860236 | atagen | 2026-10-10 12:44 UTC | 18 | 2007-06-11,7.50,5.50,wet,feeling fuller,no |
782069860236 | atagen | 2026-10-10 12:44 UTC | 19 | 2008-01-02,7.50,5.50,dry,new routine,no |
782069860236 | atagen | 2026-10-10 12:44 UTC | 20 | 2008-09-19,7.50,5.50,uli,PUT is idempotent. do not use PUT.,no |
782069860236 | atagen | 2026-10-10 12:44 UTC | 21 | 2009-06-14,7.50,5.50,wet,progress is slow but real,no |
782069860236 | atagen | 2026-10-10 12:44 UTC | 22 | "; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 23 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 24 | pub fn forum_thread() -> Value { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 25 | json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 26 | "title": "The definitive jelqing FAQ (updated 2009)", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 27 | "posts": [ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 28 | { "author": "TheElder", "body": "Warm up. Always warm up. A cold jelq is a 412 waiting to happen." }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 29 | { "author": "TheElder", "body": "Keep EQ between 50 and 70. Above 70 you are gambling. Above 90 you are a cautionary tale." }, |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 30 | { "author": "newbie_2009", "body": "everyone keeps saying uli. who is uli" }, |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 31 | { "author": "TheElder", "body": "uli was a member here. He posted the technique in 2001 and never posted again. Some say he ascended. The search function says his account is gone." }, |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 32 | { "author": "TheElder", "body": "We do not say his name in vain. We say it in girth." }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 33 | { "author": "newbie_2009", "body": "I have been sending PUT for three weeks and nothing has changed." }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 34 | { "author": "TheElder", "body": "PUT is idempotent. Read the spec." }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 35 | { "author": "TheElder", "body": "Members verify with a Ruler. Proxy-Authorization, inches, no rounding up. We can tell." }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 36 | { "author": "throwaway_77", "body": "my doctor said i was normal. i didnt believe him. i still dont know what he meant by bearer" }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 37 | { "author": "TheElder", "body": "My numbers are in my spreadsheet. They have not changed since 2009. Nothing about me has changed since 2009." }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 38 | ], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 39 | }) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 40 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 41 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 42 | fn verification(detail: &str) -> Problem { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 43 | Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 44 | StatusCode::PROXY_AUTHENTICATION_REQUIRED, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 45 | "verification-required", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 46 | detail, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 47 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 48 | .header(header::PROXY_AUTHENTICATE, "Ruler realm=\"forum\"") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 49 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 51 | impl Run { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 52 | pub(super) fn branch_offer(&self) -> Outcome { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 53 | let forum = self.path("/branches/forum"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 54 | let close = self.path("/branches/close-tab"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 55 | Outcome::json( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 56 | StatusCode::MULTIPLE_CHOICES, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 57 | json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 58 | "detail": "A browser tab is open. It has been open for some time.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 59 | "choices": [ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 60 | { "href": forum, "method": "POST", "title": "Read the forum" }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 61 | { "href": close, "method": "POST", "title": "Close the tab" }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 62 | ], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 63 | }), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 64 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 65 | .header( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 66 | header::LINK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 67 | format!( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 68 | "<{forum}>; rel=\"alternate\"; title=\"Read the forum\"; allow=\"POST\", <{close}>; rel=\"alternate\"; title=\"Close the tab\"; allow=\"POST\"" |
782069860236 | atagen | 2026-10-10 12:44 UTC | 69 | ), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 70 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 71 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 72 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 73 | pub fn choose(&mut self, choice: &str) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 74 | if self.story != Story::Pending { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 75 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 76 | StatusCode::CONFLICT, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 77 | "no-decision-pending", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 78 | "There is no decision pending.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 79 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 80 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 81 | let (story, location, detail) = match choice { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 82 | "forum" => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | self.shame += 3; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 84 | let taught = self.chance(MEDITATION_ODDS); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 85 | self.meditation_taught |= taught; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 86 | let detail = if taught { |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 87 | "The thread is from 2009. A technique called uli is discussed at length. Among the replies, a post teaches a way of breathing that lowers EQ." |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 88 | } else { |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 89 | "The thread is from 2009. A technique called uli is discussed at length." |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 90 | }; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 91 | (Story::ReadForum, self.path("/techniques"), detail) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 92 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 93 | "close-tab" => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 94 | self.suspicion = 0; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 95 | ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 96 | Story::ClosedTab, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 97 | self.path(""), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 98 | "The tab is closed. Nobody saw it.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 99 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 101 | _ => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 102 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 103 | StatusCode::NOT_FOUND, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 104 | "no-such-choice", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | "That was not one of the choices.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | self.story = story; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | Ok( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | Outcome::json(StatusCode::SEE_OTHER, json!({ "detail": detail })) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | .header(header::LOCATION, location), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 114 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 115 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 116 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 117 | fn elder_strike(&mut self, problem: Problem) -> Problem { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 118 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 119 | let Elder::Unverified { strikes } = &mut self.elder else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 120 | return problem; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 121 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 122 | *strikes += 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 123 | if *strikes < PATIENCE { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 124 | return problem; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 125 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 126 | self.end(Cause::Banned) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 127 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 128 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 129 | /// Failed verification counts toward a ban even on GET, the way repeated bad credentials lock an account. |
782069860236 | atagen | 2026-10-10 12:44 UTC | 130 | fn verify_member(&mut self, proxy_authorization: Option<&str>) -> Result<(), Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 131 | if !matches!(self.elder, Elder::Unverified { .. }) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 132 | return Ok(()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 133 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 134 | let Some(credentials) = proxy_authorization else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 135 | return Err(verification("The forum requires verification.")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 136 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 137 | let Some(claimed) = |
782069860236 | atagen | 2026-10-10 12:44 UTC | 138 | parse_credentials(credentials, "ruler").and_then(|v| v.parse::<f64>().ok()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 139 | else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 140 | return Err(verification("The forum requires verification, in inches.")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 141 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 142 | let actual = self.current_length(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 143 | if claimed >= actual + EXAGGERATION { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 144 | self.shame += 2; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 145 | return Err(self.elder_strike(exaggeration())); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 146 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 147 | if !honest(claimed, actual) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 148 | self.shame += 1; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 149 | return Err(self.elder_strike(verification("Verification failed. The forum can tell."))); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 150 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 151 | self.elder = Elder::Verified; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 152 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 153 | Ok(()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 154 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 155 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 156 | pub fn elder( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 157 | &mut self, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 158 | proxy_authorization: Option<&str>, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 159 | if_modified_since: Option<&str>, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 160 | ) -> Result<Outcome, Problem> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 161 | if self.floor != Floor::Forum { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 162 | return Err(Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 163 | StatusCode::NOT_FOUND, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 164 | "elder-absent", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 165 | "The Elder only posts on the forum.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 166 | )); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 167 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 168 | self.verify_member(proxy_authorization)?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 169 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 170 | let last_modified = |
782069860236 | atagen | 2026-10-10 12:44 UTC | 171 | httpdate::parse_http_date(ELDER_LAST_MODIFIED).expect("valid constant date"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 172 | let current = if_modified_since |
782069860236 | atagen | 2026-10-10 12:44 UTC | 173 | .and_then(|d| httpdate::parse_http_date(d).ok()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 174 | .is_some_and(|since| since >= last_modified); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 175 | if current { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 176 | if self.elder != Elder::Beaten { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 177 | self.elder = Elder::Beaten; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 178 | self.touch(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 179 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 180 | return Ok(Outcome::empty(StatusCode::NOT_MODIFIED) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 181 | .header(header::LAST_MODIFIED, ELDER_LAST_MODIFIED)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 182 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 183 | let spreadsheet = Outcome::raw(StatusCode::OK, "text/csv; header=present", SPREADSHEET) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 184 | .header(header::LAST_MODIFIED, ELDER_LAST_MODIFIED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 185 | if self.filmed_at.is_some() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 186 | return Ok(spreadsheet.header(X_FORUM_NOTE, "We have seen the footage.")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 187 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 188 | Ok(spreadsheet) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 189 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 190 | } |