51 lines
1.0 KiB
Rust
51 lines
1.0 KiB
Rust
use game::Game;
|
|
|
|
pub type SessionToken = [u8; 8];
|
|
pub type SessionSecret = [u8; 8];
|
|
|
|
pub struct Player {
|
|
pub user:Option<u32>,
|
|
pub connections:Vec<u32>,
|
|
}
|
|
|
|
pub struct Session {
|
|
pub id:u32,
|
|
pub token:SessionToken,
|
|
pub secret:SessionSecret,
|
|
|
|
pub game:Game,
|
|
|
|
pub p_dawn:Player,
|
|
pub p_dusk:Player,
|
|
pub connections:Vec<u32>,
|
|
|
|
pub time:u64,
|
|
pub chain_id:usize,
|
|
}
|
|
impl Session {
|
|
pub fn get_connections(&self) -> Vec<u32>
|
|
{
|
|
[
|
|
self.p_dawn.connections.clone(),
|
|
self.p_dusk.connections.clone(),
|
|
self.connections.clone(),
|
|
].concat()
|
|
}
|
|
|
|
pub fn remove_connection(&mut self, source:u8, id:u32)
|
|
{
|
|
let connections = match source {
|
|
0 => &mut self.p_dawn.connections,
|
|
1 => &mut self.p_dusk.connections,
|
|
_ => &mut self.connections,
|
|
};
|
|
|
|
for i in 0..connections.len() {
|
|
if connections[i] == id {
|
|
connections.remove(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|