From: Ian Jackson Date: Sun, 3 Jan 2021 02:01:14 +0000 (+0000) Subject: wip links - does not compile X-Git-Tag: otter-0.2.0~43 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=f73e1955f71c4d56a89ffb779c01fc20d6880029;p=otter.git wip links - does not compile Signed-off-by: Ian Jackson --- diff --git a/Cargo.lock.example b/Cargo.lock.example index 4c2a6d1b..8d78b041 100644 --- a/Cargo.lock.example +++ b/Cargo.lock.example @@ -100,6 +100,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f8ebf5827e4ac4fd5946560e6a99776ea73b596d80898f357007317a7141e47" +[[package]] +name = "array-macro" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06e97b4e522f9e55523001238ac59d13a8603af57f69980de5d8de4bbbe8ada6" + [[package]] name = "arrayvec" version = "0.5.2" @@ -496,6 +502,28 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "enum-map" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4187999839f4ae8be35cf185d1381aa8dc32d2f5951349cc37ae49ebc4781855" +dependencies = [ + "array-macro", + "enum-map-derive", + "serde", +] + +[[package]] +name = "enum-map-derive" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5c450cf304c9e18d45db562025a14fb1ca0f5c769b6f609309f81d4c31de455" +dependencies = [ + "proc-macro2 1.0.24", + "quote 1.0.8", + "syn 1.0.57", +] + [[package]] name = "env_logger" version = "0.8.2" @@ -1556,6 +1584,7 @@ dependencies = [ "delegate 0.5.0", "derive_more", "either", + "enum-map", "failure", "fehler", "flexi_logger", diff --git a/Cargo.toml b/Cargo.toml index 18f41a94..25383485 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ chrono-tz = "0.5" delegate = "0.5" derive_more = "0.99" either = "1" +enum-map = { version = "0.6", features = [ "serde" ] } failure = "0.1.8" # for pwd fehler = "1" flexi_logger = { version = "0.16", features = [ "specfile" ] } diff --git a/daemon/session.rs b/daemon/session.rs index 9cd70ce9..fabce96a 100644 --- a/daemon/session.rs +++ b/daemon/session.rs @@ -18,6 +18,7 @@ struct SessionRenderContext { load: String, log: Vec, sse_url_prefix: String, + links: Vec<(LinkKind, Html)>, } #[derive(Debug,Serialize)] @@ -186,6 +187,7 @@ fn session_inner(form : Json, nick : gpl.nick.clone(), sse_url_prefix, ptoken: form.ptoken.clone(), + links: ig.links.iter().map(|(k,v)| (k.clone(), v.clone())).collect(), load : serde_json::to_string(&DataLoad { players: load_players, last_log_ts: timestamp_abbrev.unwrap_or_default(), diff --git a/src/bin/otter.rs b/src/bin/otter.rs index ccac6d44..814c05ba 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -630,7 +630,7 @@ const PLAYER_DEFAULT_PERMS : &[TablePermission] = &[ #[throws(AE)] fn setup_table(_ma: &MainOpts, spec: &TableSpec) -> Vec { - let TableSpec { players, player_perms, acl } = spec; + let TableSpec { players, player_perms, acl, links } = spec; let mut player_perms = player_perms.clone() .unwrap_or(PLAYER_DEFAULT_PERMS.iter().cloned().collect()); player_perms.extend(PLAYER_ALWAYS_PERMS.iter()); @@ -831,6 +831,46 @@ mod reset_game { )} } +//---------- set-link ---------- + +mod set_link { + + use super::*; + + #[derive(Default,Debug)] + struct Args { + table_name: String, + kind: LinkKind, + url: Option, + } + + fn subargs(sa: &mut Args) -> ArgumentParser { + use argparse::*; + let mut ap = ArgumentParser::new(); + ap.refer(&mut sa.table_name).required() + .add_argument("TABLE-NAME",Store,"table name"); + ap.refer(&mut sa.kind).required() + .add_argument("LINK-KIND",Store,"link kind"); + ap.refer(&mut sa.url) + .add_argument("URL",Store,"url (or empty for none)"); + ap + } + + fn call(_sc: &Subcommand, ma: MainOpts, args: Vec) ->Result<(),AE> { + let args = parse_args::(args, &subargs, &ok_id, None); + let mut chan = access_game(&ma, &args.table_name)?; + + let mut insns = vec![]; + + } + + inventory::submit!{Subcommand( + "set-link", + "Set one of the info links visible from within the game", + call, + )} +} + //---------- join-game ---------- mod join_game { diff --git a/src/commands.rs b/src/commands.rs index 82160011..3570ce55 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -86,6 +86,10 @@ pub enum MgmtGameInstruction { UpdatePlayer { player: PlayerId, details: MgmtPlayerDetails }, LeaveGame(PlayerId), + SetLinks(HashMap), + RemoveLink { kind: LinkKind, url: String }, + SetLink { kind: LinkKind, url: String }, + ClearLog, SetACL { acl: Acl }, // RemovePlayer { player: PlayerId }, todo, does a special setacl @@ -122,6 +126,7 @@ pub struct AccessTokenReport { pub lines: Vec } pub struct MgmtGameResponseGameInfo { pub table_size: Pos, pub players: SecondarySlotMap, + pub links: Vec<(LinkKind, String>), } #[derive(Debug,Clone,Serialize,Deserialize)] diff --git a/src/global.rs b/src/global.rs index b83674bc..696e7921 100644 --- a/src/global.rs +++ b/src/global.rs @@ -38,7 +38,7 @@ pub struct InstanceName { #[derive(Debug,Clone)] pub struct InstanceRef (Arc>); -type LinksTable = HashMap; +pub type LinksTable = EnumMap>; pub struct Instance { pub name: Arc, @@ -52,13 +52,6 @@ pub struct Instance { pub links: LinksTable, } -#[derive(Copy,Clone,Debug,Eq,PartialEq,Ord,PartialOrd,Hash)] -#[derive(Serialize,Deserialize)] -pub enum LinkKind { - Voice, - Info, -} - pub struct PlayerRecord { pub u: PlayerUpdates, pub ipl: IPlayerState, diff --git a/src/imports.rs b/src/imports.rs index 394f3659..ff078e8d 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -46,6 +46,7 @@ pub use arrayvec::ArrayVec; pub use boolinator::Boolinator as _; pub use delegate::delegate; pub use either::{Either, Left, Right}; +pub use enum_map::{Enum, EnumMap}; pub use fehler::{throw, throws}; pub use flexi_logger::{self, LogSpecification}; pub use fs2::FileExt; diff --git a/src/spec.rs b/src/spec.rs index ec8ab6a7..6baab355 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -4,10 +4,12 @@ // game specs +use std::collections::hash_map::HashMap; use std::collections::hash_set::HashSet; use std::fmt::Debug; use std::hash::Hash; +use enum_map::Enum; use fehler::throws; use index_vec::{define_index_type, IndexVec}; use num_derive::{FromPrimitive, ToPrimitive}; @@ -71,6 +73,7 @@ pub struct TableSpec { #[serde(default)] pub players: Vec, pub player_perms: Option>, #[serde(default)] pub acl: Acl, + #[serde(default)] pub links: HashMap, } #[derive(Debug,Serialize,Deserialize)] @@ -110,6 +113,13 @@ pub enum TablePermission { Super, } +#[derive(Copy,Clone,Debug,Eq,PartialEq,Ord,PartialOrd,Hash)] +#[derive(Enum,Serialize,Deserialize)] +pub enum LinkKind { + Voice, + Info, +} + //---------- player accesses, should perhaps be in commands.rs ---------- #[derive(Debug,Serialize,Deserialize)] diff --git a/templates/landscape.tera b/templates/landscape.tera index b97a8319..288fc391 100644 --- a/templates/landscape.tera +++ b/templates/landscape.tera @@ -35,7 +35,20 @@
{{ m::nick() }} | {{ m::status() }}
-
+
+{%- for l in links -%} +{%- if l.first -%} +
+{%- else -%} +| +{%- endif -%} +{{ l.0 }} +xxx core should be in some other .tera file so we can reuse it on update +{%- if l.last -%} +
+{%- endif -%} +{%- endfor -%} +
switch to portrait view | {{ m::zoom() }}
diff --git a/templates/session.tera b/templates/session.tera index b3cd770f..dc0a7e1f 100644 --- a/templates/session.tera +++ b/templates/session.tera @@ -32,7 +32,7 @@
{{ m::nick() }} | -{{ m::wresting() }} +g{{ m::wresting() }} | {{ m::status() }} |