an http based roguelike rpg about jelqing
Blame: src/http/runs.rs
782069860236 | atagen | 2026-10-10 12:44 UTC | 1 | //! The resources under `/runs/{id}`. |
782069860236 | atagen | 2026-10-10 12:44 UTC | 2 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 3 | use axum::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 4 | Json, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 5 | http::{StatusCode, header}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 6 | response::{IntoResponse, Response}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 7 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 8 | use serde_json::{Value, json}; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 9 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 10 | use super::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 11 | ctx::Ctx, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 12 | inventory::{delete_item, get_inventory, get_item}, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 13 | parse::{parse_intensity, parse_techniques}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 14 | resource::{Resource, Verb}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | response::respond, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | run::{Greeting, RunResource, Scope}, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 17 | shaft::{get_foreskin, get_length}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 18 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 19 | use crate::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 20 | game::{ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 21 | Branch, Cause, Floor, Grip, Item, LUBRICANTS, Lube, PatchOp, Run, Technique, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 22 | balance::{EQ_BAND, VIEWS_PER_SECOND}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 23 | }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 24 | headers::ACCEPT_PATCH, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 25 | problem::Problem, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 26 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 27 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 28 | const fn home(verbs: &'static [Verb<Run>]) -> RunResource { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 29 | RunResource { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 30 | scope: Scope::Home, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 31 | resource: Resource::new(verbs), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 32 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 33 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 34 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 35 | const fn pockets(verbs: &'static [Verb<Run>]) -> RunResource { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 36 | RunResource { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 37 | scope: Scope::Pockets, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 38 | resource: Resource::new(verbs), |
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 not_in_clinic(run: &Run) -> bool { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 43 | run.floor != Floor::Clinic |
782069860236 | atagen | 2026-10-10 12:44 UTC | 44 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 45 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 46 | pub static RUN: RunResource = RunResource { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 47 | scope: Scope::Home, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 48 | resource: Resource::patchable(&[ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 49 | Verb::new("GET", get_run), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 50 | Verb::new("JELQ", jelq).only_when(not_in_clinic, "JELQ is not performed in the clinic."), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 51 | Verb::new("HOLD", hold_run).only_when( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 52 | Run::can_hold, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 53 | "HOLD is only available above 70 EQ or at 2 stamina or less.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 54 | ), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 55 | Verb::new("PUT", put_run), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 56 | Verb::new("PATCH", patch_run), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 57 | Verb::new("DELETE", delete_run), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 58 | Verb::new("TRACE", trace_run), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 59 | ]), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 60 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 61 | pub static LENGTH: RunResource = home(&[Verb::new("GET", get_length)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 62 | pub static FORESKIN: RunResource = home(&[ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 63 | Verb::new("GET", get_foreskin), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 64 | Verb::new("DELETE", delete_foreskin), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 65 | ]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 66 | pub static INVENTORY: RunResource = pockets(&[Verb::new("GET", get_inventory)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 67 | pub static ITEM: RunResource = |
782069860236 | atagen | 2026-10-10 12:44 UTC | 68 | pockets(&[Verb::new("GET", get_item), Verb::new("DELETE", delete_item)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 69 | pub static TECHNIQUES: RunResource = home(&[Verb::new("GET", get_techniques)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 70 | pub static DRAWER: RunResource = home(&[Verb::new("POST", search_drawer)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 71 | pub static BRANCH: RunResource = home(&[Verb::new("POST", choose_branch)]); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 72 | pub static KITCHEN: RunResource = home(&[Verb::new("POST", raid_kitchen)]); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 73 | pub static MELON: RunResource = home(&[Verb::new("POST", commit_melon)]); |
a11497af08aa | atagen | 2026-10-13 12:04 UTC | 74 | pub static THREAD: RunResource = pockets(&[Verb::new("GET", get_thread)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 75 | pub static FLOOR: RunResource = |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 76 | home(&[Verb::new("GET", get_floor), Verb::new("POST", leave_floor)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 77 | pub static SHOP: RunResource = home(&[Verb::new("GET", get_shop)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 78 | pub static BUY: RunResource = home(&[Verb::new("POST", buy)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 79 | pub static PORTAL: RunResource = pockets(&[ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 80 | Verb::new("GET", get_portal), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 81 | Verb::new("POST", accept_portal), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 82 | ]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | pub static ELDER: RunResource = home(&[Verb::new("GET", get_elder)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 84 | pub static GRIP: RunResource = home(&[Verb::new("GET", get_grip)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 85 | pub static DIAGNOSIS: RunResource = pockets(&[Verb::new("GET", get_diagnosis)]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 86 | pub static FOOTAGE: RunResource = pockets(&[ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 87 | Verb::new("GET", get_footage), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 88 | Verb::refused( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 89 | "DELETE", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 90 | "The footage has been cached by intermediaries. It cannot be deleted.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 91 | ), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 92 | ]); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 93 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 94 | fn get_run(run: &mut Run, ctx: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 95 | if ctx |
782069860236 | atagen | 2026-10-10 12:44 UTC | 96 | .header(header::ACCEPT) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 97 | .is_some_and(|accept| accept.contains("reassurance")) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 98 | { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 99 | return Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | StatusCode::NOT_ACCEPTABLE, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 101 | "no-reassurance", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 102 | "The server does not produce reassurance.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 103 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 104 | .into_response(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | StatusCode::OK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | [(header::ETAG, run.etag())], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | Json(run.view()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | .into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 114 | fn jelq(run: &mut Run, ctx: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 115 | let parsed = parse_techniques(run, ctx).and_then(|techniques| { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 116 | let intensity = parse_intensity(ctx)?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 117 | let lube = Lube::from_content_type(ctx.header(header::CONTENT_TYPE))?; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 118 | Ok((techniques, intensity, lube)) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 119 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 120 | match parsed { |
a6caa2f99786 | atagen | 2026-10-12 10:38 UTC | 121 | Ok((techniques, intensity, lube)) => respond(run.jelq(&techniques, intensity, lube)), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 122 | Err(problem) => problem.into_response(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 123 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 124 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 125 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 126 | fn put_run(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 127 | run.put().into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 128 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 129 | |
a6caa2f99786 | atagen | 2026-10-12 10:38 UTC | 130 | fn hold_run(run: &mut Run, _: &Ctx) -> Response { |
a6caa2f99786 | atagen | 2026-10-12 10:38 UTC | 131 | respond(run.hold()) |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 132 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 133 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 134 | fn patch_run(run: &mut Run, ctx: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 135 | let is_patch = ctx |
782069860236 | atagen | 2026-10-10 12:44 UTC | 136 | .header(header::CONTENT_TYPE) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 137 | .is_some_and(|ct| ct.starts_with("application/json-patch+json")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 138 | if !is_patch { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 139 | return Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 140 | StatusCode::UNSUPPORTED_MEDIA_TYPE, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 141 | "patch-format", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 142 | "Patches are accepted as application/json-patch+json.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 143 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 144 | .header(ACCEPT_PATCH, "application/json-patch+json") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 145 | .into_response(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 146 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 147 | match serde_json::from_slice::<Vec<PatchOp>>(ctx.body()) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 148 | Ok(ops) => respond(run.patch(&ops)), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 149 | Err(_) => Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 150 | StatusCode::BAD_REQUEST, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 151 | "malformed-patch", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 152 | "The patch could not be parsed.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 153 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 154 | .into_response(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 155 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 156 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 157 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 158 | fn delete_run(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 159 | run.end(Cause::Abandoned); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 160 | StatusCode::NO_CONTENT.into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 161 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 162 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 163 | fn trace_run(run: &mut Run, ctx: &Ctx) -> Response { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 164 | run.trace(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 165 | ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 166 | StatusCode::OK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 167 | [(header::CONTENT_TYPE, "message/http")], |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 168 | ctx.echo(), |
ec6fd4bb5b60 | atagen | 2026-10-11 04:34 UTC | 169 | ) |
ec6fd4bb5b60 | atagen | 2026-10-11 04:34 UTC | 170 | .into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 171 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 172 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 173 | fn delete_foreskin(run: &mut Run, ctx: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 174 | respond(run.delete_foreskin(ctx.header(header::IF_MATCH))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 175 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 176 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 177 | fn get_techniques(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 178 | let listed: Vec<Value> = Technique::ALL |
782069860236 | atagen | 2026-10-10 12:44 UTC | 179 | .into_iter() |
880b29a0c11e | atagen | 2026-10-13 09:27 UTC | 180 | .map(|t| t.describe(run.knows(t))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 181 | .collect(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 182 | Json(json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 183 | "usage": format!("JELQ {}?technique=<name>[,<name>]&intensity=<1-10>", run.path("")), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 184 | "lubricant": "Declared with Content-Type.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 185 | "lubricants": LUBRICANTS, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 186 | "eq_band": [EQ_BAND.start(), EQ_BAND.end()], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 187 | "techniques": listed, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 188 | })) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 189 | .into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 190 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 191 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 192 | fn search_drawer(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 193 | respond(run.search_drawer()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 194 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 195 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 196 | fn choose_branch(run: &mut Run, ctx: &Ctx) -> Response { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 197 | match ctx.param("choice").parse::<Branch>() { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 198 | Ok(choice) => respond(run.choose(choice)), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 199 | Err(()) => Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 200 | StatusCode::NOT_FOUND, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 201 | "no-such-choice", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 202 | "That was not one of the choices.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 203 | ) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 204 | .into_response(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 205 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 206 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 207 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 208 | fn get_floor(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 209 | Json(run.floor_view()).into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 210 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 211 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 212 | fn leave_floor(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 213 | respond(run.advance()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 214 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 215 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 216 | fn get_shop(run: &mut Run, _: &Ctx) -> Response { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 217 | respond(run.browse_shop().map(Json)) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 218 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 219 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 220 | fn buy(run: &mut Run, ctx: &Ctx) -> Response { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 221 | respond(run.buy(Item::parse(ctx.param("item")))) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 222 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 223 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 224 | fn raid_kitchen(run: &mut Run, _: &Ctx) -> Response { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 225 | respond(run.raid_kitchen()) |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 226 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 227 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 228 | fn commit_melon(run: &mut Run, _: &Ctx) -> Response { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 229 | respond(run.commit_melon()) |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 230 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 231 | |
a11497af08aa | atagen | 2026-10-13 12:04 UTC | 232 | fn get_thread(run: &mut Run, _: &Ctx) -> Response { |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 233 | respond(run.read_thread()) |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 234 | } |
b85a0d4536c3 | atagen | 2026-10-11 08:50 UTC | 235 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 236 | fn get_portal(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 237 | Json(json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 238 | "terms": "By connecting you agree that the hotel is not responsible for anything that happens in this room, and that it does not want to know.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 239 | "accept": { "href": run.path("/portal"), "method": "POST" }, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 240 | })) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 241 | .into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 242 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 243 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 244 | fn accept_portal(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 245 | respond(run.accept_terms()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 246 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 247 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 248 | fn get_elder(run: &mut Run, ctx: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 249 | respond(run.elder( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 250 | ctx.header(header::PROXY_AUTHORIZATION), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 251 | ctx.header(header::IF_MODIFIED_SINCE), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 252 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 253 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 254 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 255 | fn requested_grip(ctx: &Ctx) -> Option<Grip> { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 256 | let connection = ctx.header(header::CONNECTION)?.to_ascii_lowercase(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 257 | if !connection.split(',').any(|token| token.trim() == "upgrade") { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 258 | return None; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 259 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 260 | ctx.header(header::UPGRADE)? |
782069860236 | atagen | 2026-10-10 12:44 UTC | 261 | .split(',') |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 262 | .find_map(|protocol| protocol.trim().parse::<Grip>().ok()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 263 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 264 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 265 | fn get_grip(run: &mut Run, ctx: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 266 | if let Some(grip) = requested_grip(ctx) { |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 267 | if let Err(problem) = run.set_grip(grip) { |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 268 | return problem.into_response(); |
058650ec79d6 | atagen | 2026-10-12 10:49 UTC | 269 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 270 | let mut response = ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 271 | StatusCode::SWITCHING_PROTOCOLS, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 272 | [ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 273 | (header::UPGRADE, grip.name()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 274 | (header::CONNECTION, "upgrade"), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 275 | ], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 276 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 277 | .into_response(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 278 | response.extensions_mut().insert(Greeting(format!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 279 | "You are now jelqing {}.\r\n", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 280 | grip.name() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 281 | ))); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 282 | return response; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 283 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 284 | let detail = match ctx.header(header::UPGRADE) { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 285 | Some(protocol) => { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 286 | format!("The server does not know the {protocol} grip. Grips are protocols.") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 287 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 288 | None => "Grips are protocols. Change grip by upgrading the connection.".to_owned(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 289 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 290 | ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 291 | StatusCode::OK, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 292 | [(header::UPGRADE, "overhand, underhand")], |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 293 | Json(json!({ "grip": run.grip().name(), "detail": detail })), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 294 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 295 | .into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 296 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 297 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 298 | fn get_diagnosis(run: &mut Run, ctx: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 299 | respond(run.diagnose( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 300 | ctx.header(header::AUTHORIZATION), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 301 | ctx.header(header::IF_NONE_MATCH), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 302 | )) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 303 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 304 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 305 | fn get_footage(run: &mut Run, _: &Ctx) -> Response { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 306 | let Some((filmed, age)) = run.footage() else { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 307 | return Problem::new( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 308 | StatusCode::NOT_FOUND, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 309 | "no-footage", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 310 | "There is no footage. Yet.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 311 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 312 | .into_response(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 313 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 314 | ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 315 | [ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 316 | ( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 317 | header::CACHE_CONTROL, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 318 | "public, max-age=31536000, immutable".to_owned(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 319 | ), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 320 | (header::AGE, age.to_string()), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 321 | (header::LAST_MODIFIED, httpdate::fmt_http_date(filmed)), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 322 | ], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 323 | Json(json!({ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 324 | "detail": "A recording. It is grainy. It is unmistakably you. It has been shared.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 325 | "views": 1 + age * VIEWS_PER_SECOND, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 326 | })), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 327 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 328 | .into_response() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 329 | } |