author | Wuzzy <Wuzzy2@mail.ru> |
Sun, 02 Jun 2019 17:19:07 +0200 | |
changeset 15095 | e13b9054316b |
parent 15026 | a479916799ea |
child 15443 | eb1c407a9e8f |
permissions | -rw-r--r-- |
14457 | 1 |
use base64::encode; |
12126 | 2 |
use mio; |
14457 | 3 |
use std::iter::Iterator; |
12126 | 4 |
|
14783 | 5 |
pub const SERVER_VERSION: u32 = 3; |
14779
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14457
diff
changeset
|
6 |
pub const SERVER_TOKEN: mio::Token = mio::Token(1_000_000_000); |
14830
8ddb5842fe0b
allow running plaintext and tls servers in parallel
alfadur
parents:
14803
diff
changeset
|
7 |
pub const SECURE_SERVER_TOKEN: mio::Token = mio::Token(1_000_000_001); |
8ddb5842fe0b
allow running plaintext and tls servers in parallel
alfadur
parents:
14803
diff
changeset
|
8 |
pub const TIMER_TOKEN: mio::Token = mio::Token(1_000_000_002); |
8ddb5842fe0b
allow running plaintext and tls servers in parallel
alfadur
parents:
14803
diff
changeset
|
9 |
pub const IO_TOKEN: mio::Token = mio::Token(1_000_000_003); |
13416 | 10 |
|
14457 | 11 |
pub fn is_name_illegal(name: &str) -> bool { |
12 |
name.len() > 40 |
|
13 |
|| name.trim().is_empty() |
|
14781 | 14 |
|| name.trim() != name |
14457 | 15 |
|| name |
16 |
.chars() |
|
15026 | 17 |
.any(|c| "$()*+?[]^{|}\x7F".contains(c) || ('\x00'..='\x1F').contains(&c)) |
13423 | 18 |
} |
19 |
||
20 |
pub fn to_engine_msg<T>(msg: T) -> String |
|
14457 | 21 |
where |
22 |
T: Iterator<Item = u8> + Clone, |
|
13423 | 23 |
{ |
24 |
let mut tmp = Vec::new(); |
|
25 |
tmp.push(msg.clone().count() as u8); |
|
26 |
tmp.extend(msg); |
|
27 |
encode(&tmp) |
|
13801 | 28 |
} |
29 |
||
30 |
pub fn protocol_version_string(protocol_number: u16) -> &'static str { |
|
31 |
match protocol_number { |
|
32 |
17 => "0.9.7-dev", |
|
33 |
19 => "0.9.7", |
|
34 |
20 => "0.9.8-dev", |
|
35 |
21 => "0.9.8", |
|
36 |
22 => "0.9.9-dev", |
|
37 |
23 => "0.9.9", |
|
38 |
24 => "0.9.10-dev", |
|
39 |
25 => "0.9.10", |
|
40 |
26 => "0.9.11-dev", |
|
41 |
27 => "0.9.11", |
|
42 |
28 => "0.9.12-dev", |
|
43 |
29 => "0.9.12", |
|
44 |
30 => "0.9.13-dev", |
|
45 |
31 => "0.9.13", |
|
46 |
32 => "0.9.14-dev", |
|
47 |
33 => "0.9.14", |
|
48 |
34 => "0.9.15-dev", |
|
49 |
35 => "0.9.14.1", |
|
50 |
37 => "0.9.15", |
|
51 |
38 => "0.9.16-dev", |
|
52 |
39 => "0.9.16", |
|
53 |
40 => "0.9.17-dev", |
|
54 |
41 => "0.9.17", |
|
55 |
42 => "0.9.18-dev", |
|
56 |
43 => "0.9.18", |
|
57 |
44 => "0.9.19-dev", |
|
58 |
45 => "0.9.19", |
|
59 |
46 => "0.9.20-dev", |
|
60 |
47 => "0.9.20", |
|
61 |
48 => "0.9.21-dev", |
|
62 |
49 => "0.9.21", |
|
63 |
50 => "0.9.22-dev", |
|
64 |
51 => "0.9.22", |
|
65 |
52 => "0.9.23-dev", |
|
66 |
53 => "0.9.23", |
|
67 |
54 => "0.9.24-dev", |
|
68 |
55 => "0.9.24", |
|
69 |
56 => "0.9.25-dev", |
|
14456 | 70 |
57 => "0.9.25", |
71 |
58 => "1.0.0-dev", |
|
14457 | 72 |
_ => "Unknown", |
13801 | 73 |
} |
14456 | 74 |
} |