chiark / gitweb /
wip new game joining
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Nov 2020 12:17:01 +0000 (12:17 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Nov 2020 12:17:01 +0000 (12:17 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otter.rs
src/cmdlistener.rs
src/spec.rs

index e22030dd2a70c21cb44468e336e99761f672daa9..cff7739d2d65250002e1048579783b05f4a50b43 100644 (file)
@@ -12,10 +12,11 @@ use std::cell::RefCell;
 use std::cell::Cell;
 
 type E = anyhow::Error;
-type Insn = MgmtGameInstruction;
-type Resp = MgmtGameResponse;
+type Insn = MgmtGameInstruction; // xxx MGI
+type Resp = MgmtGameResponse; // xxx MGR
 type AS = AccountScope;
 type APE = ArgumentParseError;
+type TP = TablePermission;
 
 use argparse::action::ParseResult::Parsed;
 
@@ -354,38 +355,39 @@ fn connect(ma: &MainOpts) -> Conn {
   chan
 }
 
-const PLAYER_ALWAYS_PERMS : &[Perm] = [
+const PLAYER_ALWAYS_PERMS : &[TablePermission] = &[
   TP::TestExistence,
   TP::ViewPublic,
   TP::AddPlayer,
 ];
 
-const PLAYER_DEFAULT_PERMS : &[Perm] = [
-      TP::ChangePiecse
+const PLAYER_DEFAULT_PERMS : &[TablePermission] = &[
+  TP::ChangePieces,
 ];
 
 fn setup_table(ma: &MainOpts, chan: &mut ConnForGame,
                spec: &TableSpec, purge_old_players: bool) -> Result<(),AE> {
-  let TableSpec { players, player_perms, timezone } = spec;
+  let TableSpec { players, player_perms, acl } = spec;
   let mut player_perms = player_perms.clone()
-    .unwrap_or(PLAYER_DEFAULT_PERMS.iter().collect());
+    .unwrap_or(PLAYER_DEFAULT_PERMS.iter().cloned().collect());
   player_perms.extend(PLAYER_ALWAYS_PERMS.iter());
 
-  let mut acl =
+  let mut acl : RawAcl<_> =
     players.iter().map(|tps| AclEntry {
-      account_glob: tps.account_glob();
+      account_glob: tps.account_glob(),
       allow: player_perms.clone(),
-      deny: default()
+      deny: default(),
     })
     .chain(
-      spec.acl.iter()
+      spec.acl.ents.iter().cloned()
     )
     .collect();
 
+  let acl = acl.try_into()?;
+
   let mut insns = vec![];
-  insns.push(MGI::ClearLog);
-  insns.push(MGI::SetACL { acl });
-  isnns.push(MGI::SetTimezone { tz: timezone.clone() });
+  insns.push(Insn::ClearLog);
+  insns.push(Insn::SetACL { acl });
 
 /*
 
index d3e7ad2b37553c9d1720785446224bb970047858..cc1454f159c3559e926f9b2397b12d54560e0091 100644 (file)
@@ -502,6 +502,18 @@ fn execute_game_insn<'cs, 'igr, 'ig : 'igr>(
        Fine, ig_g)
     },
 
+    ClearLog => {
+      let ag = AccountsGuard::lock();
+      let (ig, _) = cs.check_acl(&ag, ig, PCH::Instance, &[TP::Super])?;
+      ig.gs.log.clear();
+      (U{ pcs: vec![ ],
+          log: vec![ LogEntry {
+            html: Html(format!("{} cleared the log", &who)),
+          } ],
+          raw: None },
+       Fine, ig)
+    },
+
     SetACL { acl } => {
       let ag = AccountsGuard::lock();
       let (ig, _) = cs.check_acl(&ag, ig, PCH::Instance, &[TP::Super])?;
index e5b9815aa719572a48b0e3e49768c8adc2686274..04c2f1e7feb3264c4e2331e3dfcd88fbb30f2055 100644 (file)
@@ -74,7 +74,7 @@ pub enum TablePlayerSpec {
   AllLocal,
 }
 
-type RawAcl<Perm> = Vec<AclEntry<Perm>>;
+pub type RawAcl<Perm> = Vec<AclEntry<Perm>>;
 
 #[derive(Debug,Clone)]
 #[derive(Deserialize)]
@@ -270,7 +270,7 @@ pub mod implementation {
   }
 
   impl TablePlayerSpec {
-    fn account_glob(&self) -> String {
+    pub fn account_glob(&self) -> String {
       fn scope_glob(scope: AccountScope) -> String {
         let mut out = "".to_string();
         scope.display_name(&["*"], |s| Ok::<_,Impossible>(out += s)).unwrap();