JFLib

game/src/net/room.rs#

Source: lib/game/src/net/room.rs

room -- rooms by a code or a link, players by a name, no accounts

  RoomCode       six characters of an alphabet without look-alikes (no 0 O 1 I L: 31 characters, about
                 887 million codes); random from the server's generator, parse accepts any case and
                 ignores spaces and dashes ("k7m-2qx")
  room_link      a link to a room: the page's address with "#CODE" (the fragment never reaches a server
                 log); room_from_link takes a code back out of such a link, "?room=CODE", ".../r/CODE"
                 or a bare code
  clean_name     a player's name: trimmed, inner runs of white space as one space, no control or
                 direction-changing characters, 1 to 16 characters; unique_name appends " 2", " 3" ...
                 when the room has it already (compared without case)
/// the characters of a room code
CODE_ALPHABET: &[u8; 31] = b"ABCDEFGHJKMNPQRSTUVWXYZ23456789"
/// characters a name may have at most
MAX_NAME: usize = 16
  • struct RoomCode(pub [u8; 6]) a room's code (see the module header)

impl RoomCode

  • fn from_random(mut r: u64) -> RoomCode a code from 64 random bits (the server's generator)

  • fn parse(s: &str) -> Option<RoomCode> a code typed by a person: any case, spaces and dashes ignored; None unless six characters of the alphabet remain

  • fn as_str(&self) -> &str the six characters

  • fn valid(&self) -> bool the code's bytes are all of the alphabet (a code read from the network)

  • fn clean_name(raw: &str) -> Option<String> a player's name as the room shows it (see the module header); None when nothing is left

  • fn unique_name(name: &str, taken: &[&str]) -> String name made unique among taken (compared ASCII-case-insensitively): " 2", " 3" ... appended, the name shortened to keep MAX_NAME characters

Source: docs/API.md in the JFLib repository.