>
(&'out self, ns: NS, mut f: F)
{
- const ENCODE : percent_encoding::AsciiSet =
+ const ENCODE: percent_encoding::AsciiSet =
percent_encoding::NON_ALPHANUMERIC
.remove(b'-');
use crate::imports::*;
use authproofs::*;
- pub trait Perm : FromPrimitive + ToPrimitive +
+ pub trait Perm: FromPrimitive + ToPrimitive +
Copy + Eq + Hash + Sync + Send + 'static
{
type Auth;
pub const EXIT_USAGE : i32 = 12;
pub const EXIT_DISASTER : i32 = 16;
-pub const DEFAULT_CONFIG_DIR : &str = "/etc/otter";
-pub const DEFAULT_CONFIG_LEAFNAME : &str = "server.toml";
-
+pub const DEFAULT_CONFIG_DIR : &str = "/etc/otter";
+pub const DEFAULT_CONFIG_LEAFNAME : &str = "server.toml";
pub const DEFAULT_SENDMAIL_PROGRAM : &str = "/usr/sbin/sendmail";
-pub const DAEMON_STARTUP_REPORT : &str = "otter-daemon started";
+pub const DAEMON_STARTUP_REPORT: &str = "otter-daemon started";
pub const LOG_ENV_VAR: &str = "OTTER_LOG";
#[derive(Deserialize,Debug,Clone)]
let wasm_dir = defpath(wasm_dir, "assets" );
let nwtemplate_dir = defpath(nwtemplate_dir, "nwtemplates" );
let bundled_sources = defpath(bundled_sources, "bundled-sources" );
- const DEFAULT_LIBRARY_GLOB : &str = "library/*.toml";
+ const DEFAULT_LIBRARY_GLOB: &str = "library/*.toml";
let shapelibs = shapelibs.unwrap_or_else(||{
let glob = defpath(None, DEFAULT_LIBRARY_GLOB);
let mut buf = String::new();
File::open(&config_filename).with_context(||config_filename.to_string())?
.read_to_string(&mut buf)?;
- let spec : ServerConfigSpec = toml_de::from_str(&buf)?;
+ let spec: ServerConfigSpec = toml_de::from_str(&buf)?;
let whole = spec.try_into()?;
set_config(whole);
}
pub fn save_dir(&self) -> &String {
let st = GLOBAL.save_area_lock.lock().unwrap();
- let mut _f : &File = st.as_ref().unwrap();
+ let mut _f: &File = st.as_ref().unwrap();
&self.save_dir
}
}
some_slotmap!{DenseSlotMap}
some_slotmap!{SecondarySlotMap}
-impl<T> IdForById for T where T : AccessId {
+impl<T> IdForById for T where T: AccessId {
type Error = T::Error;
- const ERROR : Self::Error = <Self as AccessId>::ERROR;
+ const ERROR: Self::Error = <Self as AccessId>::ERROR;
}
impl IdForById for PieceId {
type Error = OE;
- const ERROR : OE = OE::PieceGone;
+ const ERROR: OE = OE::PieceGone;
}
#[macro_export]
#[serde(transparent)]
pub struct Timestamp(pub u64); /* time_t */
-pub const DEFAULT_TABLE_SIZE : Pos = PosC([ 400, 200 ]);
+pub const DEFAULT_TABLE_SIZE: Pos = PosC([ 400, 200 ]);
// ---------- general data types ----------
impl PieceState {
#[throws(IE)]
- pub fn prep_piecestate(&self, p: &dyn Piece, pri : &PieceRenderInstructions)
+ pub fn prep_piecestate(&self, p: &dyn Piece, pri: &PieceRenderInstructions)
-> PreparedPieceState {
PreparedPieceState {
pos : self.pos,
let name = Arc::new(name);
let g = Instance {
- name : name.clone(),
+ name: name.clone(),
gs, acl,
ipieces: PiecesLoaded(default()),
clients: default(),
};
let cont = InstanceContainer {
- live : true,
- game_dirty : false,
- access_dirty : false,
+ live: true,
+ game_dirty: false,
+ access_dirty: false,
g,
};
_: Authorisation<AccountName>)
-> Vec<Arc<InstanceName>> {
let games = GLOBAL.games_table.read().unwrap();
- let out : Vec<Arc<InstanceName>> =
+ let out: Vec<Arc<InstanceName>> =
games.keys()
.filter(|k| account == None || account == Some(&k.account))
.cloned()
// We make a copy so if the save fails, we can put everything back
let mut players = self.c.g.gs.players.clone();
- let old_players : Vec<_> = old_players_set.iter().cloned().collect();
- let old_gpls : Vec<_> = old_players.iter().cloned().map(|oldplayer| {
+ let old_players: Vec<_> = old_players_set.iter().cloned().collect();
+ let old_gpls: Vec<_> = old_players.iter().cloned().map(|oldplayer| {
players.remove(oldplayer)
}).collect();
self.tokens_deregister_for_id(
|id:PlayerId| old_players_set.contains(&id)
);
- let old_ipls : Vec<_> = old_players.iter().cloned().map(
+ let old_ipls: Vec<_> = old_players.iter().cloned().map(
|oldplayer| self.iplayers.remove(oldplayer)
.map(|ipr| ipr.ipl)
).collect();
});
let iad = InstanceAccessDetails {
- gref : self.gref.clone(),
- ident : player,
+ gref: self.gref.clone(),
+ ident: player,
acctid
};
self.token_register(token.clone(), iad);
}
fn forget_all_tokens<Id:AccessId>(tokens: &mut TokenRegistry<Id>) {
- let global : &RwLock<TokenTable<Id>> = AccessId::global_tokens(PRIVATE_Y);
+ let global: &RwLock<TokenTable<Id>> = AccessId::global_tokens(PRIVATE_Y);
let mut global = global.write().unwrap();
for t in tokens.tr.drain() { global.remove(&t); }
}
let name = InstanceName::from_str(&rhs)?;
GameFile {
- access_leaf : [ b"a-", after_ftype_prefix ].concat(),
+ access_leaf: [ b"a-", after_ftype_prefix ].concat(),
name,
}
}
f.flush()
.with_context(||format!("save: flush {:?}",&tmp))?;
drop(
- f.into_inner().map_err(|e| { let e : io::Error = e.into(); e })
+ f.into_inner().map_err(|e| { let e: io::Error = e.into(); e })
.with_context(||format!("save: close {:?}",&tmp))?
);
let out = savefilename(&self.name, prefix,"");
let pu_bc = PlayerUpdates::new_begin(&gs);
- let iplayers : SecondarySlotMap<PlayerId, PlayerRecord> = {
+ let iplayers: SecondarySlotMap<PlayerId, PlayerRecord> = {
let a = aplayers;
a.into_iter()
}.filter_map(|(player, ipl)| {
if let Some(acctid) = acctid;
let iad = InstanceAccessDetails {
acctid,
- gref : gref.clone(),
- ident : player,
+ gref: gref.clone(),
+ ident: player,
};
then { global.insert(RawToken(token), iad); }
} }
pub trait AccessId: Copy + Clone + 'static {
type Error: Into<OnlineError>;
- const ERROR : Self::Error;
+ const ERROR: Self::Error;
fn global_tokens(_:PrivateCaller) -> &'static RwLock<TokenTable<Self>>;
fn tokens_registry(ig: &mut Instance, _:PrivateCaller)
-> &mut TokenRegistry<Self>;
}
}
-pub fn lookup_token<Id : AccessId>(s : &RawTokenVal)
+pub fn lookup_token<Id:AccessId>(s: &RawTokenVal)
-> Result<InstanceAccessDetails<Id>, Id::Error> {
Id::global_tokens(PRIVATE_Y).read().unwrap().get(s).cloned()
.ok_or(Id::ERROR)
}
#[throws(OE)]
-pub fn record_token<Id : AccessId> (
+pub fn record_token<Id:AccessId> (
ig: &mut InstanceGuard,
iad: InstanceAccessDetails<Id>
) -> RawToken {
{
for gref in games.values() {
let c = gref.lock_even_poisoned();
- let remove : Vec<_> = c.g.iplayers.iter().filter_map(|(player,pr)| {
+ let remove: Vec<_> = c.g.iplayers.iter().filter_map(|(player,pr)| {
if pr.ipl.acctid == acctid { Some(player) } else { None }
}).collect();
let mut ig = InstanceGuard { gref: gref.clone(), c };
macro_rules! display_consequential_impls {
( $x:path ) => {
impl From<$x> for String {
- fn from(p : $x) -> String { format!("{}",p) }
+ fn from(p: $x) -> String { format!("{}",p) }
}
impl Debug for $x {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fn data(&self) -> slotmap::KeyData { self.0 }
}
impl From<slotmap::KeyData> for $x {
- fn from(d : slotmap::KeyData) -> Self { $x(d) }
+ fn from(d: slotmap::KeyData) -> Self { $x(d) }
}
impl From<$x> for slotmap::KeyData {
- fn from(p : $x) -> Self {
+ fn from(p: $x) -> Self {
p.0
}
}
}
#[throws(SE)]
-pub fn svg_rectangle_path(PosC([x,y]) : PosC<f64>) -> Html {
+pub fn svg_rectangle_path(PosC([x,y]): PosC<f64>) -> Html {
Html(format!("M {} {} h {} v {} h {} z",
-x*0.5, -y*0.5, x, y, -x))
}
impl Outline for SimpleShape {
delegate! {
to self.outline {
- fn surround_path(&self, _pri : &PieceRenderInstructions)
+ fn surround_path(&self, _pri: &PieceRenderInstructions)
-> Result<Html,IE>;
- fn thresh_dragraise(&self, _pri : &PieceRenderInstructions)
+ fn thresh_dragraise(&self, _pri: &PieceRenderInstructions)
-> Result<Option<Coord>,IE>;
fn bbox_approx(&self) -> [Pos;2];
}
}
#[typetag::deserialize(tag="outline")]
-pub trait OutlineDefn : Debug + Sync + Send {
+pub trait OutlineDefn: Debug + Sync + Send {
fn check(&self, lgi: &GroupData) -> Result<(),LLE>;
fn load(&self, lgi: &GroupData) -> Result<Box<dyn Outline>,IE>;
}
match group.d.size.as_slice() {
&[c] => c,
size => throw!(LLE::WrongNumberOfSizeDimensions
- { got: size.len(), expected : [1,1] }),
+ { got: size.len(), expected: [1,1] }),
}
}
}
#[typetag::serde(name="Square")]
impl Outline for Square {
#[throws(IE)]
- fn surround_path(&self, _pri : &PieceRenderInstructions) -> Html {
+ fn surround_path(&self, _pri: &PieceRenderInstructions) -> Html {
let size = self.xy * SELECT_SCALE;
svg_rectangle_path(size)?
}
#[throws(IE)]
- fn thresh_dragraise(&self, _pri : &PieceRenderInstructions)
+ fn thresh_dragraise(&self, _pri: &PieceRenderInstructions)
-> Option<Coord> {
- let smallest : f64 = self.xy.0.iter().cloned()
+ let smallest: f64 = self.xy.0.iter().cloned()
.map(OrderedFloat::from).min().unwrap().into();
Some((smallest * 0.5) as Coord)
}
fn bbox_approx(&self) -> [Pos;2] {
- let pos : Pos = self.xy.map(
+ let pos: Pos = self.xy.map(
|v| ((v * 0.5).ceil()) as Coord
);
let neg = -pos;
&[s] => [s,s],
s if s.len() == 2 => s.try_into().unwrap(),
size => throw!(LLE::WrongNumberOfSizeDimensions
- { got: size.len(), expected : [1,2]}),
+ { got: size.len(), expected: [1,2]}),
}
)}
}
fn serialize_unit (self) -> ROk { u(line!()) }
fn serialize_some<T>(self, _: &T) -> ROk
- where T : Serialize + ?Sized { u(line!()) }
+ where T: Serialize + ?Sized { u(line!()) }
fn serialize_newtype_struct <T>(self, _:&str, _: &T) -> ROk
- where T : Serialize + ?Sized { u(line!()) }
+ where T: Serialize + ?Sized { u(line!()) }
fn serialize_newtype_variant<T>(self, _:&str, _:u32, _:&str, _: &T) -> ROk
- where T : Serialize + ?Sized { u(line!()) }
+ where T: Serialize + ?Sized { u(line!()) }
fn serialize_unit_struct (self,_:&str ) -> ROk { u(line!()) }
fn serialize_unit_variant(self,_:&str,_:u32,_:&str) -> ROk { u(line!()) }
fn serialize_unit (self) -> R<V> { u(line!()) }
fn serialize_some <T>(self, _: &T) -> R<V>
- where T : Serialize + ?Sized { u(line!()) }
+ where T: Serialize + ?Sized { u(line!()) }
fn serialize_newtype_struct <T>(self, _:&str, _: &T) -> R<V>
- where T : Serialize + ?Sized { u(line!()) }
+ where T: Serialize + ?Sized { u(line!()) }
fn serialize_newtype_variant<T>(self, _:&str, _:u32, _:&str, _: &T) -> R<V>
- where T : Serialize + ?Sized { u(line!()) }
+ where T: Serialize + ?Sized { u(line!()) }
fn serialize_unit_struct (self,_:&str ) -> R<V> { u(line!()) }
fn serialize_unit_variant (self,_:&str,_:u32,_:&str) -> R<V> { u(line!()) }
}
impl UrlSpec {
- const MAX_LEN : usize = 200;
+ const MAX_LEN: usize = 200;
}
impl TryFrom<&UrlSpec> for Url {
#[throws(io::Error)]
fn write_next<U>(&mut self, mut buf: &mut U, tz: &Timezone,
next: &PreparedUpdate)
- where U : Write {
+ where U: Write {
let tu = next.for_transmit(tz, self.player, self.client);
write!(buf, "data: ")?;
// ---------- entrypoint for dribbling the http response ----------
#[throws(OE)]
-pub fn content(iad : InstanceAccessDetails<ClientId>, gen: Generation)
+pub fn content(iad: InstanceAccessDetails<ClientId>, gen: Generation)
-> impl Read {
let client = iad.ident;
};
UpdateReader {
- need_flush : false,
- keepalives : Wrapping(0),
- overflow : None,
+ need_flush: false,
+ keepalives: Wrapping(0),
+ overflow: None,
gref,
- ending_send : default(),
- init_confirmation_send : iter::once(()),
- wn : UpdateReaderWN {
+ ending_send: default(),
+ init_confirmation_send: iter::once(()),
+ wn: UpdateReaderWN {
player, client, to_send,
},
}
use crate::imports::*;
-pub const SVG_SCALE : f64 = 6.;
+pub const SVG_SCALE: f64 = 6.;
pub const HELD_SURROUND_COLOUR: &str = "black";
impl DataLoadPlayer {
pub fn from_player(ig: &Instance, player: PlayerId) -> Self {
- let kd : slotmap::KeyData = player.into();
+ let kd: slotmap::KeyData = player.into();
let n = kd.get_idx_version().0;
let n = if n != 0 { n.try_into().unwrap() }
else { ig.gs.players.capacity() };
}
PreparedUpdateEntry_Piece {
- by_client : self.by_client,
+ by_client: self.by_client,
ops: out,
}
}
type WRC = WhatResponseToClientOp;
impl PreparedUpdate {
- pub fn for_transmit<'u>(&'u self, tz: &'u Timezone, player: PlayerId, dest : ClientId)
- -> TransmitUpdate<'u> {
+ pub fn for_transmit<'u>(&'u self, tz: &'u Timezone,
+ player: PlayerId, dest: ClientId)
+ -> TransmitUpdate<'u> {
type ESVU<T> = ErrorSignaledViaUpdate<T>;
type PUE = PreparedUpdateEntry;
type TUE<'u> = TransmitUpdateEntry<'u>;
fn serialize_logentry<S:Serializer>(&(tz,logent): &TransmitUpdateLogEntry,
s:S) -> Result<S::Ok, S::Error> {
- let f : FormattedLogEntry = (tz, logent).into();
+ let f: FormattedLogEntry = (tz, logent).into();
f.serialize(s)
}