summaryrefslogtreecommitdiff
path: root/src/types.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/types.rs')
-rw-r--r--src/types.rs27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/types.rs b/src/types.rs
index fb9f7ae..df9e168 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -16,8 +16,8 @@ use crate::minesweeper;
pub struct Config {
pub cert: String,
pub pkey: String,
+ pub index_pg: String,
pub room_pg: String,
- pub form_pg: String,
pub client_code: String,
pub stylesheet: String,
pub socket_addr: SocketAddr,
@@ -41,7 +41,8 @@ impl Display for BoardConf {
pub struct Room {
pub name: String,
pub players: PlayerMap,
- pub peer_limit: u32,
+ pub peer_limit: usize,
+ pub public: bool,
pub driver: tokio::task::JoinHandle<()>,
pub cmd_stream: CmdTx,
pub board_conf: BoardConf,
@@ -75,7 +76,29 @@ impl Display for Player {
}
}
+#[derive(Eq, PartialEq, Hash, Debug, Clone)]
+pub struct RoomId(pub String);
+impl Display for RoomId {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{}", self.0)
+ }
+}
+
+impl RoomId {
+ pub fn new_in<T>(map: &HashMap<RoomId, T>) -> Self {
+ use rand::{ thread_rng, Rng, distributions::Alphanumeric };
+ let id = RoomId { 0: thread_rng()
+ .sample_iter(&Alphanumeric)
+ .take(16)
+ .map(char::from)
+ .collect::<String>() };
+ if map.contains_key(&id) { RoomId::new_in(map) }
+ else { id }
+ }
+}
+
pub type CmdTx = tokio::sync::mpsc::UnboundedSender<MetaMove>;
+pub type RoomMap = Arc<RwLock<HashMap<RoomId, Arc<RwLock<Room>>>>>;
pub type PlayerMapData = Arc<RwLock<HashMap<SocketAddr, Player>>>;
#[derive(Debug)]
pub struct PlayerMap {