chiark / gitweb /
fake rng: Rename things to be clearer about API
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Mar 2021 18:30:30 +0000 (18:30 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Mar 2021 18:30:45 +0000 (18:30 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
daemon/session.rs
src/config.rs
src/fake-rng.rs

index c167326b0af444e17504e0ddea995ecf06a32722..09fe887f87bfa87effe8277875c33bcf0bf04a45 100644 (file)
@@ -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
     }
   }
index aac7ac8d8befa6d4209ce4d498be082d87079df4..41ab409bb93a1843873585d53e8248f57a2a0896 100644 (file)
@@ -208,7 +208,7 @@ fn session_inner(form: Json<SessionForm>,
       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(),
index 252ba54cba55cdecfee7d54ba048a67ad7ee4670..1936e5a284caae1d407c51d333327146e7bf5008 100644 (file)
@@ -64,7 +64,7 @@ pub struct ServerConfig {
   pub sendmail: String,
   pub debug_js_inject: Arc<String>,
   pub check_bundled_sources: bool,
-  pub fake_rng: RngWrap,
+  pub game_rng: RngWrap,
 }
 
 impl TryFrom<ServerConfigSpec> for WholeServerConfig {
@@ -79,7 +79,7 @@ impl TryFrom<ServerConfigSpec> 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<ServerConfigSpec> 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),
index be4d8e4d1f88a1e36a43f22f2291b3afe7202246..dbce35aab1b90917ec1d483b1fb68993ff28770c 100644 (file)
@@ -11,7 +11,7 @@ use parking_lot::Mutex;
 pub struct FakeRngSpec(Option<Vec<String>>);
 
 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<String>, _: AuthorisationSuperuser) {
+  pub fn set_fake(&self, v: Vec<String>, _: 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<T:Copy>(&self, slice: &mut [T]) { match self.next() {
+  pub fn shuffle<T:Copy>(&self, slice: &mut [T]) { match self.next_fake() {
     None => {
       let mut rng = thread_rng();
       slice.shuffle(&mut rng);