atagen

jelq

public

an http based roguelike rpg about jelqing

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

Blame: src/config.rs

782069860236atagen2026-10-10 12:44 UTC1
use std::time::Duration;
782069860236atagen2026-10-10 12:44 UTC2
3f9091557ec3atagen2026-10-11 11:43 UTC3
use crate::game::oracle::OracleTemplate;
782069860236atagen2026-10-10 12:44 UTC4
use crate::secret::Secret;
782069860236atagen2026-10-10 12:44 UTC5
782069860236atagen2026-10-10 12:44 UTC6
pub struct Config {
782069860236atagen2026-10-10 12:44 UTC7
    pub addr: String,
782069860236atagen2026-10-10 12:44 UTC8
    pub secret: Secret,
782069860236atagen2026-10-10 12:44 UTC9
    pub max_runs: usize,
782069860236atagen2026-10-10 12:44 UTC10
    pub idle_ttl: Duration,
3f9091557ec3atagen2026-10-11 11:43 UTC11
    pub(crate) oracle: OracleTemplate,
782069860236atagen2026-10-10 12:44 UTC12
}
782069860236atagen2026-10-10 12:44 UTC13
782069860236atagen2026-10-10 12:44 UTC14
impl Default for Config {
782069860236atagen2026-10-10 12:44 UTC15
    fn default() -> Self {
782069860236atagen2026-10-10 12:44 UTC16
        Self {
782069860236atagen2026-10-10 12:44 UTC17
            addr: "127.0.0.1:6969".into(),
782069860236atagen2026-10-10 12:44 UTC18
            secret: Secret::random(),
782069860236atagen2026-10-10 12:44 UTC19
            max_runs: 10_000,
782069860236atagen2026-10-10 12:44 UTC20
            idle_ttl: Duration::from_secs(6 * 60 * 60),
3f9091557ec3atagen2026-10-11 11:43 UTC21
            oracle: OracleTemplate::Rng,
782069860236atagen2026-10-10 12:44 UTC22
        }
782069860236atagen2026-10-10 12:44 UTC23
    }
782069860236atagen2026-10-10 12:44 UTC24
}
782069860236atagen2026-10-10 12:44 UTC25
782069860236atagen2026-10-10 12:44 UTC26
impl Config {
782069860236atagen2026-10-10 12:44 UTC27
    pub fn from_env() -> Self {
782069860236atagen2026-10-10 12:44 UTC28
        let var = |name| std::env::var(name).ok();
782069860236atagen2026-10-10 12:44 UTC29
        let defaults = Self::default();
782069860236atagen2026-10-10 12:44 UTC30
        Self {
782069860236atagen2026-10-10 12:44 UTC31
            addr: var("JELQD_ADDR").unwrap_or(defaults.addr),
782069860236atagen2026-10-10 12:44 UTC32
            secret: var("JELQD_SECRET").map_or(defaults.secret, |s| Secret::new(s.into_bytes())),
3f9091557ec3atagen2026-10-11 11:43 UTC33
            oracle: match var("JELQD_ORACLE").as_deref() {
3f9091557ec3atagen2026-10-11 11:43 UTC34
                Some("clm") => OracleTemplate::Clm {
3f9091557ec3atagen2026-10-11 11:43 UTC35
                    url: var("JELQD_CLM_URL")
3f9091557ec3atagen2026-10-11 11:43 UTC36
                        .unwrap_or_else(|| "http://127.0.0.1:8700/v1/systemone".into()),
3f9091557ec3atagen2026-10-11 11:43 UTC37
                },
3f9091557ec3atagen2026-10-11 11:43 UTC38
                _ => defaults.oracle,
3f9091557ec3atagen2026-10-11 11:43 UTC39
            },
782069860236atagen2026-10-10 12:44 UTC40
            ..defaults
782069860236atagen2026-10-10 12:44 UTC41
        }
782069860236atagen2026-10-10 12:44 UTC42
    }
782069860236atagen2026-10-10 12:44 UTC43
}