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