+
pub trait Piece {
fn svg(&self, pr : &PiecedRecord) -> SvgData;
}
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);
+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!
}
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 {
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);
+ }
+}
#[derive(Debug)]
pub struct Instance {
+ mod_token : RawToken,
g : RwLock<Game>,
g_notify : Condvar,
}
}
}
-#[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);
unwrap();
response::content::Content(ct,ch)
}
+*/
#[get("/_/<leaf>")]
fn resource(leaf : CheckedResourceLeaf) -> io::Result<NamedFile> {
}
fn main() {
+
+
let helmet = SpaceHelmet::default()
.enable(NoSniff::Enable)
.enable(Frame::Deny)
struct Disc {
- colours : [Colour],
+ colours : Vec<Colour>,
size : Coord,
}
).into_bytes()
}
}
+
+fn xxx_testload_disc() -> Disc { Disc { colours :
+
+}
--- /dev/null
+
+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",
+