author | alfadur |
Tue, 09 Apr 2019 21:08:35 +0300 | |
changeset 14800 | f43ab2bd76ae |
parent 14478 | 98ef2913ec73 |
child 14802 | 01f8ab45f806 |
permissions | -rw-r--r-- |
14478 | 1 |
use base64::encode; |
12126 | 2 |
use mio; |
14478 | 3 |
use std::iter::Iterator; |
12126 | 4 |
|
14478 | 5 |
pub const PROTOCOL_VERSION: u32 = 3; |
14800
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14478
diff
changeset
|
6 |
pub const SERVER_TOKEN: mio::Token = mio::Token(1_000_000_000); |
f43ab2bd76ae
add a thread for internal server IO and implement account checking with it
alfadur
parents:
14478
diff
changeset
|
7 |
pub const IO_TOKEN: mio::Token = mio::Token(1_000_000_001); |
13416 | 8 |
|
14478 | 9 |
pub fn is_name_illegal(name: &str) -> bool { |
10 |
name.len() > 40 |
|
11 |
|| name.trim().is_empty() |
|
12 |
|| name |
|
13 |
.chars() |
|
14 |
.any(|c| "$()*+?[]^{|}\x7F".contains(c) || '\x00' <= c && c <= '\x1F') |
|
13423 | 15 |
} |
16 |
||
17 |
pub fn to_engine_msg<T>(msg: T) -> String |
|
14478 | 18 |
where |
19 |
T: Iterator<Item = u8> + Clone, |
|
13423 | 20 |
{ |
21 |
let mut tmp = Vec::new(); |
|
22 |
tmp.push(msg.clone().count() as u8); |
|
23 |
tmp.extend(msg); |
|
24 |
encode(&tmp) |
|
13775 | 25 |
} |
26 |
||
27 |
pub fn protocol_version_string(protocol_number: u16) -> &'static str { |
|
28 |
match protocol_number { |
|
29 |
17 => "0.9.7-dev", |
|
30 |
19 => "0.9.7", |
|
31 |
20 => "0.9.8-dev", |
|
32 |
21 => "0.9.8", |
|
33 |
22 => "0.9.9-dev", |
|
34 |
23 => "0.9.9", |
|
35 |
24 => "0.9.10-dev", |
|
36 |
25 => "0.9.10", |
|
37 |
26 => "0.9.11-dev", |
|
38 |
27 => "0.9.11", |
|
39 |
28 => "0.9.12-dev", |
|
40 |
29 => "0.9.12", |
|
41 |
30 => "0.9.13-dev", |
|
42 |
31 => "0.9.13", |
|
43 |
32 => "0.9.14-dev", |
|
44 |
33 => "0.9.14", |
|
45 |
34 => "0.9.15-dev", |
|
46 |
35 => "0.9.14.1", |
|
47 |
37 => "0.9.15", |
|
48 |
38 => "0.9.16-dev", |
|
49 |
39 => "0.9.16", |
|
50 |
40 => "0.9.17-dev", |
|
51 |
41 => "0.9.17", |
|
52 |
42 => "0.9.18-dev", |
|
53 |
43 => "0.9.18", |
|
54 |
44 => "0.9.19-dev", |
|
55 |
45 => "0.9.19", |
|
56 |
46 => "0.9.20-dev", |
|
57 |
47 => "0.9.20", |
|
58 |
48 => "0.9.21-dev", |
|
59 |
49 => "0.9.21", |
|
60 |
50 => "0.9.22-dev", |
|
61 |
51 => "0.9.22", |
|
62 |
52 => "0.9.23-dev", |
|
63 |
53 => "0.9.23", |
|
64 |
54 => "0.9.24-dev", |
|
65 |
55 => "0.9.24", |
|
66 |
56 => "0.9.25-dev", |
|
14477 | 67 |
57 => "0.9.25", |
68 |
58 => "1.0.0-dev", |
|
14478 | 69 |
_ => "Unknown", |
13775 | 70 |
} |
14477 | 71 |
} |