From: Ian Jackson Date: Sat, 13 Mar 2021 18:30:30 +0000 (+0000) Subject: fake rng: Rename things to be clearer about API X-Git-Tag: otter-0.4.0~106 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=ba8edecf835872187b1bc954a2807aea501f2aba;p=otter.git fake rng: Rename things to be clearer about API Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index c167326b..09fe887f 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -219,7 +219,7 @@ fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { MC::LoadFakeRng(ents) => { let superuser = cs.superuser .ok_or(ME::SuperuserAuthorisationRequired)?; - config().fake_rng.set(ents, superuser)?; + config().game_rng.set_fake(ents, superuser)?; Fine } } diff --git a/daemon/session.rs b/daemon/session.rs index aac7ac8d..41ab409b 100644 --- a/daemon/session.rs +++ b/daemon/session.rs @@ -208,7 +208,7 @@ fn session_inner(form: Json, player_info_pane, ptoken: form.ptoken.clone(), links: (&*ig.links).into(), - fake_rng: config().fake_rng.is_fake(), + fake_rng: config().game_rng.is_fake(), load: serde_json::to_string(&DataLoad { players: load_players, last_log_ts: timestamp_abbrev.unwrap_or_default(), diff --git a/src/config.rs b/src/config.rs index 252ba54c..1936e5a2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -64,7 +64,7 @@ pub struct ServerConfig { pub sendmail: String, pub debug_js_inject: Arc, pub check_bundled_sources: bool, - pub fake_rng: RngWrap, + pub game_rng: RngWrap, } impl TryFrom for WholeServerConfig { @@ -79,7 +79,7 @@ impl TryFrom for WholeServerConfig { debug_js_inject_file, check_bundled_sources, fake_rng, } = spec; - let fake_rng = fake_rng.start(); + let game_rng = fake_rng.make_game_rng(); if let Some(cd) = change_directory { env::set_current_dir(&cd) @@ -182,7 +182,7 @@ impl TryFrom for WholeServerConfig { http_port, public_url, sse_wildcard_url, rocket_workers, template_dir, nwtemplate_dir, wasm_dir, bundled_sources, shapelibs, sendmail, - debug_js_inject, check_bundled_sources, fake_rng, + debug_js_inject, check_bundled_sources, game_rng, }; WholeServerConfig { server: Arc::new(server), diff --git a/src/fake-rng.rs b/src/fake-rng.rs index be4d8e4d..dbce35aa 100644 --- a/src/fake-rng.rs +++ b/src/fake-rng.rs @@ -11,7 +11,7 @@ use parking_lot::Mutex; pub struct FakeRngSpec(Option>); impl FakeRngSpec { - pub fn start(self) -> RngWrap { RngWrap( match self.0 { + pub fn make_game_rng(self) -> RngWrap { RngWrap( match self.0 { None => None, Some(ents) => Some(Arc::new(Mutex::new(FakeRng { i: 0, @@ -35,14 +35,14 @@ impl RngWrap { pub fn is_fake(&self) -> bool { self.0.is_some() } #[throws(MgmtError)] - pub fn set(&self, v: Vec, _: AuthorisationSuperuser) { + pub fn set_fake(&self, v: Vec, _: AuthorisationSuperuser) { let mut fake = self.0.as_ref().ok_or(ME::RngIsReal)?.lock(); fake.i = 0; fake.ents = v; } #[throws(as Option)] - fn next(&self) -> String { + fn next_fake(&self) -> String { let mut fake = self.0.as_ref()?.lock(); let e = fake.ents.get(fake.i)?.clone(); fake.i += 1; @@ -50,7 +50,7 @@ impl RngWrap { e } - pub fn shuffle(&self, slice: &mut [T]) { match self.next() { + pub fn shuffle(&self, slice: &mut [T]) { match self.next_fake() { None => { let mut rng = thread_rng(); slice.shuffle(&mut rng);