1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
use std::{
collections::HashMap,
net::SocketAddr,
sync::Arc,
};
use warp::ws::Message;
use tokio::sync::RwLock;
use crate::minesweeper;
#[derive(Debug, Clone)]
pub struct Config {
pub cert_path: String,
pub pkey_path: String,
pub page_path: String,
pub socket_addr: SocketAddr,
}
#[derive(Debug, Clone)]
pub struct State {
pub conf: Config,
pub peers: PeerMap,
}
#[derive(Debug)]
pub enum MetaMove {
Move(minesweeper::Move,SocketAddr),
Dump,
Reset,
}
#[derive(Debug)]
pub struct Peer {
pub tx: tokio::sync::mpsc::UnboundedSender<Message>,
pub seq_id: usize,
pub name: String,
pub clr: String,
pub position: (usize, usize),
}
pub struct ConnData {
pub cmd_tx: CmdTx,
pub remote_addr: SocketAddr,
pub peers: PeerMap,
}
pub type CmdTx = tokio::sync::mpsc::UnboundedSender<MetaMove>;
pub type PeerMap = Arc<RwLock<HashMap<SocketAddr, Peer>>>;
|