author | alfadur |
Wed, 01 May 2019 21:59:41 +0300 | |
changeset 14876 | 0f39f8efbd2e |
parent 14835 | 8ddb5842fe0b |
child 15031 | a479916799ea |
permissions | -rw-r--r-- |
14462 | 1 |
use base64::encode; |
12131 | 2 |
use mio; |
14462 | 3 |
use std::iter::Iterator; |
12131 | 4 |
|
14788 | 5 |
pub const SERVER_VERSION: u32 = 3; |
14784
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14462
diff
changeset
|
6 |
pub const SERVER_TOKEN: mio::Token = mio::Token(1_000_000_000); |
14835
8ddb5842fe0b
allow running plaintext and tls servers in parallel
alfadur
parents:
14808
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:
14808
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:
14808
diff
changeset
|
9 |
pub const IO_TOKEN: mio::Token = mio::Token(1_000_000_003); |
13421 | 10 |
|
14462 | 11 |
pub fn is_name_illegal(name: &str) -> bool { |
12 |
name.len() > 40 |
|
13 |
|| name.trim().is_empty() |
|
14786 | 14 |
|| name.trim() != name |
14462 | 15 |
|| name |
16 |
.chars() |
|
17 |
.any(|c| "$()*+?[]^{|}\x7F".contains(c) || '\x00' <= c && c <= '\x1F') |
|
13428 | 18 |
} |
19 |
||
20 |
pub fn to_engine_msg<T>(msg: T) -> String |
|
14462 | 21 |
where |
22 |
T: Iterator<Item = u8> + Clone, |
|
13428 | 23 |
{ |
24 |
let mut tmp = Vec::new(); |
|
25 |
tmp.push(msg.clone().count() as u8); |
|
26 |
tmp.extend(msg); |
|
27 |
encode(&tmp) |
|
13806 | 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", |
|
14461 | 70 |
57 => "0.9.25", |
71 |
58 => "1.0.0-dev", |
|
14462 | 72 |
_ => "Unknown", |
13806 | 73 |
} |
14461 | 74 |
} |