chiark / gitweb /
wip misc
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 10 Jun 2020 22:09:02 +0000 (23:09 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 10 Jun 2020 22:09:02 +0000 (23:09 +0100)
src/gamestate.rs
src/global.rs
src/instance.rs
src/main.rs
src/pieces.rs
src/testload.rs [new file with mode: 0644]

index 20fdd4e6157a250b457b052391ab2f0c6a559de9..90e614935eb3dd3d3cfe8dfd2c6db1f9aeeb9cc3 100644 (file)
@@ -1,3 +1,4 @@
+
 pub trait Piece {
   fn svg(&self, pr : &PiecedRecord) -> SvgData;
 }
@@ -9,11 +10,14 @@ pub struct PieceRecord {
   held : Option<PlayerRef>,
 }
 
+struct PlayerRecord {
+  nick : String,
+}
 
 #[derive(Debug)]
 pub struct GameState {
   pub pieces : Vec<Rc<PieceRecord>>,
-  pub players : Vec<Rc<PlayerRecord>>,
+  pub players : Vec<PlayerRecord>,
 }
 
 pub struct GameRef (InstanceGuard);
index 33f379637aa324ec9bbb2875939e773c37749063..57210a80e8e4da780e75304ea92649981fd48a11 100644 (file)
@@ -1,7 +1,12 @@
 
+strut InstanceAccess {
+  inst : Rc<Instance>,
+  user : usize,
+}
+
 #[derive(Default)]
 struct Global {
-  instances : RwLock<HashMap<InstanceName, Rc<Instance>>>,
+  tokens : RwLock<HashMap<RawToken, InstanceAccess>,
   // xxx delete instances at some point!
 }
 
@@ -9,21 +14,21 @@ lazy_static! {
   static ref GLOBAL : Global = Default::default();
 }
 
-fn lookup_instance(name : &str) -> Option<Rc<Instance>> {
-  GLOBAL.instances().read().get(name)
+fn lookup_token(s : &str) -> Option<InstanceAccess> {
+  GLOBAL.instances().read().get(s)
 }
-
-#[throws(TE)]
-fn create_instance(name : &str, i : Rc<Instance>) {
+  
+#[throws(E)]
+fn create_instance_access(name : &str, i : Rc<Instance>) {
   let w = GLOBAL.instances().write();
   match w.entry(name) {
-    Occupied(oe) => throw!(TE::InstanceAlreadyExists);
+    Occupied(oe) => throw!(anyhow!("access key alreay defined"));
     Vacant(ve) => ve.insert(i);
   }
 }
 
+/*
 impl<'r> FromParam<'r> for InstanceGuard<'r> {
-  // xxx any additional auth should go here
   type Error = AE;
   #[throws(E)]
   fn from_param(param: &'r RawStr) -> Self {
@@ -34,4 +39,15 @@ impl<'r> FromParam<'r> for InstanceGuard<'r> {
     i.lock(iname)
   }
 }
+*/
+
+impl<'r> FromParam<'r> for InstanceAccess<'r> {
+  type Error = AE;
+  #[throws(E)]
+  fn from_param(param: &'r RawStr) -> Option<Self> {
+    let g = GLOBAL.instances().read();
+    let iname = param.as_str();
+    g.get(iname);
+  }
+}
 
index 0118dfcb48a7a33c9c2358edda359d9943e957d7..ea2e60673dccd9f3934a8b892b2b708e0e39779c 100644 (file)
@@ -3,6 +3,7 @@ const RECENT_BUFFER : usize = 10;
  
 #[derive(Debug)]
 pub struct Instance {
+  mod_token : RawToken,
   g : RwLock<Game>,
   g_notify : Condvar,
 }
index 5bfbde915605bf7a13673f29b90340459c6a5505..3a224773abacfa5c69f666f3284f7d98e5654a03 100644 (file)
@@ -55,8 +55,16 @@ impl Read for TestCounterInner {
   }
 }
 
-#[get("/<instance>")]
-fn updates() -> impl response::Responder<'static> {
+struct MainRenderContext { };
+
+#[post("/<access>")]
+fn mainpage(access : InstanceAccess) -> impl response::Responder<'static> {
+  let c = MainRenderContext { };
+  Template::render("main",&c)
+}
+
+/*
+
   let tc = TestCounterInner { next : 0 };
   let tc = BufReader::new(tc);
   let ch = response::Stream::chunked(tc, 1);
@@ -64,6 +72,7 @@ fn updates() -> impl response::Responder<'static> {
     unwrap();
   response::content::Content(ct,ch)
 }  
+*/
 
 #[get("/_/<leaf>")]
 fn resource(leaf : CheckedResourceLeaf) -> io::Result<NamedFile> {
@@ -72,6 +81,8 @@ fn resource(leaf : CheckedResourceLeaf) -> io::Result<NamedFile> {
 }  
 
 fn main() {
+  
+
   let helmet = SpaceHelmet::default()
     .enable(NoSniff::Enable)
     .enable(Frame::Deny)
index 0f6fa366e6769b514afee17dbad9a1bdace7ae61..8d8da0a82f020288a4a93b0faaee07121fa39593 100644 (file)
@@ -1,6 +1,6 @@
 
 struct Disc {
-  colours : [Colour],
+  colours : Vec<Colour>,
   size : Coord,
 }
 
@@ -12,3 +12,7 @@ impl Piece for Disc {
     ).into_bytes()
   }
 }
+
+fn xxx_testload_disc() -> Disc { Disc { colours : 
+  
+}
diff --git a/src/testload.rs b/src/testload.rs
new file mode 100644 (file)
index 0000000..b37a61e
--- /dev/null
@@ -0,0 +1,20 @@
+
+fn testload() -> E {
+  let disc = Disc { size : 10, colours : vec![
+    Colour::literal("red"),
+    Colour::literal("pink"),
+  ] };
+  let pr = PieceRecord {
+    pos : [40,40],
+    p : Rc::new(disc),
+    held : None,
+  };
+  let g = GameState {
+    pieces : vec![ pr ],
+    players : vec![
+      PlayerRecord { nick : "alice".to_owned() },
+      PlayerRecord { nick : "bob"  .to_owned() },
+    ],
+  };
+  create_instance_access("alice", 
+