1 use super::{ |
1 use super::{ |
2 actions, |
|
3 actions::{Destination, PendingMessage}, |
|
4 client::HWClient, |
2 client::HWClient, |
5 coretypes::{ClientId, RoomId}, |
3 coretypes::{ClientId, RoomId}, |
6 handlers, |
|
7 indexslab::IndexSlab, |
4 indexslab::IndexSlab, |
8 io::HWServerIO, |
5 io::HWServerIO, |
9 room::HWRoom, |
6 room::HWRoom, |
10 }; |
7 }; |
11 use crate::{protocol::messages::*, utils}; |
8 use crate::utils; |
12 |
9 |
13 use log::*; |
10 use log::*; |
14 use slab; |
11 use slab; |
15 use std::{borrow::BorrowMut, iter, num::NonZeroU16}; |
12 use std::{borrow::BorrowMut, iter, num::NonZeroU16}; |
16 |
13 |
43 self.clients.insert(client_id, client); |
40 self.clients.insert(client_id, client); |
44 } |
41 } |
45 |
42 |
46 pub fn remove_client(&mut self, client_id: ClientId) -> Option<HWAnteClient> { |
43 pub fn remove_client(&mut self, client_id: ClientId) -> Option<HWAnteClient> { |
47 let mut client = self.clients.remove(client_id); |
44 let mut client = self.clients.remove(client_id); |
48 if let Some(HWAnteClient { web_password: Some(ref mut password), ..}) = client { |
45 if let Some(HWAnteClient { |
|
46 web_password: Some(ref mut password), |
|
47 .. |
|
48 }) = client |
|
49 { |
49 password.replace_range(.., "🦔🦔🦔🦔🦔🦔🦔🦔"); |
50 password.replace_range(.., "🦔🦔🦔🦔🦔🦔🦔🦔"); |
50 } |
51 } |
51 client |
52 client |
52 } |
53 } |
53 } |
54 } |
54 |
55 |
55 pub struct HWServer { |
56 pub struct HWServer { |
56 pub clients: IndexSlab<HWClient>, |
57 pub clients: IndexSlab<HWClient>, |
57 pub rooms: Slab<HWRoom>, |
58 pub rooms: Slab<HWRoom>, |
58 pub output: Vec<(Vec<ClientId>, HWServerMessage)>, |
|
59 pub removed_clients: Vec<ClientId>, |
|
60 pub io: Box<dyn HWServerIO>, |
59 pub io: Box<dyn HWServerIO>, |
61 pub anteroom: HWAnteroom, |
60 pub anteroom: HWAnteroom, |
62 } |
61 } |
63 |
62 |
64 impl HWServer { |
63 impl HWServer { |
81 self.clients.insert(client_id, client); |
78 self.clients.insert(client_id, client); |
82 } |
79 } |
83 } |
80 } |
84 |
81 |
85 pub fn remove_client(&mut self, client_id: ClientId) { |
82 pub fn remove_client(&mut self, client_id: ClientId) { |
86 self.removed_clients.push(client_id); |
83 self.clients.remove(client_id); |
87 if self.clients.contains(client_id) { |
|
88 self.clients.remove(client_id); |
|
89 } |
|
90 } |
84 } |
91 |
85 |
92 pub fn add_room(&mut self) -> &mut HWRoom { |
86 pub fn add_room(&mut self) -> &mut HWRoom { |
93 allocate_room(&mut self.rooms) |
87 allocate_room(&mut self.rooms) |
94 } |
88 } |