equal
deleted
inserted
replaced
4 client::HWClient, room::HWRoom, actions, handlers, |
4 client::HWClient, room::HWRoom, actions, handlers, |
5 coretypes::{ClientId, RoomId}, |
5 coretypes::{ClientId, RoomId}, |
6 actions::{Destination, PendingMessage} |
6 actions::{Destination, PendingMessage} |
7 }; |
7 }; |
8 use crate::protocol::messages::*; |
8 use crate::protocol::messages::*; |
|
9 use rand::{RngCore, thread_rng}; |
|
10 use base64::{encode}; |
9 |
11 |
10 type Slab<T> = slab::Slab<T>; |
12 type Slab<T> = slab::Slab<T>; |
11 |
13 |
12 |
14 |
13 pub struct HWServer { |
15 pub struct HWServer { |
35 pub fn add_client(&mut self) -> ClientId { |
37 pub fn add_client(&mut self) -> ClientId { |
36 let key: ClientId; |
38 let key: ClientId; |
37 { |
39 { |
38 let entry = self.clients.vacant_entry(); |
40 let entry = self.clients.vacant_entry(); |
39 key = entry.key(); |
41 key = entry.key(); |
40 let client = HWClient::new(entry.key()); |
42 let mut salt = [0u8; 18]; |
|
43 thread_rng().fill_bytes(&mut salt); |
|
44 |
|
45 let client = HWClient::new(entry.key(), encode(&salt)); |
41 entry.insert(client); |
46 entry.insert(client); |
42 } |
47 } |
43 self.send(key, &Destination::ToSelf, HWServerMessage::Connected(utils::PROTOCOL_VERSION)); |
48 self.send(key, &Destination::ToSelf, HWServerMessage::Connected(utils::PROTOCOL_VERSION)); |
44 key |
49 key |
45 } |
50 } |